Public Member Functions | |
_initSelect () | |
setJoinFlag ($table) | |
getJoinFlag ($table) | |
unsetJoinFlag ($table=null) | |
addTagFilter ($tagId) | |
addProductFilter ($productId) | |
addStatusFilter ($status) | |
addDescOrder () | |
addGroupByTag () | |
addGroupByCustomer () | |
addGroupByCustomerProduct () | |
addCustomerFilter ($customerId) | |
getSelectCountSql () | |
addProductName () | |
setOrder ($attribute, $dir='desc') | |
setCountAttribute ($value) | |
getCountAttribute () | |
addFieldToFilter ($attribute, $condition=null) | |
Protected Member Functions | |
_joinFields () | |
Protected Attributes | |
$_allowDisableGrouping = true | |
$_countAttribute = 'tr.tag_relation_id' | |
$_joinFlags = array() |
Definition at line 35 of file Collection.php.
_initSelect | ( | ) |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 41 of file Collection.php.
00042 { 00043 parent::_initSelect(); 00044 $this->_joinFields(); 00045 $this->_setIdFieldName('tag_relation_id'); 00046 return $this; 00047 }
_joinFields | ( | ) | [protected] |
Definition at line 130 of file Collection.php.
00131 { 00132 $tagRelationTable = $this->getTable('tag/relation'); 00133 $tagTable = $this->getTable('tag/tag'); 00134 00135 //TODO: add full name logic 00136 $this->addAttributeToSelect('firstname') 00137 ->addAttributeToSelect('lastname') 00138 ->addAttributeToSelect('email'); 00139 00140 $this->getSelect() 00141 ->join(array('tr' => $tagRelationTable), 'tr.customer_id = e.entity_id') 00142 ->join(array('t' => $tagTable), 't.tag_id = tr.tag_id'); 00143 }
addCustomerFilter | ( | $ | customerId | ) |
Definition at line 124 of file Collection.php.
00125 { 00126 $this->getSelect()->where('tr.customer_id = ?', $customerId); 00127 return $this; 00128 }
addDescOrder | ( | ) |
Definition at line 92 of file Collection.php.
00093 { 00094 $this->getSelect() 00095 ->order('tr.tag_relation_id desc'); 00096 return $this; 00097 }
addFieldToFilter | ( | $ | attribute, | |
$ | condition = null | |||
) |
Wrapper for compatibility with Varien_Data_Collection_Db
mixed | $attribute | |
mixed | $condition |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Definition at line 224 of file Collection.php.
00224 { 00225 if ($attribute == 'name') { 00226 $this->getSelect()->where($this->_getConditionSql('t.name', $condition)); 00227 return $this; 00228 } else { 00229 return parent::addFieldToFilter($attribute, $condition); 00230 } 00231 }
addGroupByCustomer | ( | ) |
Definition at line 108 of file Collection.php.
00109 { 00110 $this->getSelect() 00111 ->group('tr.customer_id'); 00112 00113 $this->_allowDisableGrouping = false; 00114 return $this; 00115 }
addGroupByCustomerProduct | ( | ) |
Definition at line 117 of file Collection.php.
00118 { 00119 // Nothing need to group 00120 $this->_allowDisableGrouping = false; 00121 return $this; 00122 }
addGroupByTag | ( | ) |
Definition at line 99 of file Collection.php.
00100 { 00101 $this->getSelect() 00102 ->group('tr.tag_relation_id'); 00103 00104 $this->_allowDisableGrouping = false; 00105 return $this; 00106 }
addProductFilter | ( | $ | productId | ) |
Definition at line 78 of file Collection.php.
00079 { 00080 $this->getSelect() 00081 ->where('tr.product_id = ?', $productId); 00082 return $this; 00083 }
addProductName | ( | ) |
Definition at line 161 of file Collection.php.
00162 { 00163 $productsId = array(); 00164 $productsData = array(); 00165 00166 foreach ($this->getItems() as $item) 00167 { 00168 $productsId[] = $item->getProductId(); 00169 } 00170 00171 $productsId = array_unique($productsId); 00172 00173 /* small fix */ 00174 if( sizeof($productsId) == 0 ) { 00175 return; 00176 } 00177 00178 $collection = Mage::getModel('catalog/product')->getCollection() 00179 ->addAttributeToSelect('name') 00180 ->addAttributeToSelect('sku') 00181 ->addIdFilter($productsId); 00182 00183 $collection->load(); 00184 00185 foreach ($collection->getItems() as $item) 00186 { 00187 $productsData[$item->getId()] = $item->getName(); 00188 $productsSku[$item->getId()] = $item->getSku(); 00189 } 00190 00191 foreach ($this->getItems() as $item) 00192 { 00193 $item->setProduct($productsData[$item->getProductId()]); 00194 $item->setProductSku($productsSku[$item->getProductId()]); 00195 } 00196 return $this; 00197 }
addStatusFilter | ( | $ | status | ) |
Definition at line 85 of file Collection.php.
00086 { 00087 $this->getSelect() 00088 ->where('t.status = ?', $status); 00089 return $this; 00090 }
addTagFilter | ( | $ | tagId | ) |
Definition at line 71 of file Collection.php.
00072 { 00073 $this->getSelect() 00074 ->where('tr.tag_id = ?', $tagId); 00075 return $this; 00076 }
getCountAttribute | ( | ) |
getJoinFlag | ( | $ | table | ) |
Definition at line 55 of file Collection.php.
00056 { 00057 return isset($this->_joinFlags[$table]); 00058 }
getSelectCountSql | ( | ) |
Get SQL for get record count
Reimplemented from Mage_Customer_Model_Entity_Customer_Collection.
Reimplemented in Mage_Reports_Model_Mysql4_Tag_Customer_Collection.
Definition at line 145 of file Collection.php.
00146 { 00147 $countSelect = clone $this->getSelect(); 00148 $countSelect->reset(Zend_Db_Select::ORDER); 00149 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT); 00150 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET); 00151 00152 if( $this->_allowDisableGrouping ) { 00153 $countSelect->reset(Zend_Db_Select::GROUP); 00154 } 00155 00156 $sql = $countSelect->__toString(); 00157 $sql = preg_replace('/^select\s+.+?\s+from\s+/is', "select count({$this->getCountAttribute()}) from ", $sql); 00158 return $sql; 00159 }
setCountAttribute | ( | $ | value | ) |
setJoinFlag | ( | $ | table | ) |
Definition at line 49 of file Collection.php.
00050 { 00051 $this->_joinFlags[$table] = true; 00052 return $this; 00053 }
setOrder | ( | $ | attribute, | |
$ | dir = 'desc' | |||
) |
Set sorting order
$attribute can also be an array of attributes
string|array | $attribute | |
string | $dir |
Reimplemented from Mage_Eav_Model_Entity_Collection_Abstract.
Reimplemented in Mage_Reports_Model_Mysql4_Tag_Customer_Collection.
Definition at line 199 of file Collection.php.
00200 { 00201 switch( $attribute ) { 00202 case 'name': 00203 case 'status': 00204 $this->getSelect()->order($attribute . ' ' . $dir); 00205 break; 00206 00207 default: 00208 parent::setOrder($attribute, $dir); 00209 } 00210 return $this; 00211 }
unsetJoinFlag | ( | $ | table = null |
) |
Definition at line 60 of file Collection.php.
00061 { 00062 if (is_null($table)) { 00063 $this->_joinFlags = array(); 00064 } elseif ($this->getJoinFlag($table)) { 00065 unset($this->_joinFlags[$table]); 00066 } 00067 00068 return $this; 00069 }
$_allowDisableGrouping = true [protected] |
Definition at line 37 of file Collection.php.
$_countAttribute = 'tr.tag_relation_id' [protected] |
Definition at line 38 of file Collection.php.
$_joinFlags = array() [protected] |
Definition at line 39 of file Collection.php.