====== Фильтр производителей ====== execute($Shop_Controller_Show); * * В xsl для флажков checked * В xsl для списка * Вызов в шаблоне * Далее заменяем код переменной filter ?filter=1&sorting=&price_from=&price_to=&=&[]= * */ class Kad_Shop_Producer_Filter { public $input_name = 'producer'; /** * The singleton instances. * @var mixed */ static public $instance = NULL; /** * Register an existing instance as a singleton. * @return object */ static public function instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; } public function __construct() { } /* * Получаем производителей */ public function getProducers() { $aShop_Producers = Kad_Shop_Producer::getAll($this->Shop_Controller_Show->group, true); return $aShop_Producers; } /* * Добавляем производителей к xml */ public function addToXml($aShopProducers, $aActiveProducers) { $oProducersXmlEntity = Core::factory('Core_Xml_Entity')->name('producers'); $aShopProducers = $this->getProducers(); foreach ($aShopProducers as $oShopProducer) { $oProducersXmlEntity->addEntity( $oShopProducer->clearEntities() ); } $this->Shop_Controller_Show->addEntity($oProducersXmlEntity); if ($aActiveProducers) { $xmlFilters = Core::factory('Core_Xml_Entity')->name('filters'); $xmlUsed = Core::factory('Core_Xml_Entity')->name('used'); $oActiveProducersXmlEntity = Core::factory('Core_Xml_Entity')->name('producers'); foreach ($aActiveProducers as $ActiveProducer) { $oProducerXml = Core::factory('Core_Xml_Entity')->name($this->input_name)->value($ActiveProducer); $oActiveProducersXmlEntity->addEntity($oProducerXml); } $this->Shop_Controller_Show->addEntity($xmlFilters->addEntity($xmlUsed->addEntity($oActiveProducersXmlEntity))); } return true; } /* * Фильтр по производителям */ public function filterProducers($aProducers = array()) { $this->Shop_Controller_Show->shopItems() ->queryBuilder() ->where('shop_items.shop_producer_id', 'IN', $aProducers); $this->Shop_Controller_Show->addCacheSignature( 'producer=' . implode(',', $aProducers)); } public function execute($Shop_Controller_Show = Shop_Controller_Show) { $this->Shop_Controller_Show = $Shop_Controller_Show; $aProducers = Core_Array::getGet($this->input_name); if ($aProducers && !is_array($aProducers)) { $aProducers = array($aProducers); } if (count($aProducers)) { $this->filterProducers($aProducers); } $aShop_Producers = Kad_Shop_Producer::getAll($this->Shop_Controller_Show->group); $this->addToXml($aShop_Producers, $aProducers); } }