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:  * Log Prepare Online visitors resource 
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Log
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Log_Model_Resource_Visitor_Online extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Initialize connection and define resource
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('log/visitor_online', 'visitor_id');
 44:     }
 45: 
 46:     /**
 47:      * Prepare online visitors for collection
 48:      *
 49:      * @param Mage_Log_Model_Visitor_Online $object
 50:      * @return Mage_Log_Model_Resource_Visitor_Online
 51:      */
 52:     public function prepare(Mage_Log_Model_Visitor_Online $object)
 53:     {
 54:         if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) {
 55:             return $this;
 56:         }
 57: 
 58:         $readAdapter    = $this->_getReadAdapter();
 59:         $writeAdapter   = $this->_getWriteAdapter();
 60: 
 61:         $writeAdapter->beginTransaction();
 62: 
 63:         try{
 64:             $writeAdapter->delete($this->getMainTable());
 65: 
 66:             $visitors = array();
 67:             $lastUrls = array();
 68: 
 69:             // retrieve online visitors general data
 70: 
 71:             $lastDate = Mage::getModel('core/date')->gmtTimestamp() - $object->getOnlineInterval() * 60;
 72: 
 73:             $select = $readAdapter->select()
 74:                 ->from(
 75:                     $this->getTable('log/visitor'),
 76:                     array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id'))
 77:                 ->where('last_visit_at >= ?', $readAdapter->formatDate($lastDate));
 78: 
 79:             $query = $readAdapter->query($select);
 80:             while ($row = $query->fetch()) {
 81:                 $visitors[$row['visitor_id']] = $row;
 82:                 $lastUrls[$row['last_url_id']] = $row['visitor_id'];
 83:                 $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR;
 84:                 $visitors[$row['visitor_id']]['customer_id']  = null;
 85:             }
 86: 
 87:             if (!$visitors) {
 88:                 $this->commit();
 89:                 return $this;
 90:             }
 91: 
 92:             // retrieve visitor remote addr
 93:             $select = $readAdapter->select()
 94:                 ->from(
 95:                     $this->getTable('log/visitor_info'),
 96:                     array('visitor_id', 'remote_addr'))
 97:                 ->where('visitor_id IN(?)', array_keys($visitors));
 98: 
 99:             $query = $readAdapter->query($select);
100:             while ($row = $query->fetch()) {
101:                 $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr'];
102:             }
103: 
104:             // retrieve visitor last URLs
105:             $select = $readAdapter->select()
106:                 ->from(
107:                     $this->getTable('log/url_info_table'),
108:                     array('url_id', 'url'))
109:                 ->where('url_id IN(?)', array_keys($lastUrls));
110: 
111:             $query = $readAdapter->query($select);
112:             while ($row = $query->fetch()) {
113:                 $visitorId = $lastUrls[$row['url_id']];
114:                 $visitors[$visitorId]['last_url'] = $row['url'];
115:             }
116: 
117:             // retrieve customers
118:             $select = $readAdapter->select()
119:                 ->from(
120:                     $this->getTable('log/customer'),
121:                     array('visitor_id', 'customer_id'))
122:                 ->where('visitor_id IN(?)', array_keys($visitors));
123: 
124:             $query = $readAdapter->query($select);
125:             while ($row = $query->fetch()) {
126:                 $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER;
127:                 $visitors[$row['visitor_id']]['customer_id']  = $row['customer_id'];
128:             }
129: 
130:             foreach ($visitors as $visitorData) {
131:                 unset($visitorData['last_url_id']);
132: 
133:                 $writeAdapter->insertForce($this->getMainTable(), $visitorData);
134:             }
135: 
136:             $writeAdapter->commit();
137:         } catch (Exception $e) {
138:             $writeAdapter->rollBack();
139:             throw $e;
140:         }
141: 
142:         $object->setPrepareAt();
143: 
144:         return $this;
145:     }
146: }
147: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0