Mage_Eav_Model_Mysql4_Entity_Attribute_Collection Class Reference

Inheritance diagram for Mage_Eav_Model_Mysql4_Entity_Attribute_Collection:

Mage_Core_Model_Mysql4_Collection_Abstract Varien_Data_Collection_Db Varien_Data_Collection

List of all members.

Public Member Functions

 _construct ()
 useLoadDataFields ()
 setEntityTypeFilter ($typeId)
 setAttributeSetFilter ($setId)
 setAttributeSetsFilter (array $setIds)
 setInAllAttributeSetsFilter (array $setIds)
 setAttributeSetExcludeFilter ($setId)
 setAttributesExcludeFilter ($attributes)
 setAttributeGroupFilter ($groupId)
 addAttributeGrouping ()
 addVisibleFilter ()
 addIsFilterableFilter ()
 addIsFilterableInSearchFilter ()
 addIsUniqueFilter ()
 addIsNotUniqueFilter ()
 addIsSearchableFilter ()
 addHasOptionsFilter ()
 addDisplayInAdvancedSearchFilter ()
 setFrontendInputTypeFilter ($frontendInputType)
 addSetInfo ($flag=true)
 checkConfigurableProducts ()
 setCodeFilter ($code)

Protected Member Functions

 _addSetInfo ()
 _afterLoadData ()

Protected Attributes

 $_addSetInfoFlag = false


Detailed Description

Definition at line 34 of file Collection.php.


Member Function Documentation

_addSetInfo (  )  [protected]

Ad information about attribute sets to collection result data

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 321 of file Collection.php.

00322     {
00323         if ($this->_addSetInfoFlag) {
00324             $attributeIds = array();
00325             foreach ($this->_data as &$dataItem) {
00326                 $attributeIds[] = $dataItem['attribute_id'];
00327             }
00328             $attributeToSetInfo = array();
00329 
00330             if (count($attributeIds) > 0) {
00331                 $select = $this->getConnection()->select()
00332                     ->from(
00333                         array('entity' => $this->getTable('entity_attribute')),
00334                         array('attribute_id','attribute_set_id', 'attribute_group_id', 'sort_order')
00335                     )
00336                     ->joinLeft(
00337                         array('group' => $this->getTable('attribute_group')),
00338                         'entity.attribute_group_id=group.attribute_group_id',
00339                         array('group_sort_order' => 'sort_order')
00340                     )
00341                     ->where('attribute_id IN (?)', $attributeIds);
00342                 $result = $this->getConnection()->fetchAll($select);
00343 
00344                 foreach ($result as $row) {
00345                     $data = array(
00346                         'group_id'      => $row['attribute_group_id'],
00347                         'group_sort'    => $row['group_sort_order'],
00348                         'sort'          => $row['sort_order']
00349                     );
00350                     $attributeToSetInfo[$row['attribute_id']][$row['attribute_set_id']] = $data;
00351                 }
00352             }
00353 
00354             foreach ($this->_data as &$attributeData) {
00355                 if (isset($attributeToSetInfo[$attributeData['attribute_id']])) {
00356                     $setInfo = $attributeToSetInfo[$attributeData['attribute_id']];
00357                 } else {
00358                     $setInfo = array();
00359                 }
00360 
00361                 $attributeData['attribute_set_info'] = $setInfo;
00362             }
00363 
00364             unset($attributeToSetInfo);
00365             unset($attributeIds);
00366         }
00367         return $this;
00368     }

_afterLoadData (  )  [protected]

Proces loaded collection data

Returns:
Varien_Data_Collection_Db

Reimplemented from Varien_Data_Collection_Db.

Definition at line 370 of file Collection.php.

00371     {
00372         $this->_addSetInfo();
00373         return parent::_afterLoadData();
00374     }

_construct (  ) 

Resource model initialization

Reimplemented from Mage_Core_Model_Mysql4_Collection_Abstract.

Definition at line 46 of file Collection.php.

00047     {
00048         $this->_init('eav/entity_attribute');
00049     }

addAttributeGrouping (  ) 

Declare group by attribute id condition for collection select

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 190 of file Collection.php.

00191     {
00192         $this->getSelect()->group('entity_attribute.attribute_id');
00193         return $this;
00194     }

addDisplayInAdvancedSearchFilter (  ) 

