Newer
Older

Yassine Doghri
committed
<?php
namespace App\Authorization;

Yassine Doghri
committed
use Myth\Auth\Authorization\FlatAuthorization as MythAuthFlatAuthorization;
class FlatAuthorization extends MythAuthFlatAuthorization

Yassine Doghri
committed
{
* The group model to use. Usually the class noted below (or an extension thereof) but can be any compatible
* CodeIgniter Model.
*
* @var PermissionModel
*/
protected $permissionModel;

Yassine Doghri
committed
/**
* Checks a group to see if they have the specified permission.
*/
public function groupHasPermission(int | string $permission, int $groupId): bool

Yassine Doghri
committed
{
// Get the Permission ID
$permissionId = $this->getPermissionID($permission);
if (! is_numeric($permissionId)) {

Yassine Doghri
committed
return false;
}
return $this->permissionModel->doesGroupHavePermission($groupId, $permissionId,);

Yassine Doghri
committed
}
/**

Yassine Doghri
committed
*
* @param array<string, string> $groups Either collection of ID or names

Yassine Doghri
committed
*/

Yassine Doghri
committed
public function setUserGroups(int $userId, array $groups = []): bool

Yassine Doghri
committed
{
// remove user from all groups before resetting it in new groups

Yassine Doghri
committed
$this->groupModel->removeUserFromAllGroups($userId);

Yassine Doghri
committed
if ($groups === []) {

Yassine Doghri
committed
return true;
}
foreach ($groups as $group) {

Yassine Doghri
committed
$this->addUserToGroup($userId, $group);

Yassine Doghri
committed
}
return true;
}
}