Mage_Log_Model_Mysql4_Visitor_Online Class Reference

Inheritance diagram for Mage_Log_Model_Mysql4_Visitor_Online:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 prepare (Mage_Log_Model_Visitor_Online $object)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 35 of file Online.php.


Member Function Documentation

_construct (  )  [protected]

Initialize connection and define resource

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 41 of file Online.php.

00042     {
00043         $this->_init('log/visitor_online', 'visitor_id');
00044     }

prepare ( Mage_Log_Model_Visitor_Online object  ) 

Prepare online visitors for collection

Parameters:
Mage_Log_Model_Visitor_Online $object
Returns:
Mage_Log_Model_Mysql4_Visitor_Online

Definition at line 52 of file Online.php.

00053     {
00054         if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) {
00055             return $this;
00056         }
00057 
00058         $this->_getWriteAdapter()->beginTransaction();
00059         $this->_getWriteAdapter()->truncate($this->getMainTable());
00060 
00061         $visitors = array();
00062         $lastUrls = array();
00063 
00064         // retrieve online visitors general data
00065         $whereCond = sprintf('last_visit_at >= (? - INTERVAL %d MINUTE)',
00066             $object->getOnlineInterval());
00067         $select = $this->_getReadAdapter()->select()
00068             ->from(
00069                 $this->getTable('log/visitor'),
00070                 array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id'))
00071             ->where($whereCond, now());
00072 
00073         $query = $this->_getReadAdapter()->query($select);
00074         while ($row = $query->fetch()) {
00075             $visitors[$row['visitor_id']] = $row;
00076             $lastUrls[$row['last_url_id']] = $row['visitor_id'];
00077             $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR;
00078             $visitors[$row['visitor_id']]['customer_id']  = null;
00079         }
00080 
00081         if (!$visitors) {
00082             $this->commit();
00083             return $this;
00084         }
00085 
00086         // retrieve visitor remote addr
00087         $select = $this->_getReadAdapter()->select()
00088             ->from(
00089                 $this->getTable('log/visitor_info'),
00090                 array('visitor_id', 'remote_addr'))
00091             ->where('visitor_id IN(?)', array_keys($visitors));
00092         $query = $this->_getReadAdapter()->query($select);
00093         while ($row = $query->fetch()) {
00094             $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr'];
00095         }
00096 
00097         // retrieve visitor last URLs
00098         $select = $this->_getReadAdapter()->select()
00099             ->from(
00100                 $this->getTable('log/url_info_table'),
00101                 array('url_id', 'url'))
00102             ->where('url_id IN(?)', array_keys($lastUrls));
00103         $query = $this->_getReadAdapter()->query($select);
00104         while ($row = $query->fetch()) {
00105             $visitorId = $lastUrls[$row['url_id']];
00106             $visitors[$visitorId]['last_url'] = $row['url'];
00107         }
00108 
00109         // retrieve customers
00110         $select = $this->_getReadAdapter()->select()
00111             ->from(
00112                 $this->getTable('log/customer'),
00113                 array('visitor_id', 'customer_id'))
00114             ->where('visitor_id IN(?)', array_keys($visitors));
00115         $query = $this->_getReadAdapter()->query($select);
00116         while ($row = $query->fetch()) {
00117             $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER;
00118             $visitors[$row['visitor_id']]['customer_id']  = $row['customer_id'];
00119         }
00120 
00121         foreach ($visitors as $visitorData) {
00122             unset($visitorData['last_url_id']);
00123             $this->_getWriteAdapter()->insert($this->getMainTable(), $visitorData);
00124         }
00125 
00126         $this->_getWriteAdapter()->commit();
00127 
00128         $object->setPrepareAt();
00129 
00130         return $this;
00131     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:28 2009 for Magento by  doxygen 1.5.8