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

/magento/app/code/core/Mage/Log/Model/Visitor/Online.php

https://bitbucket.org/jit_bec/shopifine
PHP | 133 lines | 43 code | 9 blank | 81 comment | 2 complexity | 16a87f839ecb57a42b0cfeae7f8ff49f 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_Log
  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. * Prepare Log Online Visitors Model
  28. *
  29. * @method Mage_Log_Model_Resource_Visitor_Online _getResource()
  30. * @method Mage_Log_Model_Resource_Visitor_Online getResource()
  31. * @method string getVisitorType()
  32. * @method Mage_Log_Model_Visitor_Online setVisitorType(string $value)
  33. * @method int getRemoteAddr()
  34. * @method Mage_Log_Model_Visitor_Online setRemoteAddr(int $value)
  35. * @method string getFirstVisitAt()
  36. * @method Mage_Log_Model_Visitor_Online setFirstVisitAt(string $value)
  37. * @method string getLastVisitAt()
  38. * @method Mage_Log_Model_Visitor_Online setLastVisitAt(string $value)
  39. * @method int getCustomerId()
  40. * @method Mage_Log_Model_Visitor_Online setCustomerId(int $value)
  41. * @method string getLastUrl()
  42. * @method Mage_Log_Model_Visitor_Online setLastUrl(string $value)
  43. *
  44. * @category Mage
  45. * @package Mage_Log
  46. * @author Magento Core Team <core@magentocommerce.com>
  47. */
  48. class Mage_Log_Model_Visitor_Online extends Mage_Core_Model_Abstract
  49. {
  50. const XML_PATH_ONLINE_INTERVAL = 'customer/online_customers/online_minutes_interval';
  51. const XML_PATH_UPDATE_FREQUENCY = 'log/visitor/online_update_frequency';
  52. /**
  53. * Initialize resource model
  54. *
  55. */
  56. protected function _construct()
  57. {
  58. $this->_init('log/visitor_online');
  59. }
  60. /**
  61. * Retrieve resource instance wrapper
  62. *
  63. * @return Mage_Log_Model_Mysql4_Visitor_Online
  64. */
  65. protected function _getResource()
  66. {
  67. return parent::_getResource();
  68. }
  69. /**
  70. * Prepare Online visitors collection
  71. *
  72. * @return Mage_Log_Model_Visitor_Online
  73. */
  74. public function prepare()
  75. {
  76. $this->_getResource()->prepare($this);
  77. return $this;
  78. }
  79. /**
  80. * Retrieve last prepare at timestamp
  81. *
  82. * @return int
  83. */
  84. public function getPrepareAt()
  85. {
  86. return Mage::app()->loadCache('log_visitor_online_prepare_at');
  87. }
  88. /**
  89. * Set Prepare at timestamp (if time is null, set current timestamp)
  90. *
  91. * @param int $time
  92. * @return Mage_Log_Model_Mysql4_Visitor_Online
  93. */
  94. public function setPrepareAt($time = null)
  95. {
  96. if (is_null($time)) {
  97. $time = time();
  98. }
  99. Mage::app()->saveCache($time, 'log_visitor_online_prepare_at');
  100. return $this;
  101. }
  102. /**
  103. * Retrieve data update Frequency in second
  104. *
  105. * @return int
  106. */
  107. public function getUpdateFrequency()
  108. {
  109. return Mage::getStoreConfig(self::XML_PATH_UPDATE_FREQUENCY);
  110. }
  111. /**
  112. * Retrieve Online Interval (in minutes)
  113. *
  114. * @return int
  115. */
  116. public function getOnlineInterval()
  117. {
  118. $value = intval(Mage::getStoreConfig(self::XML_PATH_ONLINE_INTERVAL));
  119. if (!$value) {
  120. $value = Mage_Log_Model_Visitor::DEFAULT_ONLINE_MINUTES_INTERVAL;
  121. }
  122. return $value;
  123. }
  124. }