Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Adminhtml_Block_Sitemap
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Action
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Link
  • Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Time
  • Mage_Adminhtml_SitemapController
  • Mage_Sitemap_Helper_Data
  • Mage_Sitemap_Model_Mysql4_Catalog_Category
  • Mage_Sitemap_Model_Mysql4_Catalog_Product
  • Mage_Sitemap_Model_Mysql4_Cms_Page
  • Mage_Sitemap_Model_Mysql4_Sitemap
  • Mage_Sitemap_Model_Mysql4_Sitemap_Collection
  • Mage_Sitemap_Model_Observer
  • Mage_Sitemap_Model_Resource_Catalog_Category
  • Mage_Sitemap_Model_Resource_Catalog_Product
  • Mage_Sitemap_Model_Resource_Cms_Page
  • Mage_Sitemap_Model_Resource_Sitemap
  • Mage_Sitemap_Model_Resource_Sitemap_Collection
  • Mage_Sitemap_Model_Sitemap
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Sitemap
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Sitemap resource catalog collection model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Sitemap
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Sitemap_Model_Resource_Catalog_Category extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Collection Zend Db select
 39:      *
 40:      * @var Zend_Db_Select
 41:      */
 42:     protected $_select;
 43: 
 44:     /**
 45:      * Attribute cache
 46:      *
 47:      * @var array
 48:      */
 49:     protected $_attributesCache    = array();
 50: 
 51:     /**
 52:      * Init resource model (catalog/category)
 53:      *
 54:      */
 55:     protected function _construct()
 56:     {
 57:         $this->_init('catalog/category', 'entity_id');
 58:     }
 59: 
 60:     /**
 61:      * Get category collection array
 62:      *
 63:      * @param unknown_type $storeId
 64:      * @return array
 65:      */
 66:     public function getCollection($storeId)
 67:     {
 68:         $categories = array();
 69: 
 70:         $store = Mage::app()->getStore($storeId);
 71:         /* @var $store Mage_Core_Model_Store */
 72: 
 73:         if (!$store) {
 74:             return false;
 75:         }
 76: 
 77:         $this->_select = $this->_getWriteAdapter()->select()
 78:             ->from($this->getMainTable())
 79:             ->where($this->getIdFieldName() . '=?', $store->getRootCategoryId());
 80:         $categoryRow = $this->_getWriteAdapter()->fetchRow($this->_select);
 81: 
 82:         if (!$categoryRow) {
 83:             return false;
 84:         }
 85: 
 86:         $urConditions = array(
 87:             'e.entity_id=ur.category_id',
 88:             $this->_getWriteAdapter()->quoteInto('ur.store_id=?', $store->getId()),
 89:             'ur.product_id IS NULL',
 90:             $this->_getWriteAdapter()->quoteInto('ur.is_system=?', 1),
 91:         );
 92:         $this->_select = $this->_getWriteAdapter()->select()
 93:             ->from(array('e' => $this->getMainTable()), array($this->getIdFieldName()))
 94:             ->joinLeft(
 95:                 array('ur' => $this->getTable('core/url_rewrite')),
 96:                 join(' AND ', $urConditions),
 97:                 array('url'=>'request_path')
 98:             )
 99:             ->where('e.path LIKE ?', $categoryRow['path'] . '/%');
100: 
101:         $this->_addFilter($storeId, 'is_active', 1);
102: 
103:         $query = $this->_getWriteAdapter()->query($this->_select);
104:         while ($row = $query->fetch()) {
105:             $category = $this->_prepareCategory($row);
106:             $categories[$category->getId()] = $category;
107:         }
108: 
109:         return $categories;
110:     }
111: 
112:     /**
113:      * Prepare category
114:      *
115:      * @param array $categoryRow
116:      * @return Varien_Object
117:      */
118:     protected function _prepareCategory(array $categoryRow)
119:     {
120:         $category = new Varien_Object();
121:         $category->setId($categoryRow[$this->getIdFieldName()]);
122:         $categoryUrl = !empty($categoryRow['url']) ? $categoryRow['url'] : 'catalog/category/view/id/' . $category->getId();
123:         $category->setUrl($categoryUrl);
124:         return $category;
125:     }
126: 
127:     /**
128:      * Add attribute to filter
129:      *
130:      * @param int $storeId
131:      * @param string $attributeCode
132:      * @param mixed $value
133:      * @param string $type
134:      * @return Zend_Db_Select
135:      */
136:     protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
137:     {
138:         if (!isset($this->_attributesCache[$attributeCode])) {
139:             $attribute = Mage::getSingleton('catalog/category')->getResource()->getAttribute($attributeCode);
140: 
141:             $this->_attributesCache[$attributeCode] = array(
142:                 'entity_type_id'    => $attribute->getEntityTypeId(),
143:                 'attribute_id'      => $attribute->getId(),
144:                 'table'             => $attribute->getBackend()->getTable(),
145:                 'is_global'         => $attribute->getIsGlobal(),
146:                 'backend_type'      => $attribute->getBackendType()
147:             );
148:         }
149: 
150:         $attribute = $this->_attributesCache[$attributeCode];
151: 
152:         if (!$this->_select instanceof Zend_Db_Select) {
153:             return false;
154:         }
155: 
156:         switch ($type) {
157:             case '=':
158:                 $conditionRule = '=?';
159:                 break;
160:             case 'in':
161:                 $conditionRule = ' IN(?)';
162:                 break;
163:             default:
164:                 return false;
165:                 break;
166:         }
167: 
168:         if ($attribute['backend_type'] == 'static') {
169:             $this->_select->where('e.' . $attributeCode . $conditionRule, $value);
170:         } else {
171:             $this->_select->join(
172:                 array('t1_'.$attributeCode => $attribute['table']),
173:                 'e.entity_id=t1_'.$attributeCode.'.entity_id AND t1_'.$attributeCode.'.store_id=0',
174:                 array()
175:             )
176:             ->where('t1_'.$attributeCode.'.attribute_id=?', $attribute['attribute_id']);
177: 
178:             if ($attribute['is_global']) {
179:                 $this->_select->where('t1_'.$attributeCode.'.value'.$conditionRule, $value);
180:             } else {
181:                 $ifCase = $this->_select->getAdapter()->getCheckSql('t2_'.$attributeCode.'.value_id > 0', 't2_'.$attributeCode.'.value', 't1_'.$attributeCode.'.value');
182:                 $this->_select->joinLeft(
183:                     array('t2_'.$attributeCode => $attribute['table']),
184:                     $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),
185:                     array()
186:                 )
187:                 ->where('('.$ifCase.')'.$conditionRule, $value);
188:             }
189:         }
190: 
191:         return $this->_select;
192:     }
193: }
194: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0