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: * Filter item model
29: *
30: * @category Mage
31: * @package Mage_Catalog
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Catalog_Model_Layer_Filter_Item extends Varien_Object
35: {
36: /**
37: * Get filter instance
38: *
39: * @return Mage_Catalog_Model_Layer_Filter_Abstract
40: */
41: public function getFilter()
42: {
43: $filter = $this->getData('filter');
44: if (!is_object($filter)) {
45: Mage::throwException(
46: Mage::helper('catalog')->__('Filter must be an object. Please set correct filter.')
47: );
48: }
49: return $filter;
50: }
51:
52: /**
53: * Get filter item url
54: *
55: * @return string
56: */
57: public function getUrl()
58: {
59: $query = array(
60: $this->getFilter()->getRequestVar()=>$this->getValue(),
61: Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null // exclude current page from urls
62: );
63: return Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$query));
64: }
65:
66: /**
67: * Get url for remove item from filter
68: *
69: * @return string
70: */
71: public function getRemoveUrl()
72: {
73: $query = array($this->getFilter()->getRequestVar()=>$this->getFilter()->getResetValue());
74: $params['_current'] = true;
75: $params['_use_rewrite'] = true;
76: $params['_query'] = $query;
77: $params['_escape'] = true;
78: return Mage::getUrl('*/*/*', $params);
79: }
80:
81: /**
82: * Get url for "clear" link
83: *
84: * @return false|string
85: */
86: public function getClearLinkUrl()
87: {
88: $clearLinkText = $this->getFilter()->getClearLinkText();
89: if (!$clearLinkText) {
90: return false;
91: }
92:
93: $urlParams = array(
94: '_current' => true,
95: '_use_rewrite' => true,
96: '_query' => array($this->getFilter()->getRequestVar() => null),
97: '_escape' => true,
98: );
99: return Mage::getUrl('*/*/*', $urlParams);
100: }
101:
102: /**
103: * Get item filter name
104: *
105: * @return string
106: */
107: public function getName()
108: {
109: return $this->getFilter()->getName();
110: }
111:
112: /**
113: * Get item value as string
114: *
115: * @return string
116: */
117: public function getValueString()
118: {
119: $value = $this->getValue();
120: if (is_array($value)) {
121: return implode(',', $value);
122: }
123: return $value;
124: }
125: }
126: