_column = $column; return $this; } /** * @return Column */ public function getColumn() { return $this->_column; } /** * Renders grid column * * @param Object $row * @return string */ public function render(DataObject $row) { if ($this->getColumn()->getEditable()) { $result = '
'; $result .= $this->getColumn()->getEditOnly() ? '' : '' . $this->_getValue($row) . ''; return $result . $this->_getInputValueElement($row) . '
' ; } return $this->_getValue($row); } /** * Render column for export * * @param Object $row * @return string */ public function renderExport(DataObject $row) { return $this->render($row); } /** * @param Object $row * @return mixed */ protected function _getValue(DataObject $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()); } /** * @param Object $row * @return string */ public function _getInputValueElement(DataObject $row) { return ''; } /** * @param Object $row * @return mixed */ protected function _getInputValue(DataObject $row) { return $this->_getValue($row); } /** * @return string */ public function renderHeader() { if (false !== $this->getColumn()->getSortable()) { $className = 'not-sort'; $dir = strtolower($this->getColumn()->getDir()); $nDir = $dir == 'asc' ? 'desc' : 'asc'; if ($this->getColumn()->getDir()) { $className = '_' . $dir . 'end'; } $out = '' . $this->getColumn()->getHeader() . ''; } else { $out = '' . $this->getColumn()->getHeader() . ''; } return $out; } /** * @return string */ 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; } /** * @return string */ public function renderCss() { return $this->getColumn()->getCssClass(); } }