ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB,$lng;
68
69 $this->obj_id = $a_obj_id;
70 $this->usr_id = $a_usr_id;
71 $this->type = ilObject::_lookupType($a_obj_id);
72 $ref_ids = ilObject::_getAllReferences($this->obj_id);
73 $this->ref_id = current($ref_ids);
74
75 $this->component = $a_component_name;
76
77 $this->readParticipant();
78 $this->readParticipantStatus();
79 }
80
88 public static function updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
89 {
90 global $ilDB;
91
92 $a_membership_role_type = self::getMembershipRoleType($a_role_id);
93
94 ilLoggerFactory::getInstance()->getLogger('crs')->debug($a_membership_role_type);
95
96 switch ($a_membership_role_type) {
98 $update_fields = array('admin' => array('integer', $a_status ? 1 : 0));
99 $update_string = ('admin = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
100 break;
101
103 $update_fields = array('tutor' => array('integer', $a_status ? 1 : 0));
104 $update_string = ('tutor = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
105 break;
106
108 default:
109 $current_status = self::lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type);
110 ilLoggerFactory::getInstance()->getLogger('crs')->debug($current_status);
111
112 if ($a_status) {
113 $new_status = $current_status + 1;
114 }
115 if (!$a_status) {
116 $new_status = $current_status - 1;
117 if ($new_status < 0) {
118 $new_status = 0;
119 }
120 }
121
122 $update_fields = array('member' => array('integer', $new_status));
123 $update_string = ('member = ' . $ilDB->quote($new_status, 'integer'));
124 break;
125 }
126
127 $query = 'SELECT count(*) num FROM obj_members ' .
128 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
129 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
130 $res = $ilDB->query($query);
131
132 $found = false;
133 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
134 if ($row->num) {
135 $found = true;
136 }
137 }
138 if (!$found) {
139 $ilDB->replace(
140 'obj_members',
141 array(
142 'obj_id' => array('integer',$a_obj_id),
143 'usr_id' => array('integer',$a_usr_id)
144 ),
145 $update_fields
146 );
147 } else {
148 $query = 'UPDATE obj_members SET ' .
149 $update_string . ' ' .
150 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
151 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
152
153 $ilDB->manipulate($query);
154 }
155
156 $query = 'DELETE from obj_members ' .
157 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
158 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer') . ' ' .
159 'AND admin = ' . $ilDB->quote(0, 'integer') . ' ' .
160 'AND tutor = ' . $ilDB->quote(0, 'integer') . ' ' .
161 'AND member = ' . $ilDB->quote(0, 'integer');
162 $ilDB->manipulate($query);
163
164 ilLoggerFactory::getLogger('mem')->debug($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 $ilDB;
200
201 $query = 'SELECT * FROM obj_members ' .
202 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
203 'AND usr_id = ' . $ilDB->quote($a_usr_id) . ' ';
204 $res = $ilDB->query($query);
205 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
206 switch ($a_membership_role_type) {
208 return $row->admin;
209
211 return $row->tutor;
212
214 return $row->member;
215 }
216 }
217 return 0;
218 }
219
220
226 protected function getComponent()
227 {
228 return $this->component;
229 }
230
235 public function getUserId()
236 {
237 return $this->usr_id;
238 }
239
240 public function isBlocked()
241 {
242 return (bool) $this->participants_status[$this->getUserId()]['blocked'];
243 }
244
245 // cognos-blu-patch: begin
250 public function isContact()
251 {
252 return (bool) $this->participants_status[$this->getUserId()]['contact'];
253 }
254
255
256 public function isAssigned()
257 {
258 return (bool) $this->participants;
259 }
260
261 public function isMember()
262 {
263 return (bool) $this->members;
264 }
265
266 public function isAdmin()
267 {
268 return $this->admins;
269 }
270
271 public function isTutor()
272 {
273 return (bool) $this->tutors;
274 }
275
276 public function isParticipant()
277 {
278 return (bool) $this->participants;
279 }
280
281 public function getNumberOfMembers()
282 {
283 global $DIC;
284
285 $rbacreview = $DIC['rbacreview'];
286
287 if ($this->numMembers === null) {
288 $this->numMembers = $rbacreview->getNumberOfAssignedUsers($this->member_roles);
289 }
290 return $this->numMembers;
291 }
292
293
298 protected function readParticipant()
299 {
300 global $rbacreview,$ilObjDataCache,$ilLog;
301
302 $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id, false);
303
304 $users = array();
305 $this->participants = array();
306 $this->members = $this->admins = $this->tutors = array();
307 $this->member_roles = [];
308
309 foreach ($this->roles as $role_id) {
310 $title = $ilObjDataCache->lookupTitle($role_id);
311 switch (substr($title, 0, 8)) {
312 case 'il_crs_m':
313 $this->member_roles[] = $role_id;
314 $this->role_data[IL_CRS_MEMBER] = $role_id;
315 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
316 $this->participants = true;
317 $this->members = true;
318 }
319 break;
320
321 case 'il_crs_a':
322 $this->role_data[IL_CRS_ADMIN] = $role_id;
323 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
324 $this->participants = true;
325 $this->admins = true;
326 }
327 break;
328
329 case 'il_crs_t':
330 $this->role_data[IL_CRS_TUTOR] = $role_id;
331 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
332 $this->participants = true;
333 $this->tutors = true;
334 }
335 break;
336
337 case 'il_grp_a':
338 $this->role_data[IL_GRP_ADMIN] = $role_id;
339 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
340 $this->participants = true;
341 $this->admins = true;
342 }
343 break;
344
345 case 'il_grp_m':
346 $this->member_roles[] = $role_id;
347 $this->role_data[IL_GRP_MEMBER] = $role_id;
348 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
349 $this->participants = true;
350 $this->members = true;
351 }
352 break;
353
354 default:
355
356 $this->member_roles[] = $role_id;
357 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
358 $this->participants = true;
359 $this->members = true;
360 }
361 break;
362 }
363 }
364 }
365
370 protected function readParticipantStatus()
371 {
372 global $ilDB;
373
374 $query = "SELECT * FROM obj_members " .
375 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
376 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
377
378 $res = $ilDB->query($query);
379 $this->participants_status = array();
380 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
381 $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
382 $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
383 $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
384 // cognos-blu-patch: begin
385 $this->participants_status[$this->getUserId()]['contact'] = $row->contact;
386 // cognos-blu-patch: end
387 }
388 }
389
400 public function add($a_usr_id, $a_role)
401 {
402 global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
403
404
405 if ($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $this->roles)) {
406 return false;
407 }
408
409 switch ($a_role) {
410 case IL_CRS_ADMIN:
411 $this->admins = true;
412 break;
413
414 case IL_CRS_TUTOR:
415 $this->tutors = true;
416 break;
417
418 case IL_CRS_MEMBER:
419 $this->members = true;
420 break;
421
422 case IL_GRP_ADMIN:
423 $this->admins = true;
424 break;
425
426 case IL_GRP_MEMBER:
427 $this->members = true;
428 break;
429 }
430
431 $rbacadmin->assignUser($this->role_data[$a_role], $a_usr_id);
432 $this->addDesktopItem($a_usr_id);
433
434 // Delete subscription request
435 $this->deleteSubscriber($a_usr_id);
436
437 include_once './Services/Membership/classes/class.ilWaitingList.php';
438 ilWaitingList::deleteUserEntry($a_usr_id, $this->obj_id);
439
440 $ilLog->write(__METHOD__ . ': Raise new event: ' . $this->getComponent() . ' addParticipant');
441 $ilAppEventHandler->raise(
442 $this->getComponent(),
443 "addParticipant",
444 array(
445 'obj_id' => $this->obj_id,
446 'usr_id' => $a_usr_id,
447 'role_id' => $a_role)
448 );
449 return true;
450 }
451
459 public function delete($a_usr_id)
460 {
461 global $rbacadmin,$ilDB, $ilAppEventHandler;
462
463 $this->dropDesktopItem($a_usr_id);
464 foreach ($this->roles as $role_id) {
465 $rbacadmin->deassignUser($role_id, $a_usr_id);
466 }
467
468 $query = "DELETE FROM obj_members " .
469 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
470 "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer');
471 $res = $ilDB->manipulate($query);
472
473 $ilAppEventHandler->raise(
474 $this->getComponent(),
475 "deleteParticipant",
476 array(
477 'obj_id' => $this->obj_id,
478 'usr_id' => $a_usr_id)
479 );
480 return true;
481 }
482
488 public function deleteSubscriber($a_usr_id)
489 {
490 global $ilDB;
491
492 $query = "DELETE FROM il_subscribers " .
493 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
494 "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
495 $res = $ilDB->manipulate($query);
496
497 return true;
498 }
499
507 public function addDesktopItem($a_usr_id)
508 {
509 if (!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
510 ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id, $this->type);
511 }
512 return true;
513 }
514
522 public function dropDesktopItem($a_usr_id)
523 {
524 if (ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id, $this->type)) {
525 ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id, $this->type);
526 }
527
528 return true;
529 }
530
531 // cognos-blu-patch: begin
539 public function updateContact($a_usr_id, $a_contact)
540 {
541 global $ilDB;
542
543 $ilDB->manipulate(
544 'UPDATE obj_members SET ' .
545 'contact = ' . $ilDB->quote($a_contact, 'integer') . ' ' .
546 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
547 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer')
548 );
549
550 $this->participants_status[$a_usr_id]['contact'] = $a_contact;
551 return true;
552 }
553 // cognos-blu-patch: end
554
563 public function updateNotification($a_usr_id, $a_notification)
564 {
565 global $ilDB;
566
567 $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
568
569 $query = "SELECT * FROM obj_members " .
570 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
571 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
572 $res = $ilDB->query($query);
573 if ($res->numRows()) {
574 $query = "UPDATE obj_members SET " .
575 "notification = " . $ilDB->quote((int) $a_notification, 'integer') . " " .
576 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
577 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
578 } else {
579 $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) " .
580 "VALUES ( " .
581 $ilDB->quote((int) $a_notification, 'integer') . ", " .
582 $ilDB->quote($this->obj_id, 'integer') . ", " .
583 $ilDB->quote($a_usr_id, 'integer') . ", " .
584 $ilDB->quote(0, 'integer') . ", " .
585 $ilDB->quote(0, 'integer') .
586 ")";
587 }
588 $res = $ilDB->manipulate($query);
589 return true;
590 }
591
599 public function checkLastAdmin($a_usr_ids)
600 {
601 global $ilDB;
602
603 $admin_role_id =
604 $this->type == 'crs' ?
605 $this->role_data[IL_CRS_ADMIN] :
606 $this->role_data[IL_GRP_ADMIN];
607
608
609 $query = "
610 SELECT COUNT(rolesusers.usr_id) cnt
611
612 FROM object_data rdata
613
614 LEFT JOIN rbac_ua rolesusers
615 ON rolesusers.rol_id = rdata.obj_id
616
617 WHERE rdata.obj_id = %s
618 ";
619
620 $query .= ' AND ' . $ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
621 $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
622
623 $data = $ilDB->fetchAssoc($res);
624
625 return (int) $data['cnt'] > 0;
626 }
627}
$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 getLogger($a_component_id)
Get component logger.
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.
global $lng
Definition: privfeed.php:17
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB