Exemple #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);
 }
Exemple #2
0
 /**
  * @covers Imbo\Auth\AccessControl\AbstractQuery::page
  */
 public function testSetAndGetPage()
 {
     $this->assertSame(1, $this->query->page());
     $this->assertSame($this->query, $this->query->page(2));
     $this->assertSame(2, $this->query->page());
 }
Exemple #3
0
 /**
  * {@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;
 }
Exemple #4
0
 /**
  * Data provider
  *
  * @return array[]
  */
 public function getGroupsData()
 {
     $query = new GroupQuery();
     $query->page(2)->limit(2);
     return ['no groups' => [[], []], 'some groups' => [['g1' => [], 'g2' => [], 'g3' => []], ['g1' => [], 'g2' => [], 'g3' => []]], 'groups with query object' => [['g1' => [], 'g2' => [], 'g3' => [], 'g4' => [], 'g5' => []], ['g3' => [], 'g4' => []], $query]];
 }
Exemple #5
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);
 }