示例#1
0
 /**
  * @param \Grido\Components\Filters\Condition $condition
  * @param \DibiFluent $fluent
  */
 protected function makeWhere(\Grido\Components\Filters\Condition $condition, \DibiFluent $fluent = NULL)
 {
     $fluent = $fluent === NULL ? $this->fluent : $fluent;
     if ($condition->callback) {
         callback($condition->callback)->invokeArgs(array($condition->value, $fluent));
     } else {
         call_user_func_array(array($fluent, 'where'), $condition->__toArray('[', ']'));
     }
 }
示例#2
0
 /**
  * @param Condition $condition
  * @param \Nette\Database\Table\Selection $selection
  */
 protected function makeWhere(Condition $condition, \Nette\Database\Table\Selection $selection = NULL)
 {
     $selection = $selection === NULL ? $this->selection : $selection;
     if ($condition->callback) {
         callback($condition->callback)->invokeArgs(array($condition->value, $selection));
     } else {
         call_user_func_array(array($selection, 'where'), $condition->__toArray());
     }
 }
示例#3
0
 /**
  * @param Condition $condition
  */
 protected function makeWhere(Condition $condition)
 {
     if ($condition->callback) {
         //callback($condition->callback)->invokeArgs(array($condition->value, $selection));
     } else {
         $condarray = $condition->__toArray();
         $this->filterValues[$condarray[0]] = $condarray[1];
         //call_user_func_array(array($selection, 'where'), $condition->__toArray());
     }
 }
示例#4
0
 /**
  * @param Condition $condition
  * @param \Doctrine\ORM\QueryBuilder $qb
  */
 protected function makeWhere(Condition $condition, \Doctrine\ORM\QueryBuilder $qb = NULL)
 {
     $qb = $qb === NULL ? $this->qb : $qb;
     if ($condition->callback) {
         return callback($condition->callback)->invokeArgs(array($condition->value, $qb));
     }
     $columns = $condition->column;
     foreach ($columns as $key => $column) {
         if (!Condition::isOperator($column)) {
             $columns[$key] = isset($this->filterMapping[$column]) ? $this->filterMapping[$column] : $this->qb->getRootAlias() . '.' . $column;
         }
     }
     $condition->setColumn($columns);
     list($where) = $condition->__toArray(NULL, NULL, FALSE);
     $rand = $this->getRand();
     $where = preg_replace_callback('/\\?/', function () use($rand) {
         static $i = -1;
         $i++;
         return ":{$rand}{$i}";
     }, $where);
     $qb->andWhere($where);
     foreach ($condition->getValueForColumn() as $i => $val) {
         $qb->setParameter("{$rand}{$i}", $val);
     }
 }
示例#5
0
 /**
  * @param Condition $condition
  * @param array $data
  * @return array
  */
 protected function makeWhere(Condition $condition, array $data = NULL)
 {
     $data = $data === NULL ? $this->data : $data;
     return array_filter($data, function ($row) use($condition) {
         if ($condition->callback) {
             return call_user_func_array($condition->callback, [$condition->value, $row]);
         }
         $i = 0;
         $results = [];
         foreach ($condition->column as $column) {
             if (Condition::isOperator($column)) {
                 $results[] = " {$column} ";
             } else {
                 $i = count($condition->condition) > 1 ? $i : 0;
                 $results[] = (int) $this->compare($row[$column], $condition->condition[$i], isset($condition->value[$i]) ? $condition->value[$i] : NULL);
                 $i++;
             }
         }
         $result = implode('', $results);
         return count($condition->column) === 1 ? (bool) $result : eval("return {$result};");
     });
 }
示例#6
0
文件: Filter.php 项目: Kaliver/grido
 /**
  * @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;
 }
示例#7
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);
 }