00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 abstract class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract extends Mage_Adminhtml_Block_Abstract implements Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Interface
00036 {
00037 protected $_defaultWidth;
00038 protected $_column;
00039
00040 public function setColumn($column)
00041 {
00042 $this->_column = $column;
00043 return $this;
00044 }
00045
00046 public function getColumn()
00047 {
00048 return $this->_column;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057 public function render(Varien_Object $row)
00058 {
00059 if ($this->getColumn()->getEditable()) {
00060 $value = $this->_getValue($row);
00061 $value = $value!=''?$value:' ';
00062 return $value . ( ($this->getColumn()->getEditOnly() && trim($this->_getValue($row)!='')) ? '' : '</td><td>' ) . $this->_getInputValueElement($row);
00063
00064 }
00065 return $this->_getValue($row);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 public function renderExport(Varien_Object $row)
00075 {
00076 return $this->render($row);
00077 }
00078
00079 protected function _getValue(Varien_Object $row)
00080 {
00081 if ($getter = $this->getColumn()->getGetter()) {
00082 return $row->$getter();
00083 }
00084 return $row->getData($this->getColumn()->getIndex());
00085 }
00086
00087 public function _getInputValueElement(Varien_Object $row)
00088 {
00089 return '<input type="text" class="input-text ' . $this->getColumn()->getValidateClass() . '" name="'.( $this->getColumn()->getName() ? $this->getColumn()->getName() : $this->getColumn()->getId() ).'" value="'.$this->_getInputValue($row).'"/>';
00090 }
00091
00092 protected function _getInputValue(Varien_Object $row)
00093 {
00094 return $this->_getValue($row);
00095 }
00096
00097 public function renderHeader()
00098 {
00099 $out = '';
00100 if ( (false !== $this->getColumn()->getGrid()->getSortable()) && (false !== $this->getColumn()->getSortable()) ) {
00101
00102 $className = 'not-sort';
00103 $dir = strtolower($this->getColumn()->getDir());
00104 $nDir= ($dir=='asc') ? 'desc' : 'asc';
00105 if ($this->getColumn()->getDir()) {
00106 $className = 'sort-arrow-' . $dir;
00107 }
00108 $out = '<a href="#" name="'.$this->getColumn()->getId().'" title="'.$nDir
00109 .'" class="' . $className . '"><span class="sort-title">'.$this->getColumn()->getHeader().'</span></a>';
00110 }
00111 else {
00112 $out = $this->getColumn()->getHeader();
00113 }
00114 return $out;
00115 }
00116
00117 public function renderProperty()
00118 {
00119 $out = '';
00120
00121
00122
00123
00124
00125
00126
00127 $width = $this->_defaultWidth;
00128
00129 if ($this->getColumn()->hasData('width')) {
00130 $customWidth = $this->getColumn()->getData('width');
00131 if ((null === $customWidth) || (preg_match('/^[0-9]+%?$/', $customWidth))) {
00132 $width = $customWidth;
00133 }
00134 elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
00135 $width = (int)$matches[1];
00136 }
00137 }
00138
00139 if (null !== $width) {
00140 $out .= ' width="' . $width . '"';
00141 }
00142
00143 return $out;
00144 }
00145
00146 public function renderCss()
00147 {
00148 return $this->getColumn()->getCssClass();
00149 }
00150
00151 }