Ejemplo n.º 1
0
 /**
  * @param string $value
  * @return Condition
  * @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));
         $values = $from && $to ? array($from->format($this->dateFormatOutput), $to->format($this->dateFormatOutput)) : NULL;
         return $values ? Condition::setup($this->getColumn(), $this->condition, $values) : Condition::setupEmpty();
     }
     return parent::__getCondition($value);
 }
Ejemplo n.º 2
0
 /**
  * @param string $value
  * @return Condition|bool
  * @throws \Exception
  * @internal
  */
 public function __getCondition($value)
 {
     $condition = parent::__getCondition($value);
     if ($condition === NULL) {
         $condition = Condition::setupEmpty();
         if (preg_match('/(<>|[<|>]=?)?([-0-9,|.]+)/', $value, $matches)) {
             $value = str_replace(',', '.', $matches[2]);
             $operator = $matches[1] ? $matches[1] : '=';
             $condition = Condition::setup($this->getColumn(), $operator . ' ?', $value);
         }
     }
     return $condition;
 }
Ejemplo n.º 3
0
 /**
  * @param string $value
  * @return Condition
  * @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);
     } else {
         if (is_string($condition)) {
             $condition = Condition::setup($this->getColumn(), $condition, $this->formatValue($value));
         } elseif ($condition instanceof Condition) {
             $condition = $condition;
         } elseif (is_callable($condition)) {
             $condition = callback($condition)->invokeArgs(array($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 \InvalidArgumentException("Condition must be array or Condition object. {$type} given.");
     }
     return $condition;
 }