Inheritance: extends Ublaboo\DataGrid\Object
Exemplo n.º 1
0
 /**
  * Get value from column using Row::getValue() or custom callback
  * @param Row    	    $row
  * @param Column\Column $column
  * @return bool
  */
 private function getValue(Row $row, $column)
 {
     if (!$this->rowCallback) {
         return $row->getValue($column->getColumn());
     }
     return call_user_func_array($this->rowCallback, [$row->getItem(), $column->getColumn()]);
 }
Exemplo n.º 2
0
 /**
  * Format row item value
  * @param  Row   $row
  * @return mixed
  */
 public function getColumnValue(Row $row)
 {
     $value = parent::getColumnValue($row);
     if (!is_numeric($value)) {
         return $value;
     }
     return number_format($value, $this->number_format[0], $this->number_format[1], $this->number_format[2]);
 }
Exemplo n.º 3
0
 /**
  * Render row item into template
  * @param  Row   $row
  * @return mixed
  */
 public function render(Row $row)
 {
     /**
      * Renderer function may be used
      */
     try {
         return $this->useRenderer($row);
     } catch (DataGridColumnRendererException $e) {
         /**
          * Do not use renderer
          */
     }
     $value = parent::render($row);
     if (!$value && !$this->icon) {
         return NULL;
     }
     $a = Html::el('a')->href($this->createLink($this->grid, $this->href, $this->getItemParams($row, $this->params) + $this->parameters));
     if (!empty($this->data_attributes)) {
         foreach ($this->data_attributes as $key => $attr_value) {
             $a->data($key, $attr_value);
         }
     }
     if ($this->open_in_new_tab) {
         $a->addAttributes(['target' => '_blank']);
     }
     if ($this->title) {
         $a->title($this->title);
     }
     if ($this->class) {
         $a->class($this->class);
     }
     $element = $a;
     if ($this->icon) {
         $a->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon));
         if (strlen($value)) {
             $a->addHtml(' ');
         }
     }
     if ($this->isTemplateEscaped()) {
         $a->addText($value);
     } else {
         $a->addHtml($value);
     }
     return $element;
 }
Exemplo n.º 4
0
 /**
  * Format row item value as DateTime
  * @param  Row $row
  * @return string
  */
 public function getColumnValue(Row $row)
 {
     $value = parent::getColumnValue($row);
     if (!$value instanceof DateTime) {
         /**
          * Try to convert string to DateTime object
          */
         try {
             $date = DateTimeHelper::tryConvertToDateTime($value);
             return $date->format($this->format);
         } catch (DataGridDateTimeHelperException $e) {
             /**
              * Otherwise just return raw string
              */
             return $value;
         }
     }
     return $value->format($this->format);
 }
Exemplo n.º 5
0
 /**
  * Render row item into template
  * @param  Row   $row
  * @return mixed
  */
 public function render(Row $row)
 {
     /**
      * Renderer function may be used
      */
     try {
         return $this->useRenderer($row);
     } catch (DataGridColumnRendererException $e) {
         /**
          * Do not use renderer
          */
     }
     $value = parent::render($row);
     if (!$value && !$this->icon) {
         return NULL;
     }
     $a = Html::el('a')->href($this->createLink($this->href, $this->getItemParams($row, $this->params)));
     if (!empty($this->data_attributes)) {
         foreach ($this->data_attributes as $key => $value) {
             $a->data($key, $value);
         }
     }
     if ($this->title) {
         $a->title($this->title);
     }
     if ($this->class) {
         $a->class($this->class);
     }
     $element = $a;
     if ($this->icon) {
         $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon));
         if (strlen($value)) {
             $a->add(' ');
         }
     }
     if ($this->isTemplateEscaped()) {
         $a->add(htmlspecialchars((string) $value, ENT_NOQUOTES, 'UTF-8'));
     } else {
         $a->add($value);
     }
     return $element;
 }
Exemplo n.º 6
0
 /**
  * Format item value as DateTime
  * @param  mixed $item
  * @return mixed
  */
 public function getColumnValue($item)
 {
     $value = parent::getColumnValue($item);
     if (!$value instanceof DateTime) {
         /**
          * Try to convert string Y-m-d to DateTime object
          */
         $date = \DateTime::createFromFormat('Y-m-d', $value);
         if ($date) {
             return $date->format($this->format);
         }
         /**
          * Try to convert string Y-m-d H:i:s to DateTime object
          */
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
         if ($date) {
             return $date->format($this->format);
         }
         /**
          * Try to convert string Y-m-d H:i:s.u to DateTime object
          */
         $date = \DateTime::createFromFormat('Y-m-d H:i:s.u', $value);
         if ($date) {
             return $date->format($this->format);
         }
         /**
          * Try strtotime
          */
         $timestamp = strtotime($value);
         if (FALSE !== $timestamp) {
             $date = new \DateTime();
             $date->setTimestamp($timestamp);
             return $date->format($this->format);
         }
         /**
          * Otherwise just return raw string
          */
         return $value;
     }
     return $value->format($this->format);
 }
Exemplo n.º 7
0
 /**
  * Render row item into template
  * @param  Row   $row
  * @return mixed
  */
 public function render(Row $row)
 {
     /**
      * Renderer function may be used
      */
     if ($renderer = $this->getRenderer()) {
         if (!$renderer->getConditionCallback()) {
             return call_user_func_array($renderer->getCallback(), [$row->getItem()]);
         }
         if (call_user_func_array($renderer->getConditionCallback(), [$row->getItem()])) {
             return call_user_func_array($renderer->getCallback(), [$row->getItem()]);
         }
     }
     $value = parent::render($row);
     $href = $this->grid->getPresenter()->link($this->href, $this->getItemParams($row));
     $a = Html::el('a')->href($href)->setText($value);
     if ($this->title) {
         $a->title($this->title);
     }
     if ($this->class) {
         $a->class($this->class);
     }
     return $a;
 }
Exemplo n.º 8
0
 /**
  * @param Column  $column
  * @return array
  * @internal
  */
 public function getSortNext(\Ublaboo\DataGrid\Column\Column $column)
 {
     $sort = $column->getSortNext();
     if ($this->isMultiSortEnabled()) {
         $sort = array_merge($this->sort, $sort);
     }
     return array_filter($sort);
 }
Exemplo n.º 9
0
 /**
  * @param DataGrid $grid
  * @param string   $key
  * @param string   $column
  * @param string   $name
  */
 public function __construct(DataGrid $grid, $key, $column, $name)
 {
     parent::__construct($grid, $key, $column, $name);
     $this->key = $key;
     $this->setTemplate(__DIR__ . '/../templates/column_status.latte');
 }