Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getGroups(GroupQuery $query = null, GroupsModel $model)
 {
     if ($query === null) {
         $query = new GroupQuery();
     }
     $model->setHits(count($this->groups));
     $offset = ($query->page() - 1) * $query->limit();
     return array_slice($this->groups, $offset, $query->limit(), true);
 }
Example #2
0
File: Mongo.php Project: imbo/imbo
 /**
  * {@inheritdoc}
  */
 public function getGroups(GroupQuery $query = null, GroupsModel $model)
 {
     if ($query === null) {
         $query = new GroupQuery();
     }
     $cursor = $this->getGroupsCollection()->find([], ['skip' => ($query->page() - 1) * $query->limit(), 'limit' => $query->limit()]);
     $groups = [];
     foreach ($cursor as $group) {
         $groups[$group['name']] = $group['resources']->getArrayCopy();
     }
     // Cache the retrieved groups
     $this->groups = array_merge($this->groups, $groups);
     // Update model with total hits
     $model->setHits($this->getGroupsCollection()->count());
     return $groups;
 }
Example #3
0
 /**
  * @covers Imbo\Auth\AccessControl\AbstractQuery::limit
  */
 public function testSetAndGetLimit()
 {
     $this->assertSame(20, $this->query->limit());
     $this->assertSame($this->query, $this->query->limit(10));
     $this->assertSame(10, $this->query->limit());
 }
Example #4
0
 /**
  * Load groups from the configured access control adapter
  *
  * @param EventInterface $event An event instance
  */
 public function loadGroups(EventInterface $event)
 {
     $query = new GroupQuery();
     $params = $event->getRequest()->query;
     if ($params->has('page')) {
         $query->page($params->get('page'));
     }
     if ($params->has('limit')) {
         $query->limit($params->get('limit'));
     }
     $response = $event->getResponse();
     $aclAdapter = $event->getAccessControl();
     // Create the model and set some pagination values
     $model = new GroupsModel();
     $model->setLimit($query->limit())->setPage($query->page());
     $groups = $aclAdapter->getGroups($query, $model);
     $modelGroups = [];
     foreach ($groups as $groupName => $resources) {
         $modelGroups[] = ['name' => $groupName, 'resources' => $resources];
     }
     $model->setGroups($modelGroups);
     $response->setModel($model);
 }