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_Catalog
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: * Catalog layer filter abstract
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Catalog_Block_Layer_Filter_Abstract extends Mage_Core_Block_Template
35: {
36: /**
37: * Catalog Layer Filter Attribute model
38: *
39: * @var Mage_Catalog_Model_Layer_Filter_Attribute
40: */
41: protected $_filter;
42:
43: /**
44: * Filter Model Name
45: *
46: * @var string
47: */
48: protected $_filterModelName;
49:
50: /**
51: * Whether to display product count for layer navigation items
52: * @var bool
53: */
54: protected $_displayProductCount = null;
55:
56: /**
57: * Initialize filter template
58: *
59: */
60: public function __construct()
61: {
62: parent::__construct();
63: $this->setTemplate('catalog/layer/filter.phtml');
64: }
65:
66: /**
67: * Initialize filter model object
68: *
69: * @return Mage_Catalog_Block_Layer_Filter_Abstract
70: */
71: public function init()
72: {
73: $this->_initFilter();
74: return $this;
75: }
76:
77: /**
78: * Init filter model object
79: *
80: * @return Mage_Catalog_Block_Layer_Filter_Abstract
81: */
82: protected function _initFilter()
83: {
84: if (!$this->_filterModelName) {
85: Mage::throwException(Mage::helper('catalog')->__('Filter model name must be declared.'));
86: }
87: $this->_filter = Mage::getModel($this->_filterModelName)
88: ->setLayer($this->getLayer());
89: $this->_prepareFilter();
90:
91: $this->_filter->apply($this->getRequest(), $this);
92: return $this;
93: }
94:
95: /**
96: * Prepare filter process
97: *
98: * @return Mage_Catalog_Block_Layer_Filter_Abstract
99: */
100: protected function _prepareFilter()
101: {
102: return $this;
103: }
104:
105: /**
106: * Retrieve name of the filter block
107: *
108: * @return string
109: */
110: public function getName()
111: {
112: return $this->_filter->getName();
113: }
114:
115: /**
116: * Retrieve filter items
117: *
118: * @return array
119: */
120: public function getItems()
121: {
122: return $this->_filter->getItems();
123: }
124:
125: /**
126: * Retrieve filter items count
127: *
128: * @return int
129: */
130: public function getItemsCount()
131: {
132: return $this->_filter->getItemsCount();
133: }
134:
135: /**
136: * Getter for $_displayProductCount
137: * @return bool
138: */
139: public function shouldDisplayProductCount()
140: {
141: if ($this->_displayProductCount === null) {
142: $this->_displayProductCount = Mage::helper('catalog')->shouldDisplayProductCountOnLayer();
143: }
144: return $this->_displayProductCount;
145: }
146:
147: /**
148: * Retrieve block html
149: *
150: * @return string
151: */
152: public function getHtml()
153: {
154: return parent::_toHtml();
155: }
156: }
157: