Public Member Functions | |
__construct () | |
addTagFilter ($tagId) | |
addProductFilter ($productId) | |
load ($printQuery=false, $logQuery=false) | |
Protected Member Functions | |
_loadTags ($printQuery=false, $logQuery=false) | |
Protected Attributes | |
$_tagTable | |
$_tagRelTable |
Definition at line 35 of file Collection.php.
__construct | ( | ) |
Reimplemented from Varien_Data_Collection.
Definition at line 40 of file Collection.php.
00041 { 00042 $resource = Mage::getSingleton('core/resource'); 00043 parent::__construct(); 00044 $this->_tagTable = $resource->getTableName('tag/tag'); 00045 $this->_tagRelTable = $resource->getTableName('tag/tag_relation'); 00046 00047 // $this->joinField('tag_total_used', $this->_tagRelTable, 'count(_table_tag_total_used.tag_relations_id)', 'entity_val_id=entity_id', array('entity_id' => '2')); 00048 // $this->getSelect()->group('tag_tag_id'); 00049 // echo $this->getSelect(); 00050 // $this->_productTable = $resource->getTableName('catalog/product'); 00051 // $this->_select->from(array('p' => $this->_productTable)) 00052 // ->join(array('tr' => $this->_tagRelTable), 'tr.entity_val_id=p.product_id and tr.entity_id=1', array('total_used' => 'count(tr.tag_relations_id)')) 00053 // ->group('p.product_id', 'tr.tag_id') 00054 // ; 00055 00056 }
_loadTags | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) | [protected] |
Definition at line 79 of file Collection.php.
00080 { 00081 if (empty($this->_items)) { 00082 return $this; 00083 } 00084 $customerIds = array(); 00085 foreach ($this->getItems() as $item) { 00086 $customerIds[] = $item->getId(); 00087 } 00088 $this->getSelect()->reset() 00089 ->from(array('tr' => $this->_tagRelTable), array('*','total_used' => 'count(tr.tag_relation_id)')) 00090 ->joinLeft(array('t' => $this->_tagTable),'t.tag_id=tr.tag_id') 00091 ->group(array('tr.customer_id', 't.tag_id')) 00092 ->where('tr.customer_id in (?)',$customerIds) 00093 ; 00094 $this->printLogQuery($printQuery, $logQuery); 00095 00096 $tags = array(); 00097 $data = $this->_read->fetchAll($this->getSelect()); 00098 foreach ($data as $row) { 00099 if (!isset($tags[ $row['customer_id'] ])) { 00100 $tags[ $row['customer_id'] ] = array(); 00101 } 00102 $tags[ $row['customer_id'] ][] = $row; 00103 } 00104 foreach ($this->getItems() as $item) { 00105 if (isset($tags[$item->getId()])) { 00106 $item->setData('tags', $tags[$item->getId()]); 00107 } 00108 } 00109 return $this; 00110 }
addProductFilter | ( | $ | productId | ) |
Definition at line 65 of file Collection.php.
00066 { 00067 $this->joinField('tag_product_id', $this->_tagRelTable, 'product_id', 'customer_id=entity_id'); 00068 $this->getSelect()->where($this->_getAttributeTableAlias('tag_product_id') . '.product_id=?', $productId); 00069 return $this; 00070 }
addTagFilter | ( | $ | tagId | ) |
Definition at line 58 of file Collection.php.
00059 { 00060 $this->joinField('tag_tag_id', $this->_tagRelTable, 'tag_id', 'customer_id=entity_id'); 00061 $this->getSelect()->where($this->_getAttributeTableAlias('tag_tag_id') . '.tag_id=?', $tagId); 00062 return $this; 00063 }
load | ( | $ | printQuery = false , |
|
$ | logQuery = false | |||
) |
Load collection data into object items
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 72 of file Collection.php.
00073 { 00074 parent::load($printQuery, $logQuery); 00075 $this->_loadTags($printQuery, $logQuery); 00076 return $this; 00077 }
$_tagRelTable [protected] |
Definition at line 38 of file Collection.php.
$_tagTable [protected] |
Definition at line 37 of file Collection.php.