1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Abstract
35: {
36: protected function _getOptions()
37: {
38: $emptyOption = array('value' => null, 'label' => '');
39:
40: $optionGroups = $this->getColumn()->getOptionGroups();
41: if ($optionGroups) {
42: array_unshift($optionGroups, $emptyOption);
43: return $optionGroups;
44: }
45:
46: $colOptions = $this->getColumn()->getOptions();
47: if (!empty($colOptions) && is_array($colOptions) ) {
48: $options = array($emptyOption);
49: foreach ($colOptions as $value => $label) {
50: $options[] = array('value' => $value, 'label' => $label);
51: }
52: return $options;
53: }
54: return array();
55: }
56:
57: 58: 59: 60: 61: 62: 63:
64: protected function _renderOption($option, $value)
65: {
66: $selected = (($option['value'] == $value && (!is_null($value))) ? ' selected="selected"' : '' );
67: return '<option value="'. $this->escapeHtml($option['value']).'"'.$selected.'>'.$this->escapeHtml($option['label']).'</option>';
68: }
69:
70: public function getHtml()
71: {
72: $html = '<select name="'.$this->_getHtmlName().'" id="'.$this->_getHtmlId().'" class="no-changes">';
73: $value = $this->getValue();
74: foreach ($this->_getOptions() as $option){
75: if (is_array($option['value'])) {
76: $html .= '<optgroup label="' . $this->escapeHtml($option['label']) . '">';
77: foreach ($option['value'] as $subOption) {
78: $html .= $this->_renderOption($subOption, $value);
79: }
80: $html .= '</optgroup>';
81: } else {
82: $html .= $this->_renderOption($option, $value);
83: }
84: }
85: $html.='</select>';
86: return $html;
87: }
88:
89: public function getCondition()
90: {
91: if (is_null($this->getValue())) {
92: return null;
93: }
94: return array('eq' => $this->getValue());
95: }
96:
97: }
98: