Exemple #1
0
 /**
  * @param mixed $value
  * @return Condition|bool
  * @throws Exception
  * @internal
  */
 public function __getCondition($value)
 {
     if ($value === '' || $value === NULL) {
         return FALSE;
         //skip
     }
     $condition = $this->getCondition();
     if ($this->where !== NULL) {
         $condition = Condition::setupFromCallback($this->where, $value);
     } elseif (is_string($condition)) {
         $condition = Condition::setup($this->getColumn(), $condition, $this->formatValue($value));
     } elseif (is_callable($condition)) {
         $condition = call_user_func_array($condition, [$value]);
     } elseif (is_array($condition)) {
         $condition = isset($condition[$value]) ? $condition[$value] : Condition::setupEmpty();
     }
     if (is_array($condition)) {
         //for user-defined condition by array or callback
         $condition = Condition::setupFromArray($condition);
     } elseif ($condition !== NULL && !$condition instanceof Condition) {
         $type = gettype($condition);
         throw new Exception("Condition must be array or Condition object. {$type} given.");
     }
     return $condition;
 }
Exemple #2
0
 /**
  * @param string $value
  * @return Condition|bool
  * @throws \Exception
  * @internal
  */
 public function __getCondition($value)
 {
     if ($this->where === NULL && is_string($this->condition)) {
         list(, $from, $to) = \Nette\Utils\Strings::match($value, $this->mask);
         $from = \DateTime::createFromFormat($this->dateFormatInput, trim($from));
         $to = \DateTime::createFromFormat($this->dateFormatInput, trim($to));
         if ($to && !Strings::match($this->dateFormatInput, '/G|H/i')) {
             //input format haven't got hour option
             Strings::contains($this->dateFormatOutput[1], 'G') || Strings::contains($this->dateFormatOutput[1], 'H') ? $to->setTime(23, 59, 59) : $to->setTime(11, 59, 59);
         }
         $values = $from && $to ? array($from->format($this->dateFormatOutput[0]), $to->format($this->dateFormatOutput[1])) : NULL;
         return $values ? Condition::setup($this->getColumn(), $this->condition, $values) : Condition::setupEmpty();
     }
     return parent::__getCondition($value);
 }