/** * @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('[', ']')); } }
/** * @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()); } }
/** * @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()); } }
/** * @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); } }
/** * @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};"); }); }
/** * @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; }
/** * @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); }