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 extends Mage_Adminhtml_Block_Widget
35: {
36: protected $_grid;
37: protected $_renderer;
38: protected $_filter;
39: protected $_type;
40: protected $_cssClass=null;
41:
42: public function __construct($data=array())
43: {
44: parent::__construct($data);
45: }
46:
47: public function setGrid($grid)
48: {
49: $this->_grid = $grid;
50:
51: $this->getFilter();
52: return $this;
53: }
54:
55: public function getGrid()
56: {
57: return $this->_grid;
58: }
59:
60: public function isLast()
61: {
62: return $this->getId() == $this->getGrid()->getLastColumnId();
63: }
64:
65: public function getHtmlProperty()
66: {
67: return $this->getRenderer()->renderProperty();
68: }
69:
70: public function ()
71: {
72: return $this->getRenderer()->renderHeader();
73: }
74:
75: public function getCssClass()
76: {
77: if (is_null($this->_cssClass)) {
78: if ($this->getAlign()) {
79: $this->_cssClass .= 'a-'.$this->getAlign();
80: }
81:
82: if ($this->hasData('column_css_class')) {
83: $this->_cssClass .= ' '. $this->getData('column_css_class');
84: }
85: if ($this->getEditable()) {
86: $this->_cssClass .= ' editable';
87: }
88: }
89:
90: return $this->_cssClass;
91: }
92:
93: public function getCssProperty()
94: {
95: return $this->getRenderer()->renderCss();
96: }
97:
98: public function ()
99: {
100: $class = $this->getData('header_css_class');
101: if (($this->getSortable()===false) || ($this->getGrid()->getSortable()===false)) {
102: $class .= ' no-link';
103: }
104: if ($this->isLast()) {
105: $class .= ' last';
106: }
107: return $class;
108: }
109:
110: public function ()
111: {
112: $str = '';
113: if ($class = $this->getHeaderCssClass()) {
114: $str.= ' class="'.$class.'"';
115: }
116:
117: return $str;
118: }
119:
120: 121: 122: 123: 124: 125:
126: public function getRowField(Varien_Object $row)
127: {
128: $renderedValue = $this->getRenderer()->render($row);
129: if ($this->getHtmlDecorators()) {
130: $renderedValue = $this->_applyDecorators($renderedValue, $this->getHtmlDecorators());
131: }
132:
133: 134: 135: 136: 137: 138: 139:
140: $frameCallback = $this->getFrameCallback();
141: if (is_array($frameCallback)) {
142: $renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, false);
143: }
144:
145: return $renderedValue;
146: }
147:
148: 149: 150: 151: 152: 153:
154: public function getRowFieldExport(Varien_Object $row)
155: {
156: $renderedValue = $this->getRenderer()->renderExport($row);
157:
158: 159: 160: 161: 162: 163: 164:
165: $frameCallback = $this->getFrameCallback();
166: if (is_array($frameCallback)) {
167: $renderedValue = call_user_func($frameCallback, $renderedValue, $row, $this, true);
168: }
169:
170: return $renderedValue;
171: }
172:
173: 174: 175: 176: 177: 178: 179:
180: protected function &_applyDecorators($value, $decorators)
181: {
182: if (!is_array($decorators)) {
183: if (is_string($decorators)) {
184: $decorators = explode(' ', $decorators);
185: }
186: }
187: if ((!is_array($decorators)) || empty($decorators)) {
188: return $value;
189: }
190: switch (array_shift($decorators)) {
191: case 'nobr':
192: $value = '<span class="nobr">' . $value . '</span>';
193: break;
194: }
195: if (!empty($decorators)) {
196: return $this->_applyDecorators($value, $decorators);
197: }
198: return $value;
199: }
200:
201: public function setRenderer($renderer)
202: {
203: $this->_renderer = $renderer;
204: return $this;
205: }
206:
207: protected function _getRendererByType()
208: {
209: $type = strtolower($this->getType());
210: $renderers = $this->getGrid()->getColumnRenderers();
211:
212: if (is_array($renderers) && isset($renderers[$type])) {
213: return $renderers[$type];
214: }
215:
216: switch ($type) {
217: case 'date':
218: $rendererClass = 'adminhtml/widget_grid_column_renderer_date';
219: break;
220: case 'datetime':
221: $rendererClass = 'adminhtml/widget_grid_column_renderer_datetime';
222: break;
223: case 'number':
224: $rendererClass = 'adminhtml/widget_grid_column_renderer_number';
225: break;
226: case 'currency':
227: $rendererClass = 'adminhtml/widget_grid_column_renderer_currency';
228: break;
229: case 'price':
230: $rendererClass = 'adminhtml/widget_grid_column_renderer_price';
231: break;
232: case 'country':
233: $rendererClass = 'adminhtml/widget_grid_column_renderer_country';
234: break;
235: case 'concat':
236: $rendererClass = 'adminhtml/widget_grid_column_renderer_concat';
237: break;
238: case 'action':
239: $rendererClass = 'adminhtml/widget_grid_column_renderer_action';
240: break;
241: case 'options':
242: $rendererClass = 'adminhtml/widget_grid_column_renderer_options';
243: break;
244: case 'checkbox':
245: $rendererClass = 'adminhtml/widget_grid_column_renderer_checkbox';
246: break;
247: case 'massaction':
248: $rendererClass = 'adminhtml/widget_grid_column_renderer_massaction';
249: break;
250: case 'radio':
251: $rendererClass = 'adminhtml/widget_grid_column_renderer_radio';
252: break;
253: case 'input':
254: $rendererClass = 'adminhtml/widget_grid_column_renderer_input';
255: break;
256: case 'select':
257: $rendererClass = 'adminhtml/widget_grid_column_renderer_select';
258: break;
259: case 'text':
260: $rendererClass = 'adminhtml/widget_grid_column_renderer_longtext';
261: break;
262: case 'store':
263: $rendererClass = 'adminhtml/widget_grid_column_renderer_store';
264: break;
265: case 'wrapline':
266: $rendererClass = 'adminhtml/widget_grid_column_renderer_wrapline';
267: break;
268: case 'theme':
269: $rendererClass = 'adminhtml/widget_grid_column_renderer_theme';
270: break;
271: default:
272: $rendererClass = 'adminhtml/widget_grid_column_renderer_text';
273: break;
274: }
275: return $rendererClass;
276: }
277:
278: 279: 280: 281: 282:
283: public function getRenderer()
284: {
285: if (!$this->_renderer) {
286: $rendererClass = $this->getData('renderer');
287: if (!$rendererClass) {
288: $rendererClass = $this->_getRendererByType();
289: }
290: $this->_renderer = $this->getLayout()->createBlock($rendererClass)
291: ->setColumn($this);
292: }
293: return $this->_renderer;
294: }
295:
296: public function setFilter($filterClass)
297: {
298: $this->_filter = $this->getLayout()->createBlock($filterClass)
299: ->setColumn($this);
300: }
301:
302: protected function _getFilterByType()
303: {
304: $type = strtolower($this->getType());
305: $filters = $this->getGrid()->getColumnFilters();
306: if (is_array($filters) && isset($filters[$type])) {
307: return $filters[$type];
308: }
309:
310: switch ($type) {
311: case 'datetime':
312: $filterClass = 'adminhtml/widget_grid_column_filter_datetime';
313: break;
314: case 'date':
315: $filterClass = 'adminhtml/widget_grid_column_filter_date';
316: break;
317: case 'range':
318: case 'number':
319: case 'currency':
320: $filterClass = 'adminhtml/widget_grid_column_filter_range';
321: break;
322: case 'price':
323: $filterClass = 'adminhtml/widget_grid_column_filter_price';
324: break;
325: case 'country':
326: $filterClass = 'adminhtml/widget_grid_column_filter_country';
327: break;
328: case 'options':
329: $filterClass = 'adminhtml/widget_grid_column_filter_select';
330: break;
331:
332: case 'massaction':
333: $filterClass = 'adminhtml/widget_grid_column_filter_massaction';
334: break;
335:
336: case 'checkbox':
337: $filterClass = 'adminhtml/widget_grid_column_filter_checkbox';
338: break;
339:
340: case 'radio':
341: $filterClass = 'adminhtml/widget_grid_column_filter_radio';
342: break;
343: case 'store':
344: $filterClass = 'adminhtml/widget_grid_column_filter_store';
345: break;
346: case 'theme':
347: $filterClass = 'adminhtml/widget_grid_column_filter_theme';
348: break;
349: default:
350: $filterClass = 'adminhtml/widget_grid_column_filter_text';
351: break;
352: }
353: return $filterClass;
354: }
355:
356: public function getFilter()
357: {
358: if (!$this->_filter) {
359: $filterClass = $this->getData('filter');
360: if ($filterClass === false) {
361: return false;
362: }
363: if (!$filterClass) {
364: $filterClass = $this->_getFilterByType();
365: if ($filterClass === false) {
366: return false;
367: }
368: }
369: $this->_filter = $this->getLayout()->createBlock($filterClass)
370: ->setColumn($this);
371: }
372:
373: return $this->_filter;
374: }
375:
376: public function getFilterHtml()
377: {
378: if ($this->getFilter()) {
379: return $this->getFilter()->getHtml();
380: } else {
381: return ' ';
382: }
383: return null;
384: }
385:
386: 387: 388: 389: 390:
391: public function ()
392: {
393: if ($this->getHeaderExport()) {
394: return $this->getHeaderExport();
395: }
396: return $this->getHeader();
397: }
398: }
399: