ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilParticipant.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
25include_once './Services/Membership/classes/class.ilParticipants.php';
26
34abstract class ilParticipant
35{
39
40
41 private $obj_id = 0;
42 private $usr_id = 0;
43 protected $type = '';
44 private $ref_id = 0;
45
46 private $component = '';
47
48 private $participants = false;
49 private $admins = false;
50 private $tutors = false;
51 private $members = false;
52
53 private $numMembers = null;
54
55 private $member_roles = [];
56
57 private $participants_status = array();
58
65 protected function __construct($a_component_name, $a_obj_id, $a_usr_id)
66 {
67 global $DIC;
68
69 $ilDB = $DIC['ilDB'];
70 $lng = $DIC['lng'];
71
72 $this->obj_id = $a_obj_id;
73 $this->usr_id = $a_usr_id;
74 $this->type = ilObject::_lookupType($a_obj_id);
75 $ref_ids = ilObject::_getAllReferences($this->obj_id);
76 $this->ref_id = current($ref_ids);
77
78 $this->component = $a_component_name;
79
80 $this->readParticipant();
81 $this->readParticipantStatus();
82 }
83
91 public static function updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
92 {
93 global $DIC;
94
95 $ilDB = $DIC['ilDB'];
96
97 $a_membership_role_type = self::getMembershipRoleType($a_role_id);
98
99 switch ($a_membership_role_type) {
101 $update_fields = array('admin' => array('integer', $a_status ? 1 : 0));
102 $update_string = ('admin = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
103 break;
104
106 $update_fields = array('tutor' => array('integer', $a_status ? 1 : 0));
107 $update_string = ('tutor = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
108 break;
109
111 default:
112 $current_status = self::lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type);
113
114 if ($a_status) {
115 $new_status = $current_status + 1;
116 }
117 if (!$a_status) {
118 $new_status = $current_status - 1;
119 if ($new_status < 0) {
120 $new_status = 0;
121 }
122 }
123
124 $update_fields = array('member' => array('integer', $new_status));
125 $update_string = ('member = ' . $ilDB->quote($new_status, 'integer'));
126 break;
127 }
128
129 $query = 'SELECT count(*) num FROM obj_members ' .
130 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
131 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
132 $res = $ilDB->query($query);
133
134 $found = false;
135 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
136 if ($row->num) {
137 $found = true;
138 }
139 }
140 if (!$found) {
141 $ilDB->replace(
142 'obj_members',
143 array(
144 'obj_id' => array('integer',$a_obj_id),
145 'usr_id' => array('integer',$a_usr_id)
146 ),
147 $update_fields
148 );
149 } else {
150 $query = 'UPDATE obj_members SET ' .
151 $update_string . ' ' .
152 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
153 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
154
155 $ilDB->manipulate($query);
156 }
157
158 $query = 'DELETE from obj_members ' .
159 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
160 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer') . ' ' .
161 'AND admin = ' . $ilDB->quote(0, 'integer') . ' ' .
162 'AND tutor = ' . $ilDB->quote(0, 'integer') . ' ' .
163 'AND member = ' . $ilDB->quote(0, 'integer');
164 $ilDB->manipulate($query);
165 }
166
171 public static function getMembershipRoleType($a_role_id)
172 {
173 $title = ilObject::_lookupTitle($a_role_id);
174 switch (substr($title, 0, 8)) {
175 case 'il_crs_a':
176 case 'il_grp_a':
178
179 case 'il_crs_t':
181
182 case 'il_crs_m':
183 default:
185
186 }
187 }
188
197 public static function lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
198 {
199 global $DIC;
200
201 $ilDB = $DIC['ilDB'];
202
203 $query = 'SELECT * FROM obj_members ' .
204 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
205 'AND usr_id = ' . $ilDB->quote($a_usr_id) . ' ';
206 $res = $ilDB->query($query);
207 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
208 switch ($a_membership_role_type) {
210 return $row->admin;
211
213 return $row->tutor;
214
216 return $row->member;
217 }
218 }
219 return 0;
220 }
221
222
228 protected function getComponent()
229 {
230 return $this->component;
231 }
232
237 public function getUserId()
238 {
239 return $this->usr_id;
240 }
241
242 public function isBlocked()
243 {
244 return (bool) $this->participants_status[$this->getUserId()]['blocked'];
245 }
246
247 // cognos-blu-patch: begin
252 public function isContact()
253 {
254 return (bool) $this->participants_status[$this->getUserId()]['contact'];
255 }
256
257
258 public function isAssigned()
259 {
260 return (bool) $this->participants;
261 }
262
263 public function isMember()
264 {
265 return (bool) $this->members;
266 }
267
268 public function isAdmin()
269 {
270 return $this->admins;
271 }
272
273 public function isTutor()
274 {
275 return (bool) $this->tutors;
276 }
277
278 public function isParticipant()
279 {
280 return (bool) $this->participants;
281 }
282
283 public function getNumberOfMembers()
284 {
285 global $DIC;
286
287 $rbacreview = $DIC['rbacreview'];
288
289 if ($this->numMembers === null) {
290 $this->numMembers = $rbacreview->getNumberOfAssignedUsers($this->member_roles);
291 }
292 return $this->numMembers;
293 }
294
295
300 protected function readParticipant()
301 {
302 global $DIC;
303
304 $rbacreview = $DIC['rbacreview'];
305 $ilObjDataCache = $DIC['ilObjDataCache'];
306
307 $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id, false);
308
309 $users = array();
310 $this->participants = array();
311 $this->members = $this->admins = $this->tutors = array();
312 $this->member_roles = [];
313
314 foreach ($this->roles as $role_id) {
315 $title = $ilObjDataCache->lookupTitle($role_id);
316 switch (substr($title, 0, 8)) {
317 case 'il_crs_m':
318 $this->member_roles[] = $role_id;
319 $this->role_data[IL_CRS_MEMBER] = $role_id;
320 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
321 $this->participants = true;
322 $this->members = true;
323 }
324 break;
325
326 case 'il_crs_a':
327 $this->role_data[IL_CRS_ADMIN] = $role_id;
328 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
329 $this->participants = true;
330 $this->admins = true;
331 }
332 break;
333
334 case 'il_crs_t':
335 $this->role_data[IL_CRS_TUTOR] = $role_id;
336 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
337 $this->participants = true;
338 $this->tutors = true;
339 }
340 break;
341
342 case 'il_grp_a':
343 $this->role_data[IL_GRP_ADMIN] = $role_id;
344 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
345 $this->participants = true;
346 $this->admins = true;
347 }
348 break;
349
350 case 'il_grp_m':
351 $this->member_roles[] = $role_id;
352 $this->role_data[IL_GRP_MEMBER] = $role_id;
353 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
354 $this->participants = true;
355 $this->members = true;
356 }
357 break;
358
359 default:
360
361 $this->member_roles[] = $role_id;
362 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
363 $this->participants = true;
364 $this->members = true;
365 }
366 break;
367 }
368 }
369 }
370
375 protected function readParticipantStatus()
376 {
377 global $DIC;
378
379 $ilDB = $DIC['ilDB'];
380
381 $query = "SELECT * FROM obj_members " .
382 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
383 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
384
385 $res = $ilDB->query($query);
386 $this->participants_status = array();
387 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
388 $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
389 $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
390 $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
391 // cognos-blu-patch: begin
392 $this->participants_status[$this->getUserId()]['contact'] = $row->contact;
393 // cognos-blu-patch: end
394 }
395 }
396
407 public function add($a_usr_id, $a_role)
408 {
409 global $DIC;
410
411 $rbacadmin = $DIC['rbacadmin'];
412 $ilLog = $DIC->logger()->mmbr();
413 $ilAppEventHandler = $DIC['ilAppEventHandler'];
414 $rbacreview = $DIC['rbacreview'];
415
416
417 if ($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $this->roles)) {
418 return false;
419 }
420
421 switch ($a_role) {
422 case IL_CRS_ADMIN:
423 $this->admins = true;
424 break;
425
426 case IL_CRS_TUTOR:
427 $this->tutors = true;
428 break;
429
430 case IL_CRS_MEMBER:
431 $this->members = true;
432 break;
433
434 case IL_GRP_ADMIN:
435 $this->admins = true;
436 break;
437
438 case IL_GRP_MEMBER:
439 $this->members = true;
440 break;
441 }
442
443 $rbacadmin->assignUser($this->role_data[$a_role], $a_usr_id);
444 $this->addDesktopItem($a_usr_id);
445
446 // Delete subscription request
447 $this->deleteSubscriber($a_usr_id);
448
449 include_once './Services/Membership/classes/class.ilWaitingList.php';
450 ilWaitingList::deleteUserEntry($a_usr_id, $this->obj_id);
451
452 $ilLog->debug(': Raise new event: ' . $this->getComponent() . ' addParticipant');
453 $ilAppEventHandler->raise(
454 $this->getComponent(),
455 "addParticipant",
456 array(
457 'obj_id' => $this->obj_id,
458 'usr_id' => $a_usr_id,
459 'role_id' => $a_role)
460 );
461 return true;
462 }
463
471 public function delete($a_usr_id)
472 {
473 global $DIC;
474
475 $rbacadmin = $DIC['rbacadmin'];
476 $ilDB = $DIC['ilDB'];
477 $ilAppEventHandler = $DIC['ilAppEventHandler'];
478
479 $this->dropDesktopItem($a_usr_id);
480 foreach ($this->roles as $role_id) {
481 $rbacadmin->deassignUser($role_id, $a_usr_id);
482 }
483
484 $query = "DELETE FROM obj_members " .
485 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
486 "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer');
487 $res = $ilDB->manipulate($query);
488
489 $ilAppEventHandler->raise(
490 $this->getComponent(),
491 "deleteParticipant",
492 array(
493 'obj_id' => $this->obj_id,
494 'usr_id' => $a_usr_id)
495 );
496 return true;
497 }
498
504 public function deleteSubscriber($a_usr_id)
505 {
506 global $DIC;
507
508 $ilDB = $DIC['ilDB'];
509
510 $query = "DELETE FROM il_subscribers " .
511 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
512 "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
513 $res = $ilDB->manipulate($query);
514
515 return true;
516 }
517
525 public function addDesktopItem($a_usr_id)
526 {
527 if (!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
528 ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id, $this->type);
529 }
530 return true;
531 }
532
540 public function dropDesktopItem($a_usr_id)
541 {
542 if (ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
543 ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id, $this->type);
544 }
545
546 return true;
547 }
548
549 // cognos-blu-patch: begin
557 public function updateContact($a_usr_id, $a_contact)
558 {
559 global $DIC;
560
561 $ilDB = $DIC['ilDB'];
562
563 $ilDB->manipulate(
564 'UPDATE obj_members SET ' .
565 'contact = ' . $ilDB->quote($a_contact, 'integer') . ' ' .
566 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
567 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer')
568 );
569
570 $this->participants_status[$a_usr_id]['contact'] = $a_contact;
571 return true;
572 }
573 // cognos-blu-patch: end
574
583 public function updateNotification($a_usr_id, $a_notification)
584 {
585 global $DIC;
586
587 $ilDB = $DIC['ilDB'];
588
589 $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
590
591 $query = "SELECT * FROM obj_members " .
592 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
593 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
594 $res = $ilDB->query($query);
595 if ($res->numRows()) {
596 $query = "UPDATE obj_members SET " .
597 "notification = " . $ilDB->quote((int) $a_notification, 'integer') . " " .
598 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
599 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
600 } else {
601 $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) " .
602 "VALUES ( " .
603 $ilDB->quote((int) $a_notification, 'integer') . ", " .
604 $ilDB->quote($this->obj_id, 'integer') . ", " .
605 $ilDB->quote($a_usr_id, 'integer') . ", " .
606 $ilDB->quote(0, 'integer') . ", " .
607 $ilDB->quote(0, 'integer') .
608 ")";
609 }
610 $res = $ilDB->manipulate($query);
611 return true;
612 }
613
621 public function checkLastAdmin($a_usr_ids)
622 {
623 global $DIC;
624
625 $ilDB = $DIC['ilDB'];
626
627 $admin_role_id =
628 $this->type == 'crs' ?
629 $this->role_data[IL_CRS_ADMIN] :
630 $this->role_data[IL_GRP_ADMIN];
631
632
633 $query = "
634 SELECT COUNT(rolesusers.usr_id) cnt
635
636 FROM object_data rdata
637
638 LEFT JOIN rbac_ua rolesusers
639 ON rolesusers.rol_id = rdata.obj_id
640
641 WHERE rdata.obj_id = %s
642 ";
643
644 $query .= ' AND ' . $ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
645 $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
646
647 $data = $ilDB->fetchAssoc($res);
648
649 return (int) $data['cnt'] > 0;
650 }
651}
$users
Definition: authpage.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_GRP_MEMBER
const IL_CRS_TUTOR
const IL_GRP_ADMIN
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user's personal desktop
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Base class for course and group participant.
checkLastAdmin($a_usr_ids)
Check if user for deletion are last admins.
updateContact($a_usr_id, $a_contact)
@global ilDB $ilDB
deleteSubscriber($a_usr_id)
Delete subsciber.
readParticipantStatus()
Read participant status @global ilDB $ilDB.
static updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
Update member roles @global ilDB $ilDB.
addDesktopItem($a_usr_id)
Add desktop item.
getComponent()
Get component name Used for event handling.
static lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
lookup assignment status @global ilDB $ilDB
__construct($a_component_name, $a_obj_id, $a_usr_id)
Singleton Constructor.
static getMembershipRoleType($a_role_id)
add($a_usr_id, $a_role)
Add user to course/group.
isContact()
Check if user is contact for current object.
getUserId()
get user id
dropDesktopItem($a_usr_id)
Drop desktop item.
updateNotification($a_usr_id, $a_notification)
Update notification status.
readParticipant()
Read participant.
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
$row
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: bench.php:6