Public Member Functions | |
__construct () | |
useOnlineFilter ($minutes=null) | |
showCustomersOnly () | |
getAggregatedData ($period=720, $type_code=null, $customFrom=null, $customTo=null) | |
addFieldToFilter ($fieldName, $condition=null) | |
load ($printQuery=false, $logQuery=false) | |
getIsOnlineFilterUsed () | |
addVisitorStoreFilter ($storeIds) | |
Protected Member Functions | |
_getGroupByDateFormat ($type) | |
_getRangeByType ($type_code) | |
_getFieldMap ($fieldName) | |
Protected Attributes | |
$_visitorTable | |
$_visitorInfoTable | |
$_customerTable | |
$_urlTable | |
$_urlInfoTable | |
$_summaryTable | |
$_summaryTypeTable | |
$_quoteTable | |
$_isOnlineFilterUsed = false | |
$_fieldMap |
Definition at line 35 of file Collection.php.
__construct | ( | ) |
Construct
Reimplemented from Varien_Data_Collection.
Definition at line 107 of file Collection.php.
00108 { 00109 $resource = Mage::getSingleton('core/resource'); 00110 parent::__construct($resource->getConnection('log_read')); 00111 00112 $this->_visitorTable = $resource->getTableName('log/visitor'); 00113 $this->_visitorInfoTable = $resource->getTableName('log/visitor_info'); 00114 $this->_urlTable = $resource->getTableName('log/url_table'); 00115 $this->_urlInfoTable = $resource->getTableName('log/url_info_table'); 00116 $this->_customerTable = $resource->getTableName('log/customer'); 00117 $this->_summaryTable = $resource->getTableName('log/summary_table'); 00118 $this->_summaryTypeTable = $resource->getTableName('log/summary_type_table'); 00119 $this->_quoteTable = $resource->getTableName('log/quote_table'); 00120 00121 $this->setItemObjectClass(Mage::getConfig()->getModelClassName('log/visitor')); 00122 }
_getFieldMap | ( | $ | fieldName | ) | [protected] |
Definition at line 285 of file Collection.php.
00286 { 00287 if(isset($this->_fieldMap[$fieldName])) { 00288 return $this->_fieldMap[$fieldName]; 00289 } else { 00290 return 'visitor_table.' . $fieldName; 00291 } 00292 }
_getGroupByDateFormat | ( | $ | type | ) | [protected] |
Definition at line 231 of file Collection.php.
00232 { 00233 switch ($type) { 00234 case 'day': 00235 $format = '%Y-%m-%d'; 00236 break; 00237 default: 00238 case 'hour': 00239 $format = '%Y-%m-%d %H'; 00240 break; 00241 } 00242 return $format; 00243 }
_getRangeByType | ( | $ | type_code | ) | [protected] |
Definition at line 245 of file Collection.php.
00246 { 00247 switch ($type_code) 00248 { 00249 case 'day': 00250 $range = 'DAY'; 00251 break; 00252 case 'hour': 00253 $range = 'HOUR'; 00254 break; 00255 case 'minute': 00256 default: 00257 $range = 'MINUTE'; 00258 break; 00259 00260 } 00261 00262 return $range; 00263 }
addFieldToFilter | ( | $ | fieldName, | |
$ | condition = null | |||
) |
Filter by customer ID, as 'type' field does not exist
string | $fieldName | |
array | $condition |
Reimplemented from Varien_Data_Collection_Db.
Definition at line 272 of file Collection.php.
00273 { 00274 if ($fieldName == 'type' && is_array($condition) && isset($condition['eq'])) { 00275 $fieldName = 'customer_id'; 00276 if ($condition['eq'] === Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR) { 00277 $condition = array('null' => 1); 00278 } else { 00279 $condition = array('moreq' => 1); 00280 } 00281 } 00282 return parent::addFieldToFilter($this->_getFieldMap($fieldName), $condition); 00283 }
addVisitorStoreFilter | ( | $ | storeIds | ) |
Filter visitors by specified store ids
array|int | $storeIds |
Definition at line 313 of file Collection.php.
00314 { 00315 $this->_select->where('visitor_table.store_id IN (?)', $storeIds); 00316 }
getAggregatedData | ( | $ | period = 720 , |
|
$ | type_code = null , |
|||
$ | customFrom = null , |
|||
$ | customTo = null | |||
) |
Definition at line 185 of file Collection.php.
00186 { 00187 /** 00188 * @todo : need remove agregation logic 00189 */ 00190 $timeZoneOffset = Mage::getModel('core/date')->getGmtOffset();//Mage::app()->getLocale()->date()->getGmtOffset(); 00191 $this->_itemObjectClass = 'Varien_Object'; 00192 $this->_setIdFieldName('summary_id'); 00193 00194 /* 00195 $this->_select->from(array('summary'=>$this->_summaryTable), array('summary_id','customer_count','visitor_count','add_date'=>"DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND)")) 00196 ->join(array('type'=>$this->_summaryTypeTable), 'type.type_id=summary.type_id', array()); 00197 00198 if (is_null($customFrom) && is_null($customTo)) { 00199 $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ( DATE_SUB(?, INTERVAL $timeZoneOffset SECOND) - INTERVAL {$period} {$this->_getRangeByType($type_code)} )", now() ); 00200 } else { 00201 if($customFrom) { 00202 $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ", $this->_read->convertDate($customFrom)); 00203 } 00204 if($customTo) { 00205 $this->_select->where( "DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) <= ", $this->_read->convertDate($customTo)); 00206 } 00207 } 00208 00209 00210 if( is_null($type_code) ) { 00211 $this->_select->where("summary.type_id IS NULL"); 00212 } else { 00213 $this->_select->where("type.type_code = ? ", $type_code); 00214 } 00215 */ 00216 00217 $this->_select->from(array('summary'=>$this->_summaryTable), 00218 array('summary_id', 00219 'customer_count'=>'SUM(customer_count)', 00220 'visitor_count'=>'SUM(visitor_count)', 00221 'add_date'=>"DATE_ADD(summary.add_date, INTERVAL $timeZoneOffset SECOND)" 00222 )); 00223 00224 $this->_select->where("DATE_SUB(summary.add_date, INTERVAL $timeZoneOffset SECOND) >= ( DATE_SUB(?, INTERVAL $timeZoneOffset SECOND) - INTERVAL {$period} {$this->_getRangeByType($type_code)} )", now() ); 00225 $this->_select->group('DATE_FORMAT(add_date, \''.$this->_getGroupByDateFormat($type_code).'\')'); 00226 $this->_select->order('add_date ASC'); 00227 00228 return $this; 00229 }
getIsOnlineFilterUsed | ( | ) |
load | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load data
Reimplemented from Varien_Data_Collection_Db.
Definition at line 294 of file Collection.php.
00295 { 00296 if ($this->isLoaded()) { 00297 return $this; 00298 } 00299 Mage::dispatchEvent('log_visitor_collection_load_before', array('collection' => $this)); 00300 return parent::load($printQuery, $logQuery); 00301 }
showCustomersOnly | ( | ) |
Definition at line 178 of file Collection.php.
00179 { 00180 $this->_select->where('customer_table.customer_id > 0') 00181 ->group('customer_table.customer_id'); 00182 return $this; 00183 }
useOnlineFilter | ( | $ | minutes = null |
) |
Enables online only select
int | $minutes |
Definition at line 130 of file Collection.php.
00131 { 00132 if (is_null($minutes)) { 00133 $minutes = Mage_Log_Model_Visitor::getOnlineMinutesInterval(); 00134 } 00135 $this->_select->from(array('visitor_table'=>$this->_visitorTable)) 00136 //->joinLeft(array('url_table'=>$this->_urlTable), 'visitor_table.last_url_id=url_table.url_id') 00137 ->joinLeft(array('info_table'=>$this->_visitorInfoTable), 'info_table.visitor_id=visitor_table.visitor_id') 00138 ->joinLeft(array('customer_table'=>$this->_customerTable), 00139 'customer_table.visitor_id = visitor_table.visitor_id AND customer_table.logout_at IS NULL', 00140 array('log_id', 'customer_id', 'login_at', 'logout_at')) 00141 ->joinLeft(array('url_info_table'=>$this->_urlInfoTable), 00142 'url_info_table.url_id = visitor_table.last_url_id') 00143 //->joinLeft(array('quote_table'=>$this->_quoteTable), 'quote_table.visitor_id=visitor_table.visitor_id') 00144 ->where( 'visitor_table.last_visit_at >= ( ? - INTERVAL '.$minutes.' MINUTE)', now() ); 00145 00146 00147 $customersCollection = Mage::getModel('customer/customer')->getCollection(); 00148 /* @var $customersCollection Mage_Customer_Model_Entity_Customer_Collection */ 00149 $firstname = $customersCollection->getAttribute('firstname'); 00150 $lastname = $customersCollection->getAttribute('lastname'); 00151 $email = $customersCollection->getAttribute('email'); 00152 00153 $this->_select 00154 ->from('', array('type' => 'IF(customer_id, \''.Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER.'\', \''.Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR.'\')')) 00155 ->joinLeft( 00156 array('customer_lastname_table'=>$lastname->getBackend()->getTable()), 00157 'customer_lastname_table.entity_id=customer_table.customer_id 00158 AND customer_lastname_table.attribute_id = '.(int) $lastname->getAttributeId() . ' 00159 ', 00160 array('customer_lastname'=>'value') 00161 ) 00162 ->joinLeft( 00163 array('customer_firstname_table'=>$firstname->getBackend()->getTable()), 00164 'customer_firstname_table.entity_id=customer_table.customer_id 00165 AND customer_firstname_table.attribute_id = '.(int) $firstname->getAttributeId() . ' 00166 ', 00167 array('customer_firstname'=>'value') 00168 ) 00169 ->joinLeft( 00170 array('customer_email_table'=>$email->getBackend()->getTable()), 00171 'customer_email_table.entity_id=customer_table.customer_id', 00172 array('customer_email'=>'email') 00173 ); 00174 $this->_isOnlineFilterUsed = true; 00175 return $this; 00176 }
$_customerTable [protected] |
Definition at line 56 of file Collection.php.
$_fieldMap [protected] |
Initial value:
array( 'customer_firstname' => 'customer_firstname_table.value', 'customer_lastname' => 'customer_lastname_table.value', 'customer_email' => 'customer_email_table.email', 'customer_id' => 'customer_table.customer_id', 'url' => 'url_info_table.url' )
Definition at line 95 of file Collection.php.
$_isOnlineFilterUsed = false [protected] |
Definition at line 93 of file Collection.php.
$_quoteTable [protected] |
Definition at line 91 of file Collection.php.
$_summaryTable [protected] |
Definition at line 77 of file Collection.php.
$_summaryTypeTable [protected] |
Definition at line 84 of file Collection.php.
$_urlInfoTable [protected] |
Definition at line 70 of file Collection.php.
$_urlTable [protected] |
Definition at line 63 of file Collection.php.
$_visitorInfoTable [protected] |
Definition at line 49 of file Collection.php.
$_visitorTable [protected] |
Definition at line 42 of file Collection.php.