19declare(strict_types=1);
58 protected function __construct(
string $a_component_name,
int $a_obj_id,
int $a_usr_id)
62 $this->obj_id = $a_obj_id;
63 $this->usr_id = $a_usr_id;
66 $this->ref_id = current($ref_ids);
67 $this->component = $a_component_name;
70 $this->db =
$DIC->database();
71 $this->rbacReview =
$DIC->rbac()->review();
72 $this->rbacAdmin =
$DIC->rbac()->admin();
74 $this->eventHandler =
$DIC->event();
80 public static function updateMemberRoles(
int $a_obj_id,
int $a_usr_id,
int $a_role_id,
int $a_status): void
87 switch ($a_membership_role_type) {
89 $update_fields = array(
'admin' => array(
'integer', $a_status ? 1 : 0));
90 $update_string = (
'admin = ' .
$ilDB->quote($a_status ? 1 : 0,
'integer'));
94 $update_fields = array(
'tutor' => array(
'integer', $a_status ? 1 : 0));
95 $update_string = (
'tutor = ' .
$ilDB->quote($a_status ? 1 : 0,
'integer'));
103 $new_status = $current_status + 1;
106 $new_status = $current_status - 1;
107 if ($new_status < 0) {
112 $update_fields = array(
'member' => array(
'integer', $new_status));
113 $update_string = (
'member = ' .
$ilDB->quote($new_status,
'integer'));
117 $query =
'SELECT count(*) num FROM obj_members ' .
118 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
119 'AND usr_id = ' .
$ilDB->quote($a_usr_id,
'integer');
132 'obj_id' => array(
'integer', $a_obj_id),
133 'usr_id' => array(
'integer', $a_usr_id)
138 $query =
'UPDATE obj_members SET ' .
139 $update_string .
' ' .
140 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
141 'AND usr_id = ' .
$ilDB->quote($a_usr_id,
'integer');
143 $ilDB->manipulate($query);
146 $query =
'DELETE from obj_members ' .
147 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
148 'AND usr_id = ' .
$ilDB->quote($a_usr_id,
'integer') .
' ' .
149 'AND admin = ' .
$ilDB->quote(0,
'integer') .
' ' .
150 'AND tutor = ' .
$ilDB->quote(0,
'integer') .
' ' .
151 'AND member = ' .
$ilDB->quote(0,
'integer');
152 $ilDB->manipulate($query);
158 switch (substr($title, 0, 8)) {
175 int $a_membership_role_type
180 $query =
'SELECT * FROM obj_members ' .
181 'WHERE obj_id = ' .
$ilDB->quote($a_obj_id,
'integer') .
' ' .
185 switch ($a_membership_role_type) {
187 return (
int) $row->admin;
190 return (
int) $row->tutor;
193 return (
int) $row->member;
205 return $this->component;
210 return $this->usr_id;
215 return (
bool) ($this->participants_status[$this->getUserId()][
'blocked'] ??
false);
223 return (
bool) ($this->participants_status[$this->getUserId()][
'contact'] ??
false);
228 return $this->participants;
233 return $this->members;
238 return $this->admins;
243 return $this->tutors;
248 return $this->participants;
253 if ($this->numMembers ===
null) {
254 $this->numMembers = $this->rbacReview->getNumberOfAssignedUsers($this->member_roles);
256 return $this->numMembers;
261 $this->roles = $this->rbacReview->getRolesOfRoleFolder($this->ref_id,
false);
262 $this->member_roles = [];
263 foreach ($this->roles as $role_id) {
265 switch (substr($title, 0, 8)) {
267 $this->member_roles[] = $role_id;
269 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
270 $this->participants =
true;
271 $this->members =
true;
277 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
278 $this->participants =
true;
279 $this->admins =
true;
285 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
286 $this->participants =
true;
287 $this->tutors =
true;
293 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
294 $this->participants =
true;
295 $this->admins =
true;
300 $this->member_roles[] = $role_id;
302 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
303 $this->participants =
true;
304 $this->members =
true;
310 $this->member_roles[] = $role_id;
311 if ($this->rbacReview->isAssigned($this->getUserId(), $role_id)) {
312 $this->participants =
true;
313 $this->members =
true;
322 $query =
"SELECT * FROM obj_members " .
323 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" " .
324 'AND usr_id = ' . $this->db->quote($this->getUserId(),
'integer');
326 $res = $this->db->query($query);
327 $this->participants_status = array();
329 $this->participants_status[$this->getUserId()][
'blocked'] = (bool) $row->blocked;
330 $this->participants_status[$this->getUserId()][
'notification'] = (bool) $row->notification;
331 $this->participants_status[$this->getUserId()][
'passed'] = (bool) $row->passed;
332 $this->participants_status[$this->getUserId()][
'contact'] = (bool) $row->contact;
336 public function add(
int $a_usr_id,
int $a_role): bool
338 if ($this->rbacReview->isAssignedToAtLeastOneGivenRole($a_usr_id, $this->roles)) {
345 $this->admins =
true;
349 $this->tutors =
true;
354 $this->members =
true;
358 $this->rbacAdmin->assignUser($this->role_data[$a_role], $a_usr_id);
359 $this->addRecommendation($a_usr_id);
362 $this->deleteSubscriber($a_usr_id);
366 $this->eventHandler->raise(
367 $this->getComponent(),
370 'obj_id' => $this->obj_id,
371 'usr_id' => $a_usr_id,
378 public function delete(
int $a_usr_id):
void
380 $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->ref_id);
381 foreach ($this->roles as $role_id) {
382 $this->rbacAdmin->deassignUser($role_id, $a_usr_id);
385 $query =
"DELETE FROM obj_members " .
386 "WHERE usr_id = " . $this->db->quote($a_usr_id,
'integer') .
" " .
387 "AND obj_id = " . $this->db->quote($this->obj_id,
'integer');
388 $res = $this->db->manipulate($query);
390 $this->eventHandler->raise(
391 $this->getComponent(),
394 'obj_id' => $this->obj_id,
395 'usr_id' => $a_usr_id
402 $query =
"DELETE FROM il_subscribers " .
403 "WHERE usr_id = " . $this->db->quote($a_usr_id,
'integer') .
" " .
404 "AND obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" ";
405 $res = $this->db->manipulate($query);
417 $this->db->manipulate(
418 'UPDATE obj_members SET ' .
419 'contact = ' . $this->db->quote($a_contact,
'integer') .
' ' .
420 'WHERE obj_id = ' . $this->db->quote($this->obj_id,
'integer') .
' ' .
421 'AND usr_id = ' . $this->db->quote($a_usr_id,
'integer')
423 $this->participants_status[$a_usr_id][
'contact'] = $a_contact;
428 $this->participants_status[$a_usr_id][
'notification'] = $a_notification;
430 $query =
"SELECT * FROM obj_members " .
431 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" " .
432 "AND usr_id = " . $this->db->quote($a_usr_id,
'integer');
433 $res = $this->db->query($query);
434 if (
$res->numRows()) {
435 $query =
"UPDATE obj_members SET " .
436 "notification = " . $this->db->quote((
int) $a_notification,
'integer') .
" " .
437 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" " .
438 "AND usr_id = " . $this->db->quote($a_usr_id,
'integer');
440 $query =
"INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) " .
442 $this->db->quote((
int) $a_notification,
'integer') .
", " .
443 $this->db->quote($this->obj_id,
'integer') .
", " .
444 $this->db->quote($a_usr_id,
'integer') .
", " .
445 $this->db->quote(0,
'integer') .
", " .
446 $this->db->quote(0,
'integer') .
447 ") ON DUPLICATE KEY UPDATE notification = VALUES(notification)";
449 $this->db->manipulate($query);
455 $this->type ===
'crs' ?
460 SELECT COUNT(rolesusers.usr_id) cnt
462 FROM object_data rdata
464 LEFT JOIN rbac_ua rolesusers
465 ON rolesusers.rol_id = rdata.obj_id
467 WHERE rdata.obj_id = %s
470 $query .=
' AND ' . $this->db->in(
'rolesusers.usr_id', $a_usr_ids,
true,
'integer');
471 $res = $this->db->queryF($query, array(
'integer'), array($admin_role_id));
474 return $data[
'cnt'] > 0;
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
Base class for course and group participant.
checkLastAdmin(array $a_usr_ids)
static getMembershipRoleType(int $a_role_id)
addRecommendation($a_usr_id)
updateNotification(int $a_usr_id, bool $a_notification)
add(int $a_usr_id, int $a_role)
getComponent()
Get component name Used for event handling.
ilAppEventHandler $eventHandler
updateContact(int $a_usr_id, bool $a_contact)
ilObjectDataCache $objectDataCache
static lookupStatusByMembershipRoleType(int $a_obj_id, int $a_usr_id, int $a_membership_role_type)
array $participants_status
isContact()
Check if user is contact for current object.
deleteSubscriber(int $a_usr_id)
ilRecommendedContentManager $recommended_content_manager
static updateMemberRoles(int $a_obj_id, int $a_usr_id, int $a_role_id, int $a_status)
__construct(string $a_component_name, int $a_obj_id, int $a_usr_id)
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deleteUserEntry(int $a_usr_id, int $a_obj_id)