ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
25 include_once './Services/Membership/classes/class.ilParticipants.php';
26 
34 abstract class ilParticipant
35 {
36  const MEMBERSHIP_ADMIN = 1;
37  const MEMBERSHIP_TUTOR = 2;
38  const MEMBERSHIP_MEMBER = 3;
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 
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  {
96  case self::MEMBERSHIP_ADMIN:
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 
101  case self::MEMBERSHIP_TUTOR:
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 
106  case self::MEMBERSHIP_MEMBER:
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(ilDBConstants::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  $query = 'DELETE from obj_members '.
164  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
165  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer').' '.
166  'AND admin = '.$ilDB->quote(0,'integer').' '.
167  'AND tutor = '.$ilDB->quote(0,'integer').' '.
168  'AND member = '.$ilDB->quote(0,'integer');
169  $ilDB->manipulate($query);
170 
171  ilLoggerFactory::getLogger('mem')->debug($query);
172 
173 
174  }
175 
180  public static function getMembershipRoleType($a_role_id)
181  {
182  $title = ilObject::_lookupTitle($a_role_id);
183  switch(substr($title, 0, 8))
184  {
185  case 'il_crs_a':
186  case 'il_grp_a':
187  return self::MEMBERSHIP_ADMIN;
188 
189  case 'il_crs_t':
190  return self::MEMBERSHIP_TUTOR;
191 
192  case 'il_crs_m':
193  default:
194  return self::MEMBERSHIP_MEMBER;
195 
196  }
197  }
198 
207  public static function lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
208  {
209  global $ilDB;
210 
211  $query = 'SELECT * FROM obj_members '.
212  'WHERE obj_id = '.$ilDB->quote($a_obj_id,'integer').' '.
213  'AND usr_id = '.$ilDB->quote($a_usr_id).' ';
214  $res = $ilDB->query($query);
215  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
216  {
217  switch($a_membership_role_type)
218  {
219  case self::MEMBERSHIP_ADMIN:
220  return $row->admin;
221 
222  case self::MEMBERSHIP_TUTOR:
223  return $row->tutor;
224 
225  case self::MEMBERSHIP_MEMBER:
226  return $row->member;
227  }
228  }
229  return 0;
230  }
231 
232 
238  protected function getComponent()
239  {
240  return $this->component;
241  }
242 
247  public function getUserId()
248  {
249  return $this->usr_id;
250  }
251 
252  public function isBlocked()
253  {
254  return (bool) $this->participants_status[$this->getUserId()]['blocked'];
255  }
256 
257  // cognos-blu-patch: begin
262  public function isContact()
263  {
264  return (bool) $this->participants_status[$this->getUserId()]['contact'];
265  }
266 
267 
268  public function isAssigned()
269  {
270  return (bool) $this->participants;
271  }
272 
273  public function isMember()
274  {
275  return (bool) $this->members;
276  }
277 
278  public function isAdmin()
279  {
280  return $this->admins;
281  }
282 
283  public function isTutor()
284  {
285  return (bool) $this->tutors;
286  }
287 
288  public function isParticipant()
289  {
290  return (bool) $this->participants;
291  }
292 
293  public function getNumberOfMembers()
294  {
295  return $this->numMembers;
296  }
297 
298 
303  protected function readParticipant()
304  {
305  global $rbacreview,$ilObjDataCache,$ilLog;
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 
313  $member_roles = array();
314 
315  foreach($this->roles as $role_id)
316  {
317  $title = $ilObjDataCache->lookupTitle($role_id);
318  switch(substr($title,0,8))
319  {
320  case 'il_crs_m':
321  $member_roles[] = $role_id;
322  $this->role_data[IL_CRS_MEMBER] = $role_id;
323  if($rbacreview->isAssigned($this->getUserId(),$role_id))
324  {
325  $this->participants = true;
326  $this->members = true;
327  }
328  break;
329 
330  case 'il_crs_a':
331  $this->role_data[IL_CRS_ADMIN] = $role_id;
332  if($rbacreview->isAssigned($this->getUserId(),$role_id))
333  {
334  $this->participants = true;
335  $this->admins = true;
336  }
337  break;
338 
339  case 'il_crs_t':
340  $this->role_data[IL_CRS_TUTOR] = $role_id;
341  if($rbacreview->isAssigned($this->getUserId(),$role_id))
342  {
343  $this->participants = true;
344  $this->tutors = true;
345  }
346  break;
347 
348  case 'il_grp_a':
349  $this->role_data[IL_GRP_ADMIN] = $role_id;
350  if($rbacreview->isAssigned($this->getUserId(),$role_id))
351  {
352  $this->participants = true;
353  $this->admins = true;
354  }
355  break;
356 
357  case 'il_grp_m':
358  $member_roles[] = $role_id;
359  $this->role_data[IL_GRP_MEMBER] = $role_id;
360  if($rbacreview->isAssigned($this->getUserId(),$role_id))
361  {
362  $this->participants = true;
363  $this->members = true;
364  }
365  break;
366 
367  default:
368 
369  $member_roles[] = $role_id;
370  if($rbacreview->isAssigned($this->getUserId(),$role_id))
371  {
372  $this->participants = true;
373  $this->members = true;
374  }
375  break;
376  }
377  }
378  $this->numMembers = $rbacreview->getNumberOfAssignedUsers((array) $member_roles);
379  }
380 
385  protected function readParticipantStatus()
386  {
387  global $ilDB;
388 
389  $query = "SELECT * FROM obj_members ".
390  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
391  'AND usr_id = '.$ilDB->quote($this->getUserId(),'integer');
392 
393  $res = $ilDB->query($query);
394  $this->participants_status = array();
395  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
396  {
397  $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
398  $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
399  $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
400  // cognos-blu-patch: begin
401  $this->participants_status[$this->getUserId()]['contact'] = $row->contact;
402  // cognos-blu-patch: end
403  }
404  }
405 
416  public function add($a_usr_id,$a_role)
417  {
418  global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
419 
420 
421  if($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id,$this->roles))
422  {
423  return false;
424  }
425 
426  switch($a_role)
427  {
428  case IL_CRS_ADMIN:
429  $this->admins = true;
430  break;
431 
432  case IL_CRS_TUTOR:
433  $this->tutors = true;
434  break;
435 
436  case IL_CRS_MEMBER:
437  $this->members = true;
438  break;
439 
440  case IL_GRP_ADMIN:
441  $this->admins = true;
442  break;
443 
444  case IL_GRP_MEMBER:
445  $this->members = true;
446  break;
447  }
448 
449  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
450  $this->addDesktopItem($a_usr_id);
451 
452  // Delete subscription request
453  $this->deleteSubscriber($a_usr_id);
454 
455  include_once './Services/Membership/classes/class.ilWaitingList.php';
456  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
457 
458  $ilLog->write(__METHOD__.': Raise new event: '.$this->getComponent().' addParticipant');
459  $ilAppEventHandler->raise(
460  $this->getComponent(),
461  "addParticipant",
462  array(
463  'obj_id' => $this->obj_id,
464  'usr_id' => $a_usr_id,
465  'role_id' => $a_role)
466  );
467  return true;
468  }
469 
477  public function delete($a_usr_id)
478  {
479  global $rbacadmin,$ilDB, $ilAppEventHandler;
480 
481  $this->dropDesktopItem($a_usr_id);
482  foreach($this->roles as $role_id)
483  {
484  $rbacadmin->deassignUser($role_id,$a_usr_id);
485  }
486 
487  $query = "DELETE FROM obj_members ".
488  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
489  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
490  $res = $ilDB->manipulate($query);
491 
492  $ilAppEventHandler->raise(
493  $this->getComponent(),
494  "deleteParticipant",
495  array(
496  'obj_id' => $this->obj_id,
497  'usr_id' => $a_usr_id)
498  );
499  return true;
500  }
501 
507  public function deleteSubscriber($a_usr_id)
508  {
509  global $ilDB;
510 
511  $query = "DELETE FROM il_subscribers ".
512  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
513  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
514  $res = $ilDB->manipulate($query);
515 
516  return true;
517  }
518 
526  public function addDesktopItem($a_usr_id)
527  {
528  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
529  {
530  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
531  }
532  return true;
533  }
534 
542  function dropDesktopItem($a_usr_id)
543  {
544  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
545  {
546  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
547  }
548 
549  return true;
550  }
551 
552  // cognos-blu-patch: begin
560  public function updateContact($a_usr_id, $a_contact)
561  {
562  global $ilDB;
563 
564  $ilDB->manipulate(
565  'UPDATE obj_members SET '.
566  'contact = '.$ilDB->quote($a_contact,'integer').' '.
567  'WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer').' '.
568  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer'));
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 $ilDB;
586 
587  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
588 
589  $query = "SELECT * FROM obj_members ".
590  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
591  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
592  $res = $ilDB->query($query);
593  if($res->numRows())
594  {
595  $query = "UPDATE obj_members SET ".
596  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
597  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
598  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
599  }
600  else
601  {
602  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
603  "VALUES ( ".
604  $ilDB->quote((int) $a_notification ,'integer').", ".
605  $ilDB->quote($this->obj_id ,'integer').", ".
606  $ilDB->quote($a_usr_id ,'integer').", ".
607  $ilDB->quote(0,'integer').", ".
608  $ilDB->quote(0,'integer').
609  ")";
610 
611  }
612  $res = $ilDB->manipulate($query);
613  return true;
614  }
615 
623  public function checkLastAdmin($a_usr_ids)
624  {
625  global $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 
652 
653 }
654 ?>
static updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
Update member roles ilDB $ilDB.
static getMembershipRoleType($a_role_id)
checkLastAdmin($a_usr_ids)
Check if user for deletion are last admins.
const IL_GRP_ADMIN
updateContact($a_usr_id, $a_contact)
ilDB $ilDB
isContact()
Check if user is contact for current object.
readParticipantStatus()
Read participant status ilDB $ilDB.
static _lookupTitle($a_id)
lookup object title
const IL_CRS_TUTOR
deleteSubscriber($a_usr_id)
Delete subsciber.
const IL_GRP_MEMBER
getComponent()
Get component name Used for event handling.
static _getAllReferences($a_id)
get all reference ids of object
const IL_CRS_MEMBER
__construct($a_component_name, $a_obj_id, $a_usr_id)
Singleton Constructor.
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user&#39;s personal desktop
dropDesktopItem($a_usr_id)
Drop desktop item.
const IL_CRS_ADMIN
Base class for course and group participants.
Base class for course and group participant.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
readParticipant()
Read participant.
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
addDesktopItem($a_usr_id)
Add desktop item.
global $lng
Definition: privfeed.php:17
global $ilDB
static deleteUserEntry($a_usr_id, $a_obj_id)
Delete one user entry.
static getLogger($a_component_id)
Get component logger.
add($a_usr_id, $a_role)
Add user to course/group.
getUserId()
get user id
updateNotification($a_usr_id, $a_notification)
Update notification status.
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
static lookupStatusByMembershipRoleType($a_obj_id, $a_usr_id, $a_membership_role_type)
lookup assignment status ilDB $ilDB