ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
63
70 protected function __construct($a_component_name, $a_obj_id, $a_usr_id)
71 {
72 global $DIC;
73
74 $ilDB = $DIC['ilDB'];
75 $lng = $DIC['lng'];
76
77 $this->obj_id = $a_obj_id;
78 $this->usr_id = $a_usr_id;
79 $this->type = ilObject::_lookupType($a_obj_id);
80 $ref_ids = ilObject::_getAllReferences($this->obj_id);
81 $this->ref_id = current($ref_ids);
82
83 $this->component = $a_component_name;
84
85 $this->recommended_content_manager = new ilRecommendedContentManager();
86
87 $this->readParticipant();
88 $this->readParticipantStatus();
89 }
90
98 public static function updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
99 {
100 global $DIC;
101
102 $ilDB = $DIC['ilDB'];
103
104 $a_membership_role_type = self::getMembershipRoleType($a_role_id);
105
106 switch ($a_membership_role_type) {
108 $update_fields = array('admin' => array('integer', $a_status ? 1 : 0));
109 $update_string = ('admin = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
110 break;
111
113 $update_fields = array('tutor' => array('integer', $a_status ? 1 : 0));
114 $update_string = ('tutor = ' . $ilDB->quote($a_status ? 1 : 0, 'integer'));
115 break;
116
118 default:
119 $current_status = self::lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type);
120
121 if ($a_status) {
122 $new_status = $current_status + 1;
123 }
124 if (!$a_status) {
125 $new_status = $current_status - 1;
126 if ($new_status < 0) {
127 $new_status = 0;
128 }
129 }
130
131 $update_fields = array('member' => array('integer', $new_status));
132 $update_string = ('member = ' . $ilDB->quote($new_status, 'integer'));
133 break;
134 }
135
136 $query = 'SELECT count(*) num FROM obj_members ' .
137 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
138 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
139 $res = $ilDB->query($query);
140
141 $found = false;
142 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
143 if ($row->num) {
144 $found = true;
145 }
146 }
147 if (!$found) {
148 $ilDB->replace(
149 'obj_members',
150 array(
151 'obj_id' => array('integer',$a_obj_id),
152 'usr_id' => array('integer',$a_usr_id)
153 ),
154 $update_fields
155 );
156 } else {
157 $query = 'UPDATE obj_members SET ' .
158 $update_string . ' ' .
159 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
160 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
161
162 $ilDB->manipulate($query);
163 }
164
165 $query = 'DELETE from obj_members ' .
166 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
167 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer') . ' ' .
168 'AND admin = ' . $ilDB->quote(0, 'integer') . ' ' .
169 'AND tutor = ' . $ilDB->quote(0, 'integer') . ' ' .
170 'AND member = ' . $ilDB->quote(0, 'integer');
171 $ilDB->manipulate($query);
172 }
173
178 public static function getMembershipRoleType($a_role_id)
179 {
180 $title = ilObject::_lookupTitle($a_role_id);
181 switch (substr($title, 0, 8)) {
182 case 'il_crs_a':
183 case 'il_grp_a':
185
186 case 'il_crs_t':
188
189 case 'il_crs_m':
190 default:
192
193 }
194 }
195
204 public static function lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
205 {
206 global $DIC;
207
208 $ilDB = $DIC['ilDB'];
209
210 $query = 'SELECT * FROM obj_members ' .
211 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer') . ' ' .
212 'AND usr_id = ' . $ilDB->quote($a_usr_id) . ' ';
213 $res = $ilDB->query($query);
214 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
215 switch ($a_membership_role_type) {
217 return $row->admin;
218
220 return $row->tutor;
221
223 return $row->member;
224 }
225 }
226 return 0;
227 }
228
229
235 protected function getComponent()
236 {
237 return $this->component;
238 }
239
244 public function getUserId()
245 {
246 return $this->usr_id;
247 }
248
249 public function isBlocked()
250 {
251 return (bool) $this->participants_status[$this->getUserId()]['blocked'];
252 }
253
254 // cognos-blu-patch: begin
259 public function isContact()
260 {
261 return (bool) $this->participants_status[$this->getUserId()]['contact'];
262 }
263
264
265 public function isAssigned()
266 {
267 return (bool) $this->participants;
268 }
269
270 public function isMember()
271 {
272 return (bool) $this->members;
273 }
274
275 public function isAdmin()
276 {
277 return $this->admins;
278 }
279
280 public function isTutor()
281 {
282 return (bool) $this->tutors;
283 }
284
285 public function isParticipant()
286 {
287 return (bool) $this->participants;
288 }
289
290 public function getNumberOfMembers()
291 {
292 global $DIC;
293
294 $rbacreview = $DIC['rbacreview'];
295
296 if ($this->numMembers === null) {
297 $this->numMembers = $rbacreview->getNumberOfAssignedUsers($this->member_roles);
298 }
299 return $this->numMembers;
300 }
301
302
307 protected function readParticipant()
308 {
309 global $DIC;
310
311 $rbacreview = $DIC['rbacreview'];
312 $ilObjDataCache = $DIC['ilObjDataCache'];
313
314 $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id, false);
315
316 $users = array();
317 $this->participants = array();
318 $this->members = $this->admins = $this->tutors = array();
319 $this->member_roles = [];
320
321 foreach ($this->roles as $role_id) {
322 $title = $ilObjDataCache->lookupTitle($role_id);
323 switch (substr($title, 0, 8)) {
324 case 'il_crs_m':
325 $this->member_roles[] = $role_id;
326 $this->role_data[IL_CRS_MEMBER] = $role_id;
327 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
328 $this->participants = true;
329 $this->members = true;
330 }
331 break;
332
333 case 'il_crs_a':
334 $this->role_data[IL_CRS_ADMIN] = $role_id;
335 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
336 $this->participants = true;
337 $this->admins = true;
338 }
339 break;
340
341 case 'il_crs_t':
342 $this->role_data[IL_CRS_TUTOR] = $role_id;
343 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
344 $this->participants = true;
345 $this->tutors = true;
346 }
347 break;
348
349 case 'il_grp_a':
350 $this->role_data[IL_GRP_ADMIN] = $role_id;
351 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
352 $this->participants = true;
353 $this->admins = true;
354 }
355 break;
356
357 case 'il_grp_m':
358 $this->member_roles[] = $role_id;
359 $this->role_data[IL_GRP_MEMBER] = $role_id;
360 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
361 $this->participants = true;
362 $this->members = true;
363 }
364 break;
365
366 default:
367
368 $this->member_roles[] = $role_id;
369 if ($rbacreview->isAssigned($this->getUserId(), $role_id)) {
370 $this->participants = true;
371 $this->members = true;
372 }
373 break;
374 }
375 }
376 }
377
382 protected function readParticipantStatus()
383 {
384 global $DIC;
385
386 $ilDB = $DIC['ilDB'];
387
388 $query = "SELECT * FROM obj_members " .
389 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
390 'AND usr_id = ' . $ilDB->quote($this->getUserId(), 'integer');
391
392 $res = $ilDB->query($query);
393 $this->participants_status = array();
394 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
395 $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
396 $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
397 $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
398 // cognos-blu-patch: begin
399 $this->participants_status[$this->getUserId()]['contact'] = $row->contact;
400 // cognos-blu-patch: end
401 }
402 }
403
414 public function add($a_usr_id, $a_role)
415 {
416 global $DIC;
417
418 $rbacadmin = $DIC['rbacadmin'];
419 $ilLog = $DIC->logger()->mmbr();
420 $ilAppEventHandler = $DIC['ilAppEventHandler'];
421 $rbacreview = $DIC['rbacreview'];
422
423
424 if ($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id, $this->roles)) {
425 return false;
426 }
427
428 switch ($a_role) {
429 case IL_CRS_ADMIN:
430 $this->admins = true;
431 break;
432
433 case IL_CRS_TUTOR:
434 $this->tutors = true;
435 break;
436
437 case IL_CRS_MEMBER:
438 $this->members = true;
439 break;
440
441 case IL_GRP_ADMIN:
442 $this->admins = true;
443 break;
444
445 case IL_GRP_MEMBER:
446 $this->members = true;
447 break;
448 }
449
450 $rbacadmin->assignUser($this->role_data[$a_role], $a_usr_id);
451 $this->addRecommendation($a_usr_id);
452
453 // Delete subscription request
454 $this->deleteSubscriber($a_usr_id);
455
456 include_once './Services/Membership/classes/class.ilWaitingList.php';
457 ilWaitingList::deleteUserEntry($a_usr_id, $this->obj_id);
458
459 $ilLog->debug(': Raise new event: ' . $this->getComponent() . ' addParticipant');
460 $ilAppEventHandler->raise(
461 $this->getComponent(),
462 "addParticipant",
463 array(
464 'obj_id' => $this->obj_id,
465 'usr_id' => $a_usr_id,
466 'role_id' => $a_role)
467 );
468 return true;
469 }
470
478 public function delete($a_usr_id)
479 {
480 global $DIC;
481
482 $rbacadmin = $DIC['rbacadmin'];
483 $ilDB = $DIC['ilDB'];
484 $ilAppEventHandler = $DIC['ilAppEventHandler'];
485
486 $this->recommended_content_manager->removeObjectRecommendation($a_usr_id, $this->ref_id);
487
488 foreach ($this->roles as $role_id) {
489 $rbacadmin->deassignUser($role_id, $a_usr_id);
490 }
491
492 $query = "DELETE FROM obj_members " .
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 $ilAppEventHandler->raise(
498 $this->getComponent(),
499 "deleteParticipant",
500 array(
501 'obj_id' => $this->obj_id,
502 'usr_id' => $a_usr_id)
503 );
504 return true;
505 }
506
512 public function deleteSubscriber($a_usr_id)
513 {
514 global $DIC;
515
516 $ilDB = $DIC['ilDB'];
517
518 $query = "DELETE FROM il_subscribers " .
519 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
520 "AND obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " ";
521 $res = $ilDB->manipulate($query);
522
523 return true;
524 }
525
533 public function addRecommendation($a_usr_id)
534 {
535 // deactivated for now, see discussion at
536 // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
537 //$this->recommended_content_manager->addObjectRecommendation($a_usr_id, $this->ref_id);
538 return true;
539 }
540
541
542 // cognos-blu-patch: begin
550 public function updateContact($a_usr_id, $a_contact)
551 {
552 global $DIC;
553
554 $ilDB = $DIC['ilDB'];
555
556 $ilDB->manipulate(
557 'UPDATE obj_members SET ' .
558 'contact = ' . $ilDB->quote($a_contact, 'integer') . ' ' .
559 'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
560 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer')
561 );
562
563 $this->participants_status[$a_usr_id]['contact'] = $a_contact;
564 return true;
565 }
566 // cognos-blu-patch: end
567
576 public function updateNotification($a_usr_id, $a_notification)
577 {
578 global $DIC;
579
580 $ilDB = $DIC['ilDB'];
581
582 $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
583
584 $query = "SELECT * FROM obj_members " .
585 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
586 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
587 $res = $ilDB->query($query);
588 if ($res->numRows()) {
589 $query = "UPDATE obj_members SET " .
590 "notification = " . $ilDB->quote((int) $a_notification, 'integer') . " " .
591 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer') . " " .
592 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
593 } else {
594 $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) " .
595 "VALUES ( " .
596 $ilDB->quote((int) $a_notification, 'integer') . ", " .
597 $ilDB->quote($this->obj_id, 'integer') . ", " .
598 $ilDB->quote($a_usr_id, 'integer') . ", " .
599 $ilDB->quote(0, 'integer') . ", " .
600 $ilDB->quote(0, 'integer') .
601 ")";
602 }
603 $res = $ilDB->manipulate($query);
604 return true;
605 }
606
614 public function checkLastAdmin($a_usr_ids)
615 {
616 global $DIC;
617
618 $ilDB = $DIC['ilDB'];
619
620 $admin_role_id =
621 $this->type == 'crs' ?
622 $this->role_data[IL_CRS_ADMIN] :
623 $this->role_data[IL_GRP_ADMIN];
624
625
626 $query = "
627 SELECT COUNT(rolesusers.usr_id) cnt
628
629 FROM object_data rdata
630
631 LEFT JOIN rbac_ua rolesusers
632 ON rolesusers.rol_id = rdata.obj_id
633
634 WHERE rdata.obj_id = %s
635 ";
636
637 $query .= ' AND ' . $ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
638 $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
639
640 $data = $ilDB->fetchAssoc($res);
641
642 return (int) $data['cnt'] > 0;
643 }
644}
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 _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.
addRecommendation($a_usr_id)
Add desktop item.
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.
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
updateNotification($a_usr_id, $a_notification)
Update notification status.
readParticipant()
Read participant.
Recommended content manager (business logic)
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
$query
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46