ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 = 0;
54
55 private $participants_status = array();
56
63 protected function __construct($a_component_name, $a_obj_id, $a_usr_id)
64 {
65 global $ilDB,$lng;
66
67 $this->obj_id = $a_obj_id;
68 $this->usr_id = $a_usr_id;
69 $this->type = ilObject::_lookupType($a_obj_id);
70 $ref_ids = ilObject::_getAllReferences($this->obj_id);
71 $this->ref_id = current($ref_ids);
72
73 $this->component = $a_component_name;
74
75 $this->readParticipant();
76 $this->readParticipantStatus();
77 }
78
86 public static function updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
87 {
88 global $ilDB;
89
90 $a_membership_role_type = self::getMembershipRoleType($a_role_id);
91
92 ilLoggerFactory::getInstance()->getLogger('crs')->debug($a_membership_role_type);
93
94 switch($a_membership_role_type)
95 {
97 $update_fields = array('admin' => array('integer', $a_status ? 1 : 0));
98 $update_string = ('admin = '.$ilDB->quote($a_status ? 1 : 0, 'integer'));
99 break;
100
102 $update_fields = array('tutor' => array('integer', $a_status ? 1 : 0));
103 $update_string = ('tutor = '.$ilDB->quote($a_status ? 1 : 0, 'integer'));
104 break;
105
107 default:
108 $current_status = self::lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type);
109 ilLoggerFactory::getInstance()->getLogger('crs')->debug($current_status);
110
111 if($a_status)
112 {
113 $new_status = $current_status + 1;
114 }
115 if(!$a_status)
116 {
117 $new_status = $current_status - 1;
118 if($new_status < 0)
119 {
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(DB_FETCHMODE_OBJECT))
136 {
137 if($row->num)
138 {
139 $found = TRUE;
140 }
141 }
142 if(!$found)
143 {
144 $ilDB->replace(
145 'obj_members',
146 array(
147 'obj_id' => array('integer',$a_obj_id),
148 'usr_id' => array('integer',$a_usr_id)
149 ),
150 $update_fields
151 );
152 }
153 else
154 {
155 $query = 'UPDATE obj_members SET '.
156 $update_string.' '.
157 'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
158 'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
159
160 $ilDB->manipulate($query);
161 }
162 }
163
168 public static function getMembershipRoleType($a_role_id)
169 {
170 $title = ilObject::_lookupTitle($a_role_id);
171 switch(substr($title, 0, 8))
172 {
173 case 'il_crs_a':
174 case 'il_grp_a':
176
177 case 'il_crs_t':
179
180 case 'il_crs_m':
181 default:
183
184 }
185 }
186
195 public static function lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
196 {
197 global $ilDB;
198
199 $query = 'SELECT * FROM obj_members '.
200 'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
201 'AND usr_id = '.$ilDB->quote($a_usr_id).' ';
202 $res = $ilDB->query($query);
203 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
204 {
205 switch($a_membership_role_type)
206 {
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 return $this->numMembers;
284 }
285
286
291 protected function readParticipant()
292 {
293 global $rbacreview,$ilObjDataCache,$ilLog;
294
295 $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id,false);
296
297 $users = array();
298 $this->participants = array();
299 $this->members = $this->admins = $this->tutors = array();
300
301 $member_roles = array();
302
303 foreach($this->roles as $role_id)
304 {
305 $title = $ilObjDataCache->lookupTitle($role_id);
306 switch(substr($title,0,8))
307 {
308 case 'il_crs_m':
309 $member_roles[] = $role_id;
310 $this->role_data[IL_CRS_MEMBER] = $role_id;
311 if($rbacreview->isAssigned($this->getUserId(),$role_id))
312 {
313 $this->participants = true;
314 $this->members = true;
315 }
316 break;
317
318 case 'il_crs_a':
319 $this->role_data[IL_CRS_ADMIN] = $role_id;
320 if($rbacreview->isAssigned($this->getUserId(),$role_id))
321 {
322 $this->participants = true;
323 $this->admins = true;
324 }
325 break;
326
327 case 'il_crs_t':
328 $this->role_data[IL_CRS_TUTOR] = $role_id;
329 if($rbacreview->isAssigned($this->getUserId(),$role_id))
330 {
331 $this->participants = true;
332 $this->tutors = true;
333 }
334 break;
335
336 case 'il_grp_a':
337 $this->role_data[IL_GRP_ADMIN] = $role_id;
338 if($rbacreview->isAssigned($this->getUserId(),$role_id))
339 {
340 $this->participants = true;
341 $this->admins = true;
342 }
343 break;
344
345 case 'il_grp_m':
346 $member_roles[] = $role_id;
347 $this->role_data[IL_GRP_MEMBER] = $role_id;
348 if($rbacreview->isAssigned($this->getUserId(),$role_id))
349 {
350 $this->participants = true;
351 $this->members = true;
352 }
353 break;
354
355 default:
356
357 $member_roles[] = $role_id;
358 if($rbacreview->isAssigned($this->getUserId(),$role_id))
359 {
360 $this->participants = true;
361 $this->members = true;
362 }
363 break;
364 }
365 }
366 $this->numMembers = $rbacreview->getNumberOfAssignedUsers((array) $member_roles);
367 }
368
373 protected function readParticipantStatus()
374 {
375 global $ilDB;
376
377 $query = "SELECT * FROM obj_members ".
378 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
379 'AND usr_id = '.$ilDB->quote($this->getUserId(),'integer');
380
381 $res = $ilDB->query($query);
382 $this->participants_status = array();
383 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
384 {
385 $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
386 $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
387 $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
388 // cognos-blu-patch: begin
389 $this->participants_status[$this->getUserId()]['contact'] = $row->contact;
390 // cognos-blu-patch: end
391 }
392 }
393
404 public function add($a_usr_id,$a_role)
405 {
406 global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
407
408
409 if($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id,$this->roles))
410 {
411 return false;
412 }
413
414 switch($a_role)
415 {
416 case IL_CRS_ADMIN:
417 $this->admins = true;
418 break;
419
420 case IL_CRS_TUTOR:
421 $this->tutors = true;
422 break;
423
424 case IL_CRS_MEMBER:
425 $this->members = true;
426 break;
427
428 case IL_GRP_ADMIN:
429 $this->admins = true;
430 break;
431
432 case IL_GRP_MEMBER:
433 $this->members = true;
434 break;
435 }
436
437 $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
438 $this->addDesktopItem($a_usr_id);
439
440 // Delete subscription request
441 $this->deleteSubscriber($a_usr_id);
442
443 include_once './Services/Membership/classes/class.ilWaitingList.php';
444 ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
445
446 $ilLog->write(__METHOD__.': Raise new event: '.$this->getComponent().' addParticipant');
447 $ilAppEventHandler->raise(
448 $this->getComponent(),
449 "addParticipant",
450 array(
451 'obj_id' => $this->obj_id,
452 'usr_id' => $a_usr_id,
453 'role_id' => $a_role)
454 );
455 return true;
456 }
457
465 public function delete($a_usr_id)
466 {
467 global $rbacadmin,$ilDB, $ilAppEventHandler;
468
469 $this->dropDesktopItem($a_usr_id);
470 foreach($this->roles as $role_id)
471 {
472 $rbacadmin->deassignUser($role_id,$a_usr_id);
473 }
474
475 $query = "DELETE FROM obj_members ".
476 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
477 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
478 $res = $ilDB->manipulate($query);
479
480 $ilAppEventHandler->raise(
481 $this->getComponent(),
482 "deleteParticipant",
483 array(
484 'obj_id' => $this->obj_id,
485 'usr_id' => $a_usr_id)
486 );
487 return true;
488 }
489
495 public function deleteSubscriber($a_usr_id)
496 {
497 global $ilDB;
498
499 $query = "DELETE FROM il_subscribers ".
500 "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
501 "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
502 $res = $ilDB->manipulate($query);
503
504 return true;
505 }
506
514 public function addDesktopItem($a_usr_id)
515 {
516 if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
517 {
518 ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
519 }
520 return true;
521 }
522
530 function dropDesktopItem($a_usr_id)
531 {
532 if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
533 {
534 ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
535 }
536
537 return true;
538 }
539
540 // cognos-blu-patch: begin
548 public function updateContact($a_usr_id, $a_contact)
549 {
550 global $ilDB;
551
552 $ilDB->manipulate(
553 'UPDATE obj_members SET '.
554 'contact = '.$ilDB->quote($a_contact,'integer').' '.
555 'WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer').' '.
556 'AND usr_id = '.$ilDB->quote($a_usr_id,'integer'));
557
558 $this->participants_status[$a_usr_id]['contact'] = $a_contact;
559 return TRUE;
560 }
561 // cognos-blu-patch: end
562
571 public function updateNotification($a_usr_id,$a_notification)
572 {
573 global $ilDB;
574
575 $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
576
577 $query = "SELECT * FROM obj_members ".
578 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
579 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
580 $res = $ilDB->query($query);
581 if($res->numRows())
582 {
583 $query = "UPDATE obj_members SET ".
584 "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
585 "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
586 "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
587 }
588 else
589 {
590 $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
591 "VALUES ( ".
592 $ilDB->quote((int) $a_notification ,'integer').", ".
593 $ilDB->quote($this->obj_id ,'integer').", ".
594 $ilDB->quote($a_usr_id ,'integer').", ".
595 $ilDB->quote(0,'integer').", ".
596 $ilDB->quote(0,'integer').
597 ")";
598
599 }
600 $res = $ilDB->manipulate($query);
601 return true;
602 }
603
611 public function checkLastAdmin($a_usr_ids)
612 {
613 global $ilDB;
614
615 $admin_role_id =
616 $this->type == 'crs' ?
617 $this->role_data[IL_CRS_ADMIN] :
618 $this->role_data[IL_GRP_ADMIN];
619
620
621 $query = "
622 SELECT COUNT(rolesusers.usr_id) cnt
623
624 FROM object_data rdata
625
626 LEFT JOIN rbac_ua rolesusers
627 ON rolesusers.rol_id = rdata.obj_id
628
629 WHERE rdata.obj_id = %s
630 ";
631
632 $query .= ' AND '.$ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
633 $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
634
635 $data = $ilDB->fetchAssoc($res);
636
637 return (int)$data['cnt'] > 0;
638 }
639
640
641}
642?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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.
$data
global $lng
Definition: privfeed.php:40
global $ilDB