示例#1
0
 /**
  * Renders grid column
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $row)
 {
     $line = parent::_getValue($row);
     $wrappedLine = '';
     $lineLength = $this->getColumn()->getData('lineLength') ? $this->getColumn()->getData('lineLength') : $this->_defaultMaxLineLength;
     for ($i = 0, $n = floor($this->string->strlen($line) / $lineLength); $i <= $n; $i++) {
         $wrappedLine .= $this->string->substr($line, $lineLength * $i, $lineLength) . "<br />";
     }
     return $wrappedLine;
 }
示例#2
0
 /**
  * @param \Magento\Framework\DataObject $row
  * @return int|string
  */
 protected function _getValue(\Magento\Framework\DataObject $row)
 {
     $data = parent::_getValue($row);
     if (intval($data) == $data) {
         return (string) number_format($data, 2);
     }
     if ($data !== null) {
         return $data * 1;
     }
     return $this->getColumn()->getDefault();
 }
示例#3
0
文件: Number.php 项目: aiesh/magento2
 /**
  * Returns value of the row
  *
  * @param \Magento\Framework\Object $row
  * @return mixed|string
  */
 protected function _getValue(\Magento\Framework\Object $row)
 {
     $data = parent::_getValue($row);
     if (!is_null($data)) {
         $value = $data * 1;
         $sign = (bool) (int) $this->getColumn()->getShowNumberSign() && $value > 0 ? '+' : '';
         if ($sign) {
             $value = $sign . $value;
         }
         // fixed for showing zero in grid
         return $value ? $value : '0';
     }
     return $this->getColumn()->getDefault();
 }
示例#4
0
 /**
  * Render contents as a long text
  *
  * Text will be truncated as specified in string_limit, truncate or 250 by default
  * Also it can be html-escaped and nl2br()
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $row)
 {
     $truncateLength = 250;
     // stringLength() is for legacy purposes
     if ($this->getColumn()->getStringLimit()) {
         $truncateLength = $this->getColumn()->getStringLimit();
     }
     if ($this->getColumn()->getTruncate()) {
         $truncateLength = $this->getColumn()->getTruncate();
     }
     $text = $this->filterManager->truncate(parent::_getValue($row), ['length' => $truncateLength]);
     if ($this->getColumn()->getEscape()) {
         $text = $this->escapeHtml($text);
     }
     if ($this->getColumn()->getNl2br()) {
         $text = nl2br($text);
     }
     return $text;
 }
示例#5
0
 /**
  * Renders grid column
  *
  * @param \Magento\Framework\DataObject $row
  * @return mixed
  */
 public function _getValue(\Magento\Framework\DataObject $row)
 {
     $format = $this->getColumn()->getFormat() ? $this->getColumn()->getFormat() : null;
     $defaultValue = $this->getColumn()->getDefault();
     if ($format === null) {
         // If no format and it column not filtered specified return data as is.
         $data = parent::_getValue($row);
         $string = $data === null ? $defaultValue : $data;
         return $this->escapeHtml($string);
     } elseif (preg_match_all($this->_variablePattern, $format, $matches)) {
         // Parsing of format string
         $formattedString = $format;
         foreach ($matches[0] as $matchIndex => $match) {
             $value = $row->getData($matches[1][$matchIndex]);
             $formattedString = str_replace($match, $value, $formattedString);
         }
         return $formattedString;
     } else {
         return $this->escapeHtml($format);
     }
 }