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