ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumModerators.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private readonly \ILIAS\DI\RBACServices $rbac;
29
30 public function __construct(private int $ref_id)
31 {
32 global $DIC;
33
34 $this->rbac = $DIC->rbac();
35 }
36
37 public function setRefId(int $ref_id): void
38 {
39 $this->ref_id = $ref_id;
40 }
41
42 public function getRefId(): int
43 {
44 return $this->ref_id;
45 }
46
47 public function addModeratorRole(int $a_usr_id): bool
48 {
49 $a_rol_id = null;
50 $role_list = $this->rbac->review()->getRoleListByObject($this->getRefId());
51 foreach ($role_list as $role) {
52 if (str_contains($role['title'], 'il_frm_moderator')) {
53 $a_rol_id = (int) $role['obj_id'];
54 break;
55 }
56 }
57
58 if ($a_rol_id !== null) {
59 $this->rbac->admin()->assignUser($a_rol_id, $a_usr_id);
60 return true;
61 }
62
63 return false;
64 }
65
66 public function detachModeratorRole(int $a_usr_id): bool
67 {
68 $a_rol_id = null;
69 $role_list = $this->rbac->review()->getRoleListByObject($this->getRefId());
70 foreach ($role_list as $role) {
71 if (str_contains($role['title'], 'il_frm_moderator')) {
72 $a_rol_id = (int) $role['obj_id'];
73 break;
74 }
75 }
76
77 if ($a_rol_id !== null) {
78 $this->rbac->admin()->deassignUser($a_rol_id, $a_usr_id);
79 return true;
80 }
81
82 return false;
83 }
84
88 public function getCurrentModerators(): array
89 {
90 $assigned_users = [];
91 $roles = $this->rbac->review()->getRoleListByObject($this->getRefId());
92 foreach ($roles as $role) {
93 if (str_contains($role['title'], 'il_frm_moderator')) {
94 $assigned_users = $this->rbac->review()->assignedUsers((int) $role['rol_id']);
95 break;
96 }
97 }
98
99 return $assigned_users;
100 }
101
105 public function getUsers(): array
106 {
107 $assigned_users = [];
108 $roles = $this->rbac->review()->getRoleListByObject($this->getRefId());
109 foreach ($roles as $role) {
110 if (str_contains($role['title'], 'il_frm_moderator')) {
111 $assigned_users = array_map('intval', $this->rbac->review()->assignedUsers((int) $role['rol_id']));
112 break;
113 }
114 }
115
116 return $assigned_users;
117 }
118}
Class ilForumModerators.
addModeratorRole(int $a_usr_id)
detachModeratorRole(int $a_usr_id)
__construct(private int $ref_id)
readonly ILIAS DI RBACServices $rbac
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26