Grido@master
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Grido
    • Components
      • Actions
      • Columns
      • Filters
    • DataSources
    • PropertyAccessors
    • Translations

Classes

  • Grido\Translations\FileTranslator
  1 <?php
  2 
  3 /**
  4  * This file is part of the Grido (https://github.com/o5/grido)
  5  *
  6  * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
  7  *
  8  * For the full copyright and license information, please view
  9  * the file LICENSE.md that was distributed with this source code.
 10  */
 11 
 12 namespace Grido\Components\Columns;
 13 
 14 /**
 15  * Date column.
 16  *
 17  * @package     Grido
 18  * @subpackage  Components\Columns
 19  * @author      Petr Bugyík
 20  *
 21  * @property string $dateFormat
 22  */
 23 class Date extends Editable
 24 {
 25     const FORMAT_TEXT = 'd M Y';
 26     const FORMAT_DATE = 'd.m.Y';
 27     const FORMAT_DATETIME = 'd.m.Y H:i:s';
 28 
 29     /** @var string */
 30     protected $dateFormat = self::FORMAT_DATE;
 31 
 32     /**
 33      * @param \Grido\Grid $grid
 34      * @param string $name
 35      * @param string $label
 36      * @param string $dateFormat
 37      */
 38     public function __construct($grid, $name, $label, $dateFormat = NULL)
 39     {
 40         parent::__construct($grid, $name, $label);
 41 
 42         if ($dateFormat !== NULL) {
 43             $this->dateFormat = $dateFormat;
 44         }
 45     }
 46 
 47     /**
 48      * @param string $format
 49      * @return Date
 50      */
 51     public function setDateFormat($format)
 52     {
 53         $this->dateFormat = $format;
 54         return $this;
 55     }
 56 
 57     /**
 58      * @return string
 59      */
 60     public function getDateFormat()
 61     {
 62         return $this->dateFormat;
 63     }
 64 
 65     /**
 66      * @param mixed $value
 67      * @return string
 68      */
 69     protected function formatValue($value)
 70     {
 71         if ($value === NULL || is_bool($value)) {
 72             return $this->applyReplacement($value);
 73         } elseif (is_scalar($value)) {
 74             $value = \Nette\Templating\Helpers::escapeHtml($value);
 75             $replaced = $this->applyReplacement($value);
 76             if ($value !== $replaced && is_scalar($replaced)) {
 77                 return $replaced;
 78             }
 79         }
 80 
 81         return $value instanceof \DateTime
 82             ? $value->format($this->dateFormat)
 83             : date($this->dateFormat, is_numeric($value) ? $value : strtotime($value)); //@todo notice for "01.01.1970"
 84     }
 85 
 86     /**
 87      * @param mixed $row
 88      * @return string
 89      * @internal
 90      */
 91     public function renderExport($row)
 92     {
 93         if (is_callable($this->customRenderExport)) {
 94             return callback($this->customRenderExport)->invokeArgs(array($row));
 95         }
 96 
 97         $value = $this->getValue($row);
 98         return $this->formatValue($value);
 99     }
100 }
101 
Grido@master API documentation generated by ApiGen