Specify "is_visible_in_advanced_search" filter

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 284 of file Collection.php.

00284                                                       {
00285         $this->getSelect()
00286             ->where('main_table.is_visible_in_advanced_search = ?', 1);
00287 
00288         return $this;
00289     }

addHasOptionsFilter (  ) 

Specify filter to select just attributes with options

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 267 of file Collection.php.

00268     {
00269         $this->getSelect()
00270             ->joinLeft(
00271                 array('ao'=>$this->getTable('eav/attribute_option')), 'ao.attribute_id = main_table.attribute_id', 'option_id'
00272             )
00273             ->group('main_table.attribute_id')
00274             ->where('(main_table.frontend_input = ? and option_id > 0) or (main_table.frontend_input <> ?) or (main_table.is_user_defined = 0)', 'select', 'select');
00275 
00276         return $this;
00277     }

addIsFilterableFilter (  ) 

Specify "is_filterable" filter

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 212 of file Collection.php.

00213     {
00214         $this->getSelect()->where('main_table.is_filterable>0');
00215         return $this;
00216     }

addIsFilterableInSearchFilter (  ) 

Add filterable in search filter

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 223 of file Collection.php.

00224     {
00225         $this->getSelect()->where('main_table.is_filterable_in_search>0');
00226         return $this;
00227     }

addIsNotUniqueFilter (  ) 

Specify "is_unique" filter as false

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 245 of file Collection.php.

00246     {
00247         $this->getSelect()->where('main_table.is_unique=0');
00248         return $this;
00249     }

addIsSearchableFilter (  ) 

Specify "is_searchable" filter

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 256 of file Collection.php.

00257     {
00258         $this->getSelect()->where('main_table.is_searchable=1');
00259         return $this;
00260     }

addIsUniqueFilter (  ) 

Specify "is_unique" filter as true

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 234 of file Collection.php.

00235     {
00236         $this->getSelect()->where('main_table.is_unique>0');
00237         return $this;
00238     }

addSetInfo ( flag = true  ) 

Flag for adding information about attributes sets to result

Parameters:
bool $flag
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 310 of file Collection.php.

00311     {
00312         $this->_addSetInfoFlag = $flag;
00313         return $this;
00314     }

addVisibleFilter (  ) 

Specify filter by "is_visible" field

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 201 of file Collection.php.

00202     {
00203         $this->getSelect()->where('main_table.is_visible=?', 1);
00204         return $this;
00205     }

checkConfigurableProducts (  ) 

TODO: issue #5126

Returns:
unknown

Definition at line 381 of file Collection.php.

00382     {
00383 // was:
00384 /*
00385 SELECT `main_table`.*, `entity_attribute`.*
00386 FROM `eav_attribute` AS `main_table`
00387     INNER JOIN `eav_entity_attribute` AS `entity_attribute` ON entity_attribute.attribute_id=main_table.attribute_id
00388 WHERE (entity_attribute.attribute_group_id='46') AND (main_table.is_visible=1)
00389 */
00390 // to be done: left join catalog_product_super_attribute and count appropriate lines
00391 /*
00392 SELECT `main_table`.*, `entity_attribute`.*, COUNT(`super`.attribute_id) AS `is_used_in_configurable`
00393 FROM `eav_attribute` AS `main_table`
00394     INNER JOIN `eav_entity_attribute` AS `entity_attribute` ON entity_attribute.attribute_id=main_table.attribute_id
00395     LEFT JOIN `catalog_product_super_attribute` AS `super` ON `main_table`.attribute_id=`super`.attribute_id
00396 WHERE (entity_attribute.attribute_group_id='46') AND (main_table.is_visible=1)
00397 GROUP BY `main_table`.attribute_id
00398 */
00399         return $this;
00400     }

setAttributeGroupFilter ( groupId  ) 

Filter by attribute group id

Parameters:
int $groupId
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 177 of file Collection.php.

00178     {
00179         $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*');
00180         $this->getSelect()->where('entity_attribute.attribute_group_id=?', $groupId);
00181         $this->setOrder('sort_order', 'asc');
00182         return $this;
00183     }

setAttributeSetExcludeFilter ( setId  ) 

Add filter which exclude attributes assigned to attribute set

Parameters:
int $setId
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 151 of file Collection.php.

00152     {
00153         $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*');
00154         $this->getSelect()->where('entity_attribute.attribute_set_id != ?', $setId);
00155         $this->setOrder('sort_order', 'asc');
00156         return $this;
00157     }

setAttributeSetFilter ( setId  ) 

Specify attribute set filter

Parameters:
int $setId
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 92 of file Collection.php.

00093     {
00094         if (is_array($setId)) {
00095             if (!empty($setId)) {
00096                 $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', 'attribute_id');
00097                 $this->getSelect()->where('entity_attribute.attribute_set_id IN(?)', $setId);
00098             }
00099         }
00100         elseif($setId) {
00101             $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', '*');
00102             $this->getSelect()->where('entity_attribute.attribute_set_id=?', $setId);
00103             $this->setOrder('sort_order', 'asc');
00104         }
00105         return $this;
00106     }

setAttributeSetsFilter ( array setIds  ) 

Specify multiple attribute sets filter Result will be ordered by sort_order

Parameters:
array $setIds
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 115 of file Collection.php.

00116     {
00117         $this->join('entity_attribute', 'entity_attribute.attribute_id=main_table.attribute_id', 'attribute_id');
00118         $this->getSelect()->distinct(true);
00119         $this->getSelect()->where('entity_attribute.attribute_set_id IN(?)', $setIds);
00120         $this->setOrder('sort_order', 'asc');
00121         return $this;
00122     }

setAttributesExcludeFilter ( attributes  ) 

Exclude attributes filter

Parameters:
array $attributes
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 165 of file Collection.php.

00166     {
00167         $this->getSelect()->where('main_table.attribute_id NOT IN(?)', $attributes);
00168         return $this;
00169     }

setCodeFilter ( code  ) 

Specify collection attribute codes filter

Parameters:
string || array $code
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 408 of file Collection.php.

00409     {
00410         if (empty($code)) {
00411             return $this;
00412         }
00413         if (!is_array($code)) {
00414             $code = array($code);
00415         }
00416         $this->getSelect()->where('main_table.attribute_code IN(?)', $code);
00417         return $this;
00418     }

setEntityTypeFilter ( typeId  ) 

Specify attribute entity type filter

Parameters:
int $typeId
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 80 of file Collection.php.

00081     {
00082         $this->getSelect()->where('main_table.entity_type_id=?', $typeId);
00083         return $this;
00084     }

setFrontendInputTypeFilter ( frontendInputType  ) 

Apply filter by attribute frontend input type

Parameters:
string $frontendInputType
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 297 of file Collection.php.

00298     {
00299         $this->getSelect()
00300             ->where('main_table.frontend_input = ?', $frontendInputType);
00301         return $this;
00302     }

setInAllAttributeSetsFilter ( array setIds  ) 

Filter for selecting of attributes that is in all sets

Parameters:
array $setIds
Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 130 of file Collection.php.

00131     {
00132         foreach ($setIds as $setId) {
00133             $setId = (int) $setId;
00134             if (!$setId) {
00135                 continue;
00136             }
00137             $this->getSelect()->join(array('entity_attribute_'.$setId=>$this->getTable('entity_attribute')), 'entity_attribute_' . $setId . '.attribute_id=main_table.attribute_id and entity_attribute_' . $setId . '.attribute_set_id=' . $setId, 'attribute_id');
00138         }
00139 
00140         $this->getSelect()->distinct(true);
00141         $this->setOrder('is_user_defined', 'asc');
00142         return $this;
00143     }

useLoadDataFields (  ) 

Specify select columns which are used for load arrtibute values

Returns:
Mage_Eav_Model_Mysql4_Entity_Attribute_Collection

Definition at line 56 of file Collection.php.

00057     {
00058         $this->getSelect()->reset(Zend_Db_Select::COLUMNS);
00059         $this->getSelect()->columns(array(
00060             'attribute_id',
00061             'entity_type_id',
00062             'attribute_code',
00063             'attribute_model',
00064             'backend_model',
00065             'backend_type',
00066             'backend_table',
00067             'frontend_input',
00068             'source_model',
00069             'is_global'
00070         ));
00071         return $this;
00072     }


Member Data Documentation

$_addSetInfoFlag = false [protected]

Definition at line 41 of file Collection.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:12 2009 for Magento by  doxygen 1.5.8