00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_CatalogIndex 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Index data retreiver factory 00029 * 00030 * @author Magento Core Team <core@magentocommerce.com> 00031 */ 00032 class Mage_CatalogIndex_Model_Retreiver extends Mage_Core_Model_Abstract 00033 { 00034 const CHILDREN_FOR_TIERS = 1; 00035 const CHILDREN_FOR_PRICES = 2; 00036 const CHILDREN_FOR_ATTRIBUTES = 3; 00037 00038 protected $_attributeIdCache = array(); 00039 00040 /** 00041 * Customer group cache 00042 * 00043 * @var Mage_Customer_Model_Mysql4_Group_Collection 00044 */ 00045 protected $_customerGroups; 00046 00047 /** 00048 * Retreiver model names cache 00049 * 00050 * @var array 00051 */ 00052 protected $_retreivers = array(); 00053 00054 /** 00055 * Retreiver factory init, load retreiver settings 00056 * 00057 */ 00058 protected function _construct() 00059 { 00060 $config = Mage::getConfig()->getNode('global/catalog/product/type')->asArray(); 00061 foreach ($config as $type=>$data) { 00062 if (isset($data['index_data_retreiver'])) { 00063 $this->_retreivers[$type] = $data['index_data_retreiver']; 00064 } 00065 } 00066 00067 $this->_init('catalogindex/retreiver'); 00068 } 00069 00070 /** 00071 * Returns data retreiver model by specified product type 00072 * 00073 * @param string $type 00074 * @return Mage_CatalogIndex_Model_Data_Abstract 00075 */ 00076 public function getRetreiver($type) 00077 { 00078 if (isset($this->_retreivers[$type])) { 00079 return Mage::getSingleton($this->_retreivers[$type]); 00080 } else { 00081 Mage::throwException("Data retreiver for '{$type}' is not defined"); 00082 } 00083 } 00084 00085 /** 00086 * Return customer group collection 00087 * 00088 * @return Mage_Customer_Model_Entity_Group_Collection 00089 */ 00090 public function getCustomerGroups() 00091 { 00092 if (is_null($this->_customerGroups)) { 00093 $this->_customerGroups = Mage::getModel('customer/group')->getCollection(); 00094 } 00095 return $this->_customerGroups; 00096 } 00097 00098 /** 00099 * Return product ids sorted by type 00100 * 00101 * @param array $products 00102 * @return array 00103 */ 00104 public function assignProductTypes($products) 00105 { 00106 $flat = $this->_getResource()->getProductTypes($products); 00107 $result = array(); 00108 foreach ($flat as $one) { 00109 $result[$one['type']][] = $one['id']; 00110 } 00111 return $result; 00112 } 00113 }