PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/MXWest/magento-ce-1.5.1.0
PHP | 118 lines | 43 code | 9 blank | 66 comment | 2 complexity | e2b7207c9f89874a84be9d7f93547709 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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) 2010 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. * @category Mage
  30. * @package Mage_Log
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Log_Model_Visitor_Online extends Mage_Core_Model_Abstract
  34. {
  35. const XML_PATH_ONLINE_INTERVAL = 'customer/online_customers/online_minutes_interval';
  36. const XML_PATH_UPDATE_FREQUENCY = 'log/visitor/online_update_frequency';
  37. /**
  38. * Initialize resource model
  39. *
  40. */
  41. protected function _construct()
  42. {
  43. $this->_init('log/visitor_online');
  44. }
  45. /**
  46. * Retrieve resource instance wrapper
  47. *
  48. * @return Mage_Log_Model_Mysql4_Visitor_Online
  49. */
  50. protected function _getResource()
  51. {
  52. return parent::_getResource();
  53. }
  54. /**
  55. * Prepare Online visitors collection
  56. *
  57. * @return Mage_Log_Model_Visitor_Online
  58. */
  59. public function prepare()
  60. {
  61. $this->_getResource()->prepare($this);
  62. return $this;
  63. }
  64. /**
  65. * Retrieve last prepare at timestamp
  66. *
  67. * @return int
  68. */
  69. public function getPrepareAt()
  70. {
  71. return Mage::app()->loadCache('log_visitor_online_prepare_at');
  72. }
  73. /**
  74. * Set Prepare at timestamp (if time is null, set current timestamp)
  75. *
  76. * @param int $time
  77. * @return Mage_Log_Model_Mysql4_Visitor_Online
  78. */
  79. public function setPrepareAt($time = null)
  80. {
  81. if (is_null($time)) {
  82. $time = time();
  83. }
  84. Mage::app()->saveCache($time, 'log_visitor_online_prepare_at');
  85. return $this;
  86. }
  87. /**
  88. * Retrieve data update Frequency in second
  89. *
  90. * @return int
  91. */
  92. public function getUpdateFrequency()
  93. {
  94. return Mage::getStoreConfig(self::XML_PATH_UPDATE_FREQUENCY);
  95. }
  96. /**
  97. * Retrieve Online Interval (in minutes)
  98. *
  99. * @return int
  100. */
  101. public function getOnlineInterval()
  102. {
  103. $value = intval(Mage::getStoreConfig(self::XML_PATH_ONLINE_INTERVAL));
  104. if (!$value) {
  105. $value = Mage_Log_Model_Visitor::DEFAULT_ONLINE_MINUTES_INTERVAL;
  106. }
  107. return $value;
  108. }
  109. }