Skip to content

Instantly share code, notes, and snippets.

@kamaulynder
Last active August 29, 2015 14:04
Show Gist options
  • Save kamaulynder/93b7b0ff1c15d880e011 to your computer and use it in GitHub Desktop.
Save kamaulynder/93b7b0ff1c15d880e011 to your computer and use it in GitHub Desktop.
// TagRepository
public function search(TagSearchData $search, Array $params = null)
{
$where = Arr::extract($search->asArray(), ['tag', 'type','role']);
if ($search->parent) {
$where['parent_id'] = $search->parent;
}
if ($search->role) {
$where['role'] = $search->role;
}
// Start the query, removing empty values
$query = $this->selectQuery(array_filter($where));
if ($search->q) {
// Tag text searching
$query->where('tag', 'LIKE', "%{$search->q}%");
}
if (!empty($params['orderby'])) {
$query->order_by($params['orderby'], Arr::get($params, 'order'));
}
if (!empty($params['offset'])) {
$query->offset($params['offset']);
}
if (!empty($params['limit'])) {
$query->limit($params['limit']);
}
$results = $query->execute($this->db);
return $this->getCollection($results->as_array());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment