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;
}