/** * {@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); }
/** * {@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; }
/** * @covers Imbo\Model\Groups::setHits * @covers Imbo\Model\Groups::getHits */ public function testCanSetAndGetHits() { $this->assertNull($this->model->getHits()); $this->assertSame($this->model, $this->model->setHits(10)); $this->assertSame(10, $this->model->getHits()); }