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_Adminhtml
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: * Adminhtml grid item abstract renderer
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: abstract class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36: extends Mage_Adminhtml_Block_Abstract implements Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Interface
37: {
38: protected $_defaultWidth;
39: protected $_column;
40:
41: public function setColumn($column)
42: {
43: $this->_column = $column;
44: return $this;
45: }
46:
47: public function getColumn()
48: {
49: return $this->_column;
50: }
51:
52: /**
53: * Renders grid column
54: *
55: * @param Varien_Object $row
56: * @return string
57: */
58: public function render(Varien_Object $row)
59: {
60: if ($this->getColumn()->getEditable()) {
61: $value = $this->_getValue($row);
62: return $value
63: . ($this->getColumn()->getEditOnly() ? '' : ($value != '' ? '' : ' '))
64: . $this->_getInputValueElement($row);
65: }
66: return $this->_getValue($row);
67: }
68:
69: /**
70: * Render column for export
71: *
72: * @param Varien_Object $row
73: * @return string
74: */
75: public function renderExport(Varien_Object $row)
76: {
77: return $this->render($row);
78: }
79:
80: protected function _getValue(Varien_Object $row)
81: {
82: if ($getter = $this->getColumn()->getGetter()) {
83: if (is_string($getter)) {
84: return $row->$getter();
85: } elseif (is_callable($getter)) {
86: return call_user_func($getter, $row);
87: }
88: return '';
89: }
90: return $row->getData($this->getColumn()->getIndex());
91: }
92:
93: public function _getInputValueElement(Varien_Object $row)
94: {
95: return '<input type="text" class="input-text '
96: . $this->getColumn()->getValidateClass()
97: . '" name="' . $this->getColumn()->getId()
98: . '" value="' . $this->_getInputValue($row) . '"/>';
99: }
100:
101: protected function _getInputValue(Varien_Object $row)
102: {
103: return $this->_getValue($row);
104: }
105:
106: public function renderHeader()
107: {
108: if (false !== $this->getColumn()->getGrid()->getSortable() && false !== $this->getColumn()->getSortable()) {
109: $className = 'not-sort';
110: $dir = strtolower($this->getColumn()->getDir());
111: $nDir= ($dir=='asc') ? 'desc' : 'asc';
112: if ($this->getColumn()->getDir()) {
113: $className = 'sort-arrow-' . $dir;
114: }
115: $out = '<a href="#" name="' . $this->getColumn()->getId() . '" title="' . $nDir
116: . '" class="' . $className . '"><span class="sort-title">'
117: . $this->getColumn()->getHeader().'</span></a>';
118: } else {
119: $out = $this->getColumn()->getHeader();
120: }
121: return $out;
122: }
123:
124: public function renderProperty()
125: {
126: $out = '';
127: $width = $this->_defaultWidth;
128:
129: if ($this->getColumn()->hasData('width')) {
130: $customWidth = $this->getColumn()->getData('width');
131: if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
132: $width = $customWidth;
133: }
134: elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
135: $width = (int)$matches[1];
136: }
137: }
138:
139: if (null !== $width) {
140: $out .= ' width="' . $width . '"';
141: }
142:
143: return $out;
144: }
145:
146: public function renderCss()
147: {
148: return $this->getColumn()->getCssClass();
149: }
150:
151: }
152: