Mage_Log_Model_Mysql4_Visitor Class Reference

Inheritance diagram for Mage_Log_Model_Mysql4_Visitor:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Protected Member Functions

 _construct ()
 _prepareDataForSave (Mage_Core_Model_Abstract $visitor)
 _saveUrlInfo ($visitor)
 _beforeSave (Mage_Core_Model_Abstract $visitor)
 _afterSave (Mage_Core_Model_Abstract $visitor)
 _saveVisitorInfo ($visitor)
 _saveVisitorUrl ($visitor)
 _saveCustomerInfo ($visitor)
 _saveQuoteInfo ($visitor)


Detailed Description

Definition at line 34 of file Visitor.php.


Member Function Documentation

_afterSave ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions after object save

Parameters:
Varien_Object $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 76 of file Visitor.php.

00077     {
00078         if ($visitor->getIsNewVisitor()) {
00079             $this->_saveVisitorInfo($visitor);
00080             $visitor->setIsNewVisitor(false);
00081         }
00082         else {
00083             $this->_saveVisitorUrl($visitor);
00084             if ($visitor->getDoCustomerLogin() || $visitor->getDoCustomerLogout()) {
00085                 $this->_saveCustomerInfo($visitor);
00086             }
00087             if ($visitor->getDoQuoteCreate() || $visitor->getDoQuoteDestroy()) {
00088                 $this->_saveQuoteInfo($visitor);
00089             }
00090         }
00091         return $this;
00092     }

_beforeSave ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions before object save

Parameters:
Varien_Object $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 68 of file Visitor.php.

00069     {
00070         if (!$visitor->getIsNewVisitor()) {
00071             $this->_saveUrlInfo($visitor);
00072         }
00073         return $this;
00074     }

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 36 of file Visitor.php.

00037     {
00038         $this->_init('log/visitor', 'visitor_id');
00039     }

_prepareDataForSave ( Mage_Core_Model_Abstract object  )  [protected]

Prepare data for save

Parameters:
Mage_Core_Model_Abstract $object
Returns:
array

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 41 of file Visitor.php.

00042     {
00043         return array(
00044             'session_id'    => $visitor->getSessionId(),
00045             'first_visit_at'=> $visitor->getFirstVisitAt(),
00046             'last_visit_at' => $visitor->getLastVisitAt(),
00047             'last_url_id'   => $visitor->getLastUrlId() ? $visitor->getLastUrlId() : 0,
00048             'store_id'      => Mage::app()->getStore()->getId(),
00049         );
00050     }

_saveCustomerInfo ( visitor  )  [protected]

Saving information about customer

Parameters:
Mage_Log_Model_Visitor $visitor
Returns:
Mage_Log_Model_Mysql4_Visitor

Definition at line 140 of file Visitor.php.

00141     {
00142         $write = $this->_getWriteAdapter();
00143 
00144         if ($visitor->getDoCustomerLogin()) {
00145             $write->insert($this->getTable('log/customer'), array(
00146                 'visitor_id'    => $visitor->getVisitorId(),
00147                 'customer_id'   => $visitor->getCustomerId(),
00148                 'login_at'      => now(),
00149                 'store_id'      => Mage::app()->getStore()->getId(),
00150             ));
00151             $visitor->setCustomerLogId($write->lastInsertId());
00152             $visitor->setDoCustomerLogin(false);
00153         }
00154 
00155         if ($visitor->getDoCustomerLogout() && $logId = $visitor->getCustomerLogId()) {
00156             $write->update($this->getTable('log/customer'),
00157                 array(
00158                     'logout_at' => now(),
00159                     'store_id'  => Mage::app()->getStore()->getId(),
00160                 ),
00161                 $write->quoteInto('log_id=?', $logId)
00162             );
00163             $visitor->setDoCustomerLogout(false);
00164             $visitor->setCustomerId(null);
00165             $visitor->setCustomerLogId(null);
00166         }
00167         return $this;
00168     }

_saveQuoteInfo ( visitor  )  [protected]

Saving information about quote

Parameters:
Mage_Log_Model_Visitor $visitor
Returns:
Mage_Log_Model_Mysql4_Visitor

We have delete quote from log because if original quote was deleted and Mysql restarted we will get key duplication error

Definition at line 176 of file Visitor.php.

00177     {
00178         $write = $this->_getWriteAdapter();
00179         if ($visitor->getDoQuoteCreate()) {
00180             $write->insert($this->getTable('log/quote_table'), array(
00181                 'quote_id'  => $visitor->getQuoteId(),
00182                 'visitor_id'=> $visitor->getId(),
00183                 'created_at'=> now()
00184             ));
00185             $visitor->setDoQuoteCreate(false);
00186         }
00187 
00188         if ($visitor->getDoQuoteDestroy()) {
00189             /**
00190              * We have delete quote from log because if original quote was
00191              * deleted and Mysql restarted we will get key duplication error
00192              */
00193             $write->delete($this->getTable('log/quote_table'),
00194                 $write->quoteInto('quote_id=?', $visitor->getQuoteId())
00195             );
00196 //            $write->update($this->getTable('log/quote_table'),
00197 //                array('deleted_at'=> now()),
00198 //                $write->quoteInto('quote_id=?', $visitor->getQuoteId())
00199 //            );
00200             $visitor->setDoQuoteDestroy(false);
00201             $visitor->setQuoteId(null);
00202         }
00203         return $this;
00204     }

_saveUrlInfo ( visitor  )  [protected]

Saving information about url

Parameters:
Mage_Log_Model_Visitor $visitor
Returns:
Mage_Log_Model_Mysql4_Visitor

Definition at line 58 of file Visitor.php.

00059     {
00060         $this->_getWriteAdapter()->insert($this->getTable('log/url_info_table'), array(
00061             'url'    => Mage::helper('core/string')->substr($visitor->getUrl(), 0, 250),
00062             'referer'=> Mage::helper('core/string')->substr($visitor->getHttpReferer(), 0, 250)
00063         ));
00064         $visitor->setLastUrlId($this->_getWriteAdapter()->lastInsertId());
00065         return $this;
00066     }

_saveVisitorInfo ( visitor  )  [protected]

Saving visitor information

Parameters:
Mage_Log_Model_Visitor $visitor
Returns:
Mage_Log_Model_Mysql4_Visitor

Definition at line 100 of file Visitor.php.

00101     {
00102         $write = $this->_getWriteAdapter();
00103         $data = array(
00104             'visitor_id'        => $visitor->getId(),
00105             'http_referer'      => Mage::helper('core/string')->substr($visitor->getHttpReferer(), 0, 250),
00106             'http_user_agent'   => $visitor->getHttpUserAgent(),
00107             'http_accept_charset'=>$visitor->getHttpAcceptCharset(),
00108             'http_accept_language'=>$visitor->getHttpAcceptLanguage(),
00109             'server_addr'       => $visitor->getServerAddr(),
00110             'remote_addr'       => $visitor->getRemoteAddr(),
00111         );
00112 
00113         $write->insert($this->getTable('log/visitor_info'), $data);
00114         return $this;
00115     }

_saveVisitorUrl ( visitor  )  [protected]

Saving visitor and url relation

Parameters:
Mage_Log_Model_Visitor $visitor
Returns:
Mage_Log_Model_Mysql4_Visitor

Definition at line 123 of file Visitor.php.

00124     {
00125         $write = $this->_getWriteAdapter();
00126         $write->insert($this->getTable('log/url_table'), array(
00127             'url_id'    => $visitor->getLastUrlId(),
00128             'visitor_id'=> $visitor->getId(),
00129             'visit_time'=> now(),
00130         ));
00131         return $this;
00132     }


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