Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Log_Helper_Data
  • Mage_Log_Model_Aggregation
  • Mage_Log_Model_Cron
  • Mage_Log_Model_Customer
  • Mage_Log_Model_Log
  • Mage_Log_Model_Mysql4_Aggregation
  • Mage_Log_Model_Mysql4_Customer
  • Mage_Log_Model_Mysql4_Log
  • Mage_Log_Model_Mysql4_Visitor
  • Mage_Log_Model_Mysql4_Visitor_Collection
  • Mage_Log_Model_Mysql4_Visitor_Online
  • Mage_Log_Model_Mysql4_Visitor_Online_Collection
  • Mage_Log_Model_Resource_Aggregation
  • Mage_Log_Model_Resource_Customer
  • Mage_Log_Model_Resource_Log
  • Mage_Log_Model_Resource_Visitor
  • Mage_Log_Model_Resource_Visitor_Collection
  • Mage_Log_Model_Resource_Visitor_Online
  • Mage_Log_Model_Resource_Visitor_Online_Collection
  • Mage_Log_Model_Visitor
  • Mage_Log_Model_Visitor_Online
  • Overview
  • Package
  • Class
  • Tree
  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:  * Enter description here ...
 30:  *
 31:  * @method Mage_Log_Model_Resource_Visitor _getResource()
 32:  * @method Mage_Log_Model_Resource_Visitor getResource()
 33:  * @method string getSessionId()
 34:  * @method Mage_Log_Model_Visitor setSessionId(string $value)
 35:  * @method Mage_Log_Model_Visitor setFirstVisitAt(string $value)
 36:  * @method Mage_Log_Model_Visitor setLastVisitAt(string $value)
 37:  * @method int getLastUrlId()
 38:  * @method Mage_Log_Model_Visitor setLastUrlId(int $value)
 39:  * @method int getStoreId()
 40:  * @method Mage_Log_Model_Visitor setStoreId(int $value)
 41:  *
 42:  * @category    Mage
 43:  * @package     Mage_Log
 44:  * @author      Magento Core Team <core@magentocommerce.com>
 45:  */
 46: class Mage_Log_Model_Visitor extends Mage_Core_Model_Abstract
 47: {
 48:     const DEFAULT_ONLINE_MINUTES_INTERVAL = 15;
 49:     const VISITOR_TYPE_CUSTOMER = 'c';
 50:     const VISITOR_TYPE_VISITOR  = 'v';
 51: 
 52:     protected $_skipRequestLogging = false;
 53: 
 54:     /**
 55:      * Onject initialization
 56:      */
 57:     protected function _construct()
 58:     {
 59:         $this->_init('log/visitor');
 60:         $userAgent = Mage::helper('core/http')->getHttpUserAgent();
 61:         $ignoreAgents = Mage::getConfig()->getNode('global/ignore_user_agents');
 62:         if ($ignoreAgents) {
 63:             $ignoreAgents = $ignoreAgents->asArray();
 64:             if (in_array($userAgent, $ignoreAgents)) {
 65:                 $this->_skipRequestLogging = true;
 66:             }
 67:         }
 68:     }
 69: 
 70:     /**
 71:      * Retrieve session object
 72:      *
 73:      * @return Mage_Core_Model_Session_Abstract
 74:      */
 75:     protected function _getSession()
 76:     {
 77:         return Mage::getSingleton('core/session');
 78:     }
 79: 
 80:     /**
 81:      * Initialize visitor information from server data
 82:      *
 83:      * @return Mage_Log_Model_Visitor
 84:      */
 85:     public function initServerData()
 86:     {
 87:         /* @var $helper Mage_Core_Helper_Http */
 88:         $helper = Mage::helper('core/http');
 89: 
 90:         $this->addData(array(
 91:             'server_addr'           => $helper->getServerAddr(true),
 92:             'remote_addr'           => $helper->getRemoteAddr(true),
 93:             'http_secure'           => Mage::app()->getStore()->isCurrentlySecure(),
 94:             'http_host'             => $helper->getHttpHost(true),
 95:             'http_user_agent'       => $helper->getHttpUserAgent(true),
 96:             'http_accept_language'  => $helper->getHttpAcceptLanguage(true),
 97:             'http_accept_charset'   => $helper->getHttpAcceptCharset(true),
 98:             'request_uri'           => $helper->getRequestUri(true),
 99:             'session_id'            => $this->_getSession()->getSessionId(),
100:             'http_referer'          => $helper->getHttpReferer(true),
101:         ));
102: 
103:         return $this;
104:     }
105: 
106:     /**
107:      * Return Online Minutes Interval
108:      *
109:      * @return int Minutes Interval
110:      */
111:     public static function getOnlineMinutesInterval()
112:     {
113:         $configValue = Mage::getStoreConfig('customer/online_customers/online_minutes_interval');
114:         return intval($configValue) > 0
115:             ? intval($configValue)
116:             : self::DEFAULT_ONLINE_MINUTES_INTERVAL;
117:     }
118: 
119:     /**
120:      * Retrieve url from model data
121:      *
122:      * @return string
123:      */
124:     public function getUrl()
125:     {
126:         $url = 'http' . ($this->getHttpSecure() ? 's' : '') . '://';
127:         $url .= $this->getHttpHost().$this->getRequestUri();
128:         return $url;
129:     }
130: 
131:     public function getFirstVisitAt()
132:     {
133:         if (!$this->hasData('first_visit_at')) {
134:             $this->setData('first_visit_at', now());
135:         }
136:         return $this->getData('first_visit_at');
137:     }
138: 
139:     public function getLastVisitAt()
140:     {
141:         if (!$this->hasData('last_visit_at')) {
142:             $this->setData('last_visit_at', now());
143:         }
144:         return $this->getData('last_visit_at');
145:     }
146: 
147:     /**
148:      * Initialization visitor information by request
149:      *
150:      * Used in event "controller_action_predispatch"
151:      *
152:      * @param   Varien_Event_Observer $observer
153:      * @return  Mage_Log_Model_Visitor
154:      */
155:     public function initByRequest($observer)
156:     {
157:         if ($this->_skipRequestLogging || $this->isModuleIgnored($observer)) {
158:             return $this;
159:         }
160: 
161:         $this->setData($this->_getSession()->getVisitorData());
162:         $this->initServerData();
163: 
164:         if (!$this->getId()) {
165:             $this->setFirstVisitAt(now());
166:             $this->setIsNewVisitor(true);
167:             $this->save();
168:             Mage::dispatchEvent('visitor_init', array('visitor' => $this));
169:         }
170:         return $this;
171:     }
172: 
173:     /**
174:      * Saving visitor information by request
175:      *
176:      * Used in event "controller_action_postdispatch"
177:      *
178:      * @param   Varien_Event_Observer $observer
179:      * @return  Mage_Log_Model_Visitor
180:      */
181:     public function saveByRequest($observer)
182:     {
183:         if ($this->_skipRequestLogging || $this->isModuleIgnored($observer)) {
184:             return $this;
185:         }
186: 
187:         try {
188:             $this->setLastVisitAt(now());
189:             $this->save();
190:             $this->_getSession()->setVisitorData($this->getData());
191:         } catch (Exception $e) {
192:             Mage::logException($e);
193:         }
194:         return $this;
195:     }
196: 
197:     /**
198:      * Bind customer data when customer login
199:      *
200:      * Used in event "customer_login"
201:      *
202:      * @param   Varien_Event_Observer $observer
203:      * @return  Mage_Log_Model_Visitor
204:      */
205:     public function bindCustomerLogin($observer)
206:     {
207:         if (!$this->getCustomerId() && $customer = $observer->getEvent()->getCustomer()) {
208:             $this->setDoCustomerLogin(true);
209:             $this->setCustomerId($customer->getId());
210:         }
211:         return $this;
212:     }
213: 
214:     /**
215:      * Bind customer data when customer logout
216:      *
217:      * Used in event "customer_logout"
218:      *
219:      * @param   Varien_Event_Observer $observer
220:      * @return  Mage_Log_Model_Visitor
221:      */
222:     public function bindCustomerLogout($observer)
223:     {
224:         if ($this->getCustomerId() && $customer = $observer->getEvent()->getCustomer()) {
225:             $this->setDoCustomerLogout(true);
226:         }
227:         return $this;
228:     }
229: 
230:     public function bindQuoteCreate($observer)
231:     {
232:         if ($quote = $observer->getEvent()->getQuote()) {
233:             if ($quote->getIsCheckoutCart()) {
234:                 $this->setQuoteId($quote->getId());
235:                 $this->setDoQuoteCreate(true);
236:             }
237:         }
238:         return $this;
239:     }
240: 
241:     public function bindQuoteDestroy($observer)
242:     {
243:         if ($quote = $observer->getEvent()->getQuote()) {
244:             $this->setDoQuoteDestroy(true);
245:         }
246:         return $this;
247:     }
248: 
249:     /**
250:      * Methods for research (depends from customer online admin section)
251:      */
252:     public function addIpData($data)
253:     {
254:         $ipData = array();
255:         $data->setIpData($ipData);
256:         return $this;
257:     }
258: 
259:     public function addCustomerData($data)
260:     {
261:         $customerId = $data->getCustomerId();
262:         if( intval($customerId) <= 0 ) {
263:             return $this;
264:         }
265:         $customerData = Mage::getModel('customer/customer')->load($customerId);
266:         $newCustomerData = array();
267:         foreach( $customerData->getData() as $propName => $propValue ) {
268:             $newCustomerData['customer_' . $propName] = $propValue;
269:         }
270: 
271:         $data->addData($newCustomerData);
272:         return $this;
273:     }
274: 
275:     public function addQuoteData($data)
276:     {
277:         $quoteId = $data->getQuoteId();
278:         if( intval($quoteId) <= 0 ) {
279:             return $this;
280:         }
281:         $data->setQuoteData(Mage::getModel('sales/quote')->load($quoteId));
282:         return $this;
283:     }
284: 
285:     public function isModuleIgnored($observer)
286:     {
287:         $ignores = Mage::getConfig()->getNode('global/ignoredModules/entities')->asArray();
288: 
289:         if( is_array($ignores) && $observer) {
290:             $curModule = $observer->getEvent()->getControllerAction()->getRequest()->getRouteName();
291:             if (isset($ignores[$curModule])) {
292:                 return true;
293:             }
294:         }
295:         return false;
296:     }
297: }
298: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0