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\Filters;
 13 
 14 /**
 15  * Date input filter.
 16  *
 17  * @package     Grido
 18  * @subpackage  Components\Filters
 19  * @author      Petr Bugyík
 20  *
 21  * @property string $dateFormatInput
 22  * @property string $dateFormatOutput
 23  */
 24 class Date extends Text
 25 {
 26     /** @var string */
 27     protected $formatValue;
 28 
 29     /** @var string */
 30     protected $dateFormatInput = 'd.m.Y';
 31 
 32     /** @var string */
 33     protected $dateFormatOutput = 'Y-m-d%';
 34 
 35     /**
 36      * Sets date-input format.
 37      * @param string $format
 38      * @return Date
 39      */
 40     public function setDateFormatInput($format)
 41     {
 42         $this->dateFormatInput = $format;
 43         return $this;
 44     }
 45 
 46     /**
 47      * Returns date-input format.
 48      * @return string
 49      */
 50     public function getDateFormatInput()
 51     {
 52         return $this->dateFormatInput;
 53     }
 54 
 55     /**
 56      * Sets date-output format.
 57      * @param string $format
 58      * @return Date
 59      */
 60     public function setDateFormatOutput($format)
 61     {
 62         $this->dateFormatOutput = $format;
 63         return $this;
 64     }
 65 
 66     /**
 67      * Returns date-output format.
 68      * @return string
 69      */
 70     public function getDateFormatOutput()
 71     {
 72         return $this->dateFormatOutput;
 73     }
 74 
 75     /**
 76      * @return \Nette\Forms\Controls\TextInput
 77      */
 78     protected function getFormControl()
 79     {
 80         $control = parent::getFormControl();
 81         $control->getControlPrototype()->class[] = 'date';
 82         $control->getControlPrototype()->attrs['autocomplete'] = 'off';
 83 
 84         return $control;
 85     }
 86 
 87     /**
 88      * @param string $value
 89      * @return Condition
 90      * @throws \Exception
 91      * @internal
 92      */
 93     public function __getCondition($value)
 94     {
 95         $condition = $this->condition;
 96         if ($this->where === NULL && is_string($condition)) {
 97             $column = $this->getColumn();
 98             return ($date = \DateTime::createFromFormat($this->dateFormatInput, $value))
 99                 ? Condition::setupFromArray(array($column, $condition, $date->format($this->dateFormatOutput)))
100                 : Condition::setupEmpty();
101         }
102 
103         return parent::__getCondition($value);
104     }
105 }
106 
Grido@master API documentation generated by ApiGen