*/ abstract class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract extends Mage_Adminhtml_Block_Abstract implements Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Interface { protected $_defaultWidth; protected $_column; public function setColumn($column) { $this->_column = $column; return $this; } public function getColumn() { return $this->_column; } /** * Renders grid column * * @param Varien_Object $row * @return string */ public function render(Varien_Object $row) { if ($this->getColumn()->getEditable()) { $value = $this->_getValue($row); return $value . ($this->getColumn()->getEditOnly() ? '' : ($value != '' ? '' : ' ')) . $this->_getInputValueElement($row); } return $this->_getValue($row); } /** * Render column for export * * @param Varien_Object $row * @return string */ public function renderExport(Varien_Object $row) { return $this->render($row); } protected function _getValue(Varien_Object $row) { if ($getter = $this->getColumn()->getGetter()) { if (is_string($getter)) { return $row->$getter(); } elseif (is_callable($getter)) { return call_user_func($getter, $row); } return ''; } return $row->getData($this->getColumn()->getIndex()); } public function _getInputValueElement(Varien_Object $row) { return ''; } protected function _getInputValue(Varien_Object $row) { return $this->_getValue($row); } public function renderHeader() { if (false !== $this->getColumn()->getGrid()->getSortable() && false !== $this->getColumn()->getSortable()) { $className = 'not-sort'; $dir = strtolower($this->getColumn()->getDir()); $nDir= ($dir=='asc') ? 'desc' : 'asc'; if ($this->getColumn()->getDir()) { $className = 'sort-arrow-' . $dir; } $out = '' . $this->getColumn()->getHeader().''; } else { $out = $this->getColumn()->getHeader(); } return $out; } public function renderProperty() { $out = ''; $width = $this->_defaultWidth; if ($this->getColumn()->hasData('width')) { $customWidth = $this->getColumn()->getData('width'); if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) { $width = $customWidth; } elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) { $width = (int)$matches[1]; } } if (null !== $width) { $out .= ' width="' . $width . '"'; } return $out; } public function renderCss() { return $this->getColumn()->getCssClass(); } }