public function search($params = null) { if ($params !== null) { $this->load($params); } $this->query = $this->app->getItems()->with(['itemsElements', 'app'])->joinWith(['categories']); $this->query->andFilterWhere([Categories::tablename() . '.id' => $this->categoryTree($this->category)]); foreach ($this->elements as $element) { $e = $element->name; if (!in_array($e, $this->attributes()) && ($element->filter || $element->search || $e == $this->app->defaultOrder)) { $value = $this->{$e}; if ($e == $this->app->defaultOrder || (is_array($value) && count($value) > 0 || !is_array($value) && !empty($value))) { $this->query->leftJoin([$e => ItemsElements::tablename()], $e . ".item_id = " . Items::tablename() . ".id AND " . $e . ".element = '" . $e . "'"); $this->query->andFilterWhere([$e . '.value_string' => $value]); } } } if (!empty($this->search)) { $this->query->select(Items::tablename() . '.*, MATCH (node) AGAINST (:text) as REL')->andWhere('MATCH (node) AGAINST (:text)', [':text' => $this->search]); } return $this->query; }
public function getItemsElements() { return $this->hasMany(ItemsElements::className(), ['item_id' => 'id']); }