Mage_Sitemap_Model_Mysql4_Catalog_Category Class Reference

Inheritance diagram for Mage_Sitemap_Model_Mysql4_Catalog_Category:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 getCollection ($storeId)

Protected Member Functions

 _construct ()
 _prepareCategory (array $categoryRow)
 _addFilter ($storeId, $attributeCode, $value, $type= '=')

Protected Attributes

 $_select
 $_attributesCache = array()


Detailed Description

Definition at line 35 of file Category.php.


Member Function Documentation

_addFilter ( storeId,
attributeCode,
value,
type = '=' 
) [protected]

Add attribute to filter

Parameters:
int $storeId
string $attributeCode
mixed $value
string $type
Returns:
Zend_Db_Select

Definition at line 135 of file Category.php.

00136     {
00137         if (!isset($this->_attributesCache[$attributeCode])) {
00138             $attribute = Mage::getSingleton('catalog/category')->getResource()->getAttribute($attributeCode);
00139 
00140             $this->_attributesCache[$attributeCode] = array(
00141                 'entity_type_id'    => $attribute->getEntityTypeId(),
00142                 'attribute_id'      => $attribute->getId(),
00143                 'table'             => $attribute->getBackend()->getTable(),
00144                 'is_global'         => $attribute->getIsGlobal(),
00145                 'backend_type'      => $attribute->getBackendType()
00146             );
00147         }
00148 
00149         $attribute = $this->_attributesCache[$attributeCode];
00150 
00151         if (!$this->_select instanceof Zend_Db_Select) {
00152             return false;
00153         }
00154 
00155         switch ($type) {
00156             case '=':
00157                 $conditionRule = '=?';
00158                 break;
00159             case 'in':
00160                 $conditionRule = ' IN(?)';
00161                 break;
00162             default:
00163                 return false;
00164                 break;
00165         }
00166 
00167         if ($attribute['backend_type'] == 'static') {
00168             $this->_select->where('e.' . $attributeCode . $conditionRule, $value);
00169         }
00170         else {
00171             if ($attribute['is_global']) {
00172 
00173             }
00174             else {
00175                 $this->_select->join(
00176                     array('t1_'.$attributeCode => $attribute['table']),
00177                     'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0',
00178                     array()
00179                 )
00180                 ->joinLeft(
00181                     array('t2_'.$attributeCode => $attribute['table']),
00182                     $this->_getWriteAdapter()->quoteInto('t1_'.$attributeCode.'.entity_id = t2_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.attribute_id = t2_'.$attributeCode.'.attribute_id AND t2_'.$attributeCode.'.store_id=?', $storeId),
00183                     array()
00184                 )
00185                 ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id'])
00186                 ->where('IFNULL(t2_'.$attributeCode.'.value, t1_'.$attributeCode.'.value)'.$conditionRule, $value);
00187             }
00188         }
00189 
00190         return $this->_select;
00191     }

_construct (  )  [protected]

Init resource model (catalog/category)

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 54 of file Category.php.

00055     {
00056         $this->_init('catalog/category', 'entity_id');
00057     }

_prepareCategory ( array categoryRow  )  [protected]

Prepare category

Parameters:
array $categoryRow
Returns:
Varien_Object

Definition at line 116 of file Category.php.

00117     {
00118         $category = new Varien_Object();
00119         $category->setId($categoryRow[$this->getIdFieldName()]);
00120         $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId();
00121         $category->setUrl($categoryUrl);
00122         return $category;
00123     }

getCollection ( storeId  ) 

Get category collection array

Returns:
array

Definition at line 64 of file Category.php.

00065     {
00066         $categories = array();
00067 
00068         $store = Mage::app()->getStore($storeId);
00069         /* @var $store Mage_Core_Model_Store */
00070 
00071         if (!$store) {
00072             return false;
00073         }
00074 
00075         $this->_select = $this->_getWriteAdapter()->select()
00076             ->from($this->getMainTable())
00077             ->where($this->getIdFieldName() . '=?', $store->getRootCategoryId());
00078         $categoryRow = $this->_getWriteAdapter()->fetchRow($this->_select);
00079 
00080         if (!$categoryRow) {
00081             return false;
00082         }
00083 
00084         $urConditions = array(
00085             'e.entity_id=ur.category_id',
00086             $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
00087             'ur.product_id IS NULL',
00088             $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
00089         );
00090         $this->_select = $this->_getWriteAdapter()->select()
00091             ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName()))
00092             ->joinLeft(
00093                 array('ur' => $this->getTable('core/url_rewrite')),
00094                 join(' AND ', $urConditions),
00095                 array('url'=>'request_path')
00096             )
00097             ->where('e.path LIKE ?', $categoryRow['path'] . '/%');
00098 
00099         $this->_addFilter($storeId, 'is_active', 1);
00100 
00101         $query = $this->_getWriteAdapter()->query($this->_select);
00102         while ($row = $query->fetch()) {
00103             $category = $this->_prepareCategory($row);
00104             $categories[$category->getId()] = $category;
00105         }
00106 
00107         return $categories;
00108     }


Member Data Documentation

$_attributesCache = array() [protected]

Definition at line 49 of file Category.php.

$_select [protected]

Definition at line 42 of file Category.php.


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

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