/** * Applies the API query on the model query through this strategy * @param \ride\library\http\jsonapi\JsonApiQuery $jsonApiQuery * @param \ride\library\orm\query\ModelQuery $modelQuery * @return null */ public function applyFilter(JsonApiQuery $jsonApiQuery, ModelQuery $modelQuery) { $query = $jsonApiQuery->getFilter('query', null); if ($query) { $modelQuery->getModel()->applySearch($modelQuery, array('query' => $query)); } }
/** * Applies the API query on the model query through this strategy * @param \ride\library\http\jsonapi\JsonApiQuery $jsonApiQuery * @param \ride\library\orm\query\ModelQuery $modelQuery * @return null */ public function applyFilter(JsonApiQuery $jsonApiQuery, ModelQuery $modelQuery) { $expression = $jsonApiQuery->getFilter('expression', null); if ($expression) { $modelQuery->addCondition($expression); } }
private function search(OrmManager $orm, JsonApiQuery $documentQuery) { $term = $documentQuery->getFilter('term'); if ($term) { $term = '%' . $term . '%'; } $geoLocationModel = $orm->getGeoLocationModel(); $geoLocationLocalizedModel = $orm->getGeoLocationLocalizedModel(); // query localized table if ($term) { $query = $geoLocationLocalizedModel->createQuery(); $query->setFields('{entry}, {name}'); $query->setLimit(100); $query->addCondition('{locale} = %1%', $orm->getLocale()); $query->addCondition('{name} LIKE %1%', $term); $geoLocationLocalizedResult = $query->query('entry'); } // query main table $query = $geoLocationModel->createQuery(); $query->setFields('{id}, {path}, {code}'); $query->setLimit(100); if ($term) { if (!$geoLocationLocalizedResult) { $query->addCondition('{code} LIKE %1%', $term); } else { $query->addCondition('{id} IN %1%', array_keys($geoLocationLocalizedResult)); } } $type = $documentQuery->getFilter('type'); if ($type) { if (is_array($type)) { $query->addCondition('{type} IN %1%', $type); } elseif (strpos($type, ',')) { $query->addCondition('{type} IN %1%', explode(',', $type)); } else { $query->addCondition('{type} = %1%', $type); } } $path = $documentQuery->getFilter('path'); if ($path) { if (strpos($path, '~') == false) { $path = '~' . $path . '~'; } $query->addCondition('{path} LIKE %1%', '%' . $path . '%'); } $geoLocationResult = $query->query(); // foreach ($geoLocationResult as $index => $geoLocation) { // $result[$index] = $index; // } // merge result return $geoLocationResult; }
/** * Applies the API query on the model query through this strategy * @param \ride\library\http\jsonapi\JsonApiQuery $jsonApiQuery * @param \ride\library\orm\query\ModelQuery $modelQuery * @return null */ public function applyFilter(JsonApiQuery $jsonApiQuery, ModelQuery $modelQuery) { $query = $jsonApiQuery->getFilter('elastic', null); if (!$query) { return; } $model = $modelQuery->getModel(); if ($model->getMeta()->isLocalized()) { $query = str_replace(array('%locale%', '%25locale%25'), $modelQuery->getLocale(), $query); } $parameters = array('query' => $query, 'limit' => $jsonApiQuery->getLimit(50), 'offset' => $jsonApiQuery->getOffset()); $result = $this->search->searchByQueryString($model, $parameters); $this->search->applyResultToModelQuery($result, $modelQuery); }
/** * @dataProvider providerGetFilter */ public function testGetFilter($expected, $filters, $filter, $default = null) { $query = new JsonApiQuery(array(JsonApiQuery::PARAMETER_FILTER => $filters)); $result = $query->getFilter($filter, $default); $this->assertEquals($result, $expected); }