Newer
Older

Yassine Doghri
committed
<?php
namespace App\Authorization;

Yassine Doghri
committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class FlatAuthorization extends \Myth\Auth\Authorization\FlatAuthorization
{
//--------------------------------------------------------------------
// Actions
//--------------------------------------------------------------------
/**
* Checks a group to see if they have the specified permission.
*
* @param int|string $permission
* @param int $groupId
*
* @return mixed
*/
public function groupHasPermission($permission, int $groupId)
{
if (
empty($permission) ||
(!is_string($permission) && !is_numeric($permission))
) {
return null;
}
if (empty($groupId) || !is_numeric($groupId)) {
return null;
}
// Get the Permission ID
$permissionId = $this->getPermissionID($permission);
if (!is_numeric($permissionId)) {
return false;
}
if (
$this->permissionModel->doesGroupHavePermission(
$groupId,
(int) $permissionId
)
) {
return true;
}
return false;
}
/**

Yassine Doghri
committed
*

Yassine Doghri
committed
* @param $userId

Yassine Doghri
committed
* @param array|null $groups // Either collection of ID or names
*
* @return bool
*/

Yassine Doghri
committed
public function setUserGroups(int $userId, $groups)

Yassine Doghri
committed
{

Yassine Doghri
committed
if (empty($userId) || !is_numeric($userId)) {

Yassine Doghri
committed
return null;
}
// remove user from all groups before resetting it in new groups

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

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

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

Yassine Doghri
committed
}
return true;
}
}