Skip to content

Instantly share code, notes, and snippets.

@kamaulynder
Created August 20, 2014 06:35
Show Gist options
  • Save kamaulynder/60ae482dc8113866aa28 to your computer and use it in GitHub Desktop.
Save kamaulynder/60ae482dc8113866aa28 to your computer and use it in GitHub Desktop.
/**
* Retrieve All Tags
*
* GET /api/tags
*
* @return void
*/
public function action_get_index_collection()
{
$repo = service('repository.tag');
$parser = service('parser.tag.search');
$format = service('formatter.entity.tag');
$authorize = service('authorizer.tagauthorizer');
$input = $parser($this->request->query());
// this probably belongs in the parser, or should just return the
// order/limit params as an array for the search call
$this->_prepare_order_limit_params();
$tags = $repo->search($input, [
'orderby' => $this->_record_orderby,
'order' => $this->_record_order,
'offset' => $this->_record_offset,
'limit' => $this->_record_limit,
]);
$count = count($tags);
$results = [];
foreach ($tags as $tag)
{
// Check if user is allowed to access this tag
// todo: fix the ACL layer so that it can consume an Entity
if($authorize->isAllowed($tag, 'get', $this->user))
{
$result = $format($tag);
$result['allowed_methods'] = $this->_allowed_methods($tag->getResource());
$results[] = $result;
}
}
// Respond with posts
$this->_response_payload = array(
'count' => $count,
'results' => $results,
)
+ $this->_get_paging_parameters();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment