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