00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Log_Model_Mysql4_Visitor_Online_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00036 {
00037
00038
00039
00040
00041 protected function _construct()
00042 {
00043 $this->_init('log/visitor_online');
00044 }
00045
00046
00047
00048
00049
00050
00051 public function addCustomerData()
00052 {
00053 $customer = Mage::getModel('customer/customer');
00054
00055 $attributes = array(
00056 'customer_lastname' => 'lastname',
00057 'customer_firstname' => 'firstname',
00058 'customer_email' => 'email'
00059 );
00060
00061 foreach ($attributes as $alias => $attributeCode) {
00062 $attribute = $customer->getAttribute($attributeCode);
00063
00064
00065 if ($attribute->getBackendType() == 'static') {
00066 $tableAlias = 'customer_' . $attribute->getAttributeCode();
00067
00068 $this->getSelect()->joinLeft(
00069 array($tableAlias => $attribute->getBackend()->getTable()),
00070 sprintf('%s.entity_id=main_table.customer_id', $tableAlias),
00071 array($alias => $attribute->getAttributeCode())
00072 );
00073 }
00074 else {
00075 $tableAlias = 'customer_' . $attribute->getAttributeCode();
00076
00077 $joinConds = array(
00078 sprintf('%s.entity_id=main_table.customer_id', $tableAlias),
00079 $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute->getAttributeId())
00080 );
00081
00082 $this->getSelect()->joinLeft(
00083 array($tableAlias => $attribute->getBackend()->getTable()),
00084 join(' AND ', $joinConds),
00085 array($alias => 'value')
00086 );
00087 }
00088 }
00089
00090 $this->setFlag('has_customer_data', true);
00091 return $this;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 public function addWebsiteFilter($websiteIds)
00101 {
00102 if ($this->getFlag('has_customer_data')) {
00103 $this->getSelect()
00104 ->where('customer_email.website_id IN (?)', $websiteIds);
00105 }
00106 return $this;
00107 }
00108 }