PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/Sendfriend/Model/Resource/Sendfriend.php

https://bitbucket.org/jit_bec/shopifine
PHP | 107 lines | 42 code | 7 blank | 58 comment | 0 complexity | 2703b52f6b61383fc1ce54119788ef42 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Sendfriend
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * SendFriend Log Resource Model
  28. *
  29. * @category Mage
  30. * @package Mage_Sendfriend
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Sendfriend_Model_Resource_Sendfriend extends Mage_Core_Model_Resource_Db_Abstract
  34. {
  35. /**
  36. * Initialize connection and table
  37. *
  38. */
  39. protected function _construct()
  40. {
  41. $this->_init('sendfriend/sendfriend', 'log_id');
  42. }
  43. /**
  44. * Retrieve Sended Emails By Ip
  45. *
  46. * @param Mage_Sendfriend_Model_Sendfriend $object
  47. * @param int $ip
  48. * @param int $startTime
  49. * @param int $websiteId
  50. * @return int
  51. */
  52. public function getSendCount($object, $ip, $startTime, $websiteId = null)
  53. {
  54. $adapter = $this->_getReadAdapter();
  55. $select = $adapter->select()
  56. ->from($this->getMainTable(), array('count' => new Zend_Db_Expr('count(*)')))
  57. ->where('ip=:ip
  58. AND time>=:time
  59. AND website_id=:website_id');
  60. $bind = array(
  61. 'ip' => $ip,
  62. 'time' => $startTime,
  63. 'website_id' => (int)$websiteId,
  64. );
  65. $row = $adapter->fetchRow($select, $bind);
  66. return $row['count'];
  67. }
  68. /**
  69. * Add sended email by ip item
  70. *
  71. * @param int $ip
  72. * @param int $startTime
  73. * @param int $websiteId
  74. * @return Mage_Sendfriend_Model_Resource_Sendfriend
  75. */
  76. public function addSendItem($ip, $startTime, $websiteId)
  77. {
  78. $this->_getWriteAdapter()->insert(
  79. $this->getMainTable(),
  80. array(
  81. 'ip' => $ip,
  82. 'time' => $startTime,
  83. 'website_id' => $websiteId
  84. )
  85. );
  86. return $this;
  87. }
  88. /**
  89. * Delete Old logs
  90. *
  91. * @param int $time
  92. * @return Mage_Sendfriend_Model_Resource_Sendfriend
  93. */
  94. public function deleteLogsBefore($time)
  95. {
  96. $cond = $this->_getWriteAdapter()->quoteInto('time<?', $time);
  97. $this->_getWriteAdapter()->delete($this->getMainTable(), $cond);
  98. return $this;
  99. }
  100. }