/** * Apply dibi fluent where from array hash * @param ArrayHash $filters * * @throws Exception */ public function filter(ArrayHash $filters) { if (!$this->dataSource) { throw new Exception('Data source is missing'); } foreach ($filters as $key => $value) { $value = trim($value); if (empty($value)) { continue; } if (isset($this->filters[$key]) && !is_null($this->filters[$key]['callback'])) { call_user_func($this->filters[$key]['callback'], $value, $this->dataSource); continue; } if (is_numeric($value)) { $this->dataSource->where($key . " = ?", $value); } else { $this->dataSource->where($key)->like("?", '%' . $value . '%'); } } // echo $this->dataSource; exit; }
private function addSearchCondition(DibiFluent $sql, SearchRequest $request) { if ($request->query == "" && $request->from == "") { // limit results to topics $sql->where("data.parent_id = 0"); } else { if ($request->query != "") { $sql->where("MATCH(data.message) AGAINST (%s IN BOOLEAN MODE)", $request->query); } if ($request->from != "") { $sql = $sql->where("data.from_name LIKE %~like~", $request->from); // protection of hidden names in closed/secret groups $sql = $sql->where("groups.closed = 0"); } } if (count($request->tags)) { $taggedPostsId = $this->getMatchedIdByTags($request->tags); $sql = $sql->where("data.id IN %in", $taggedPostsId); } if (count($request->groups)) { $sql->where("data.group_id IN %in", $request->groups); } }
public function setFilter(array $filter) { if ($filter) { $this->fluent->where("%and", $this->convertFilter($filter)); } }