ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  private $obj_id = 0;
37  private $usr_id = 0;
38  protected $type = '';
39  private $ref_id = 0;
40 
41  private $participants = false;
42  private $admins = false;
43  private $tutors = false;
44  private $members = false;
45 
46  private $numMembers = 0;
47 
48  private $participants_status = array();
49 
56  protected function __construct($a_obj_id,$a_usr_id)
57  {
58  global $ilDB,$lng;
59 
60  $this->obj_id = $a_obj_id;
61  $this->usr_id = $a_usr_id;
62  $this->type = ilObject::_lookupType($a_obj_id);
63  $ref_ids = ilObject::_getAllReferences($this->obj_id);
64  $this->ref_id = current($ref_ids);
65 
66  $this->readParticipant();
67  $this->readParticipantStatus();
68  }
69 
74  public function getUserId()
75  {
76  return $this->usr_id;
77  }
78 
79  public function isBlocked()
80  {
81  return (bool) $this->participants_status[$this->getUserId()]['blocked'];
82  }
83 
84  public function isAssigned()
85  {
86  return (bool) $this->participants;
87  }
88 
89  public function isMember()
90  {
91  return (bool) $this->members;
92  }
93 
94  public function isAdmin()
95  {
96  return $this->admins;
97  }
98 
99  public function isTutor()
100  {
101  return (bool) $this->tutors;
102  }
103 
104  public function isParticipant()
105  {
106  return (bool) $this->participants;
107  }
108 
109  public function getNumberOfMembers()
110  {
111  return $this->numMembers;
112  }
113 
114 
119  protected function readParticipant()
120  {
121  global $rbacreview,$ilObjDataCache,$ilLog;
122 
123  $rolf = $rbacreview->getRoleFolderOfObject($this->ref_id);
124 
125  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
126  {
127  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->ref_id));
128  #$ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$this->ref_id.', title: '.$title);
129  #$ilLog->logStack();
130  return false;
131  }
132 
133  $this->roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
134 
135  $users = array();
136  $this->participants = array();
137  $this->members = $this->admins = $this->tutors = array();
138 
139  $member_roles = array();
140 
141  foreach($this->roles as $role_id)
142  {
143  $title = $ilObjDataCache->lookupTitle($role_id);
144  switch(substr($title,0,8))
145  {
146  case 'il_crs_m':
147  $member_roles[] = $role_id;
148  $this->role_data[IL_CRS_MEMBER] = $role_id;
149  if($rbacreview->isAssigned($this->getUserId(),$role_id))
150  {
151  $this->participants = true;
152  $this->members = true;
153  }
154  break;
155 
156  case 'il_crs_a':
157  $this->role_data[IL_CRS_ADMIN] = $role_id;
158  if($rbacreview->isAssigned($this->getUserId(),$role_id))
159  {
160  $this->participants = true;
161  $this->admins = true;
162  }
163  break;
164 
165  case 'il_crs_t':
166  $this->role_data[IL_CRS_TUTOR] = $role_id;
167  if($rbacreview->isAssigned($this->getUserId(),$role_id))
168  {
169  $this->participants = true;
170  $this->tutors = true;
171  }
172  break;
173 
174  case 'il_grp_a':
175  $this->role_data[IL_GRP_ADMIN] = $role_id;
176  if($rbacreview->isAssigned($this->getUserId(),$role_id))
177  {
178  $this->participants = true;
179  $this->admins = true;
180  }
181  break;
182 
183  case 'il_grp_m':
184  $member_roles[] = $role_id;
185  $this->role_data[IL_GRP_MEMBER] = $role_id;
186  if($rbacreview->isAssigned($this->getUserId(),$role_id))
187  {
188  $this->participants = true;
189  $this->members = true;
190  }
191  break;
192 
193  default:
194 
195  $member_roles[] = $role_id;
196  if($rbacreview->isAssigned($this->getUserId(),$role_id))
197  {
198  $this->participants = true;
199  $this->members = true;
200  }
201  break;
202  }
203  }
204  $this->numMembers = $rbacreview->getNumberOfAssignedUsers((array) $member_roles);
205  }
206 
211  protected function readParticipantStatus()
212  {
213  global $ilDB;
214 
215  $query = "SELECT * FROM obj_members ".
216  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
217  'AND usr_id = '.$ilDB->quote($this->getUserId(),'integer');
218 
219  $res = $ilDB->query($query);
220  $this->participants_status = array();
221  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
222  {
223  $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
224  $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
225  $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
226  }
227  }
228 
239  public function add($a_usr_id,$a_role)
240  {
241  global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
242 
243 
244  if($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id,$this->roles))
245  {
246  return false;
247  }
248 
249  switch($a_role)
250  {
251  case IL_CRS_ADMIN:
252  $this->admins = true;
253  break;
254 
255  case IL_CRS_TUTOR:
256  $this->tutors = true;
257  break;
258 
259  case IL_CRS_MEMBER:
260  $this->members = true;
261  break;
262 
263  case IL_GRP_ADMIN:
264  $this->admins = true;
265  break;
266 
267  case IL_GRP_MEMBER:
268  $this->members = true;
269  break;
270  }
271 
272  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
273  $this->addDesktopItem($a_usr_id);
274 
275  // Delete subscription request
276  $this->deleteSubscriber($a_usr_id);
277 
278  include_once './Services/Membership/classes/class.ilWaitingList.php';
279  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
280 
281  if($this->type == 'crs')
282  {
283  // Add event: used for ecs accounts
284  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
285  $ilAppEventHandler->raise("Modules/Course", "addParticipant", array('obj_id' => $this->obj_id, 'usr_id' => $a_usr_id,'role_id' => $a_role));
286  }
287  return true;
288  }
289 
297  public function delete($a_usr_id)
298  {
299  global $rbacadmin,$ilDB, $ilAppEventHandler;
300 
301  $this->dropDesktopItem($a_usr_id);
302  foreach($this->roles as $role_id)
303  {
304  $rbacadmin->deassignUser($role_id,$a_usr_id);
305  }
306 
307  $query = "DELETE FROM obj_members ".
308  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
309  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
310  $res = $ilDB->manipulate($query);
311 
312  if($this->type == 'crs')
313  {
314  // Add event: used for ecs accounts
315  $ilAppEventHandler->raise("Modules/Course", "deleteParticipant", array('obj_id' => $this->obj_id, 'usr_id' => $a_usr_id));
316  }
317 
318  return true;
319  }
320 
326  public function deleteSubscriber($a_usr_id)
327  {
328  global $ilDB;
329 
330  $query = "DELETE FROM il_subscribers ".
331  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
332  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
333  $res = $ilDB->manipulate($query);
334 
335  return true;
336  }
337 
345  public function addDesktopItem($a_usr_id)
346  {
347  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
348  {
349  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
350  }
351  return true;
352  }
353 
361  function dropDesktopItem($a_usr_id)
362  {
363  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
364  {
365  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
366  }
367 
368  return true;
369  }
370 
379  public function updateNotification($a_usr_id,$a_notification)
380  {
381  global $ilDB;
382 
383  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
384 
385  $query = "SELECT * FROM obj_members ".
386  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
387  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
388  $res = $ilDB->query($query);
389  if($res->numRows())
390  {
391  $query = "UPDATE obj_members SET ".
392  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
393  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
394  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
395  }
396  else
397  {
398  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
399  "VALUES ( ".
400  $ilDB->quote((int) $a_notification ,'integer').", ".
401  $ilDB->quote($this->obj_id ,'integer').", ".
402  $ilDB->quote($a_usr_id ,'integer').", ".
403  $ilDB->quote(0,'integer').", ".
404  $ilDB->quote(0,'integer').
405  ")";
406 
407  }
408  $res = $ilDB->manipulate($query);
409  return true;
410  }
411 
419  public function checkLastAdmin($a_usr_ids)
420  {
421  global $ilDB;
422 
423  $admin_role_id =
424  $this->type == 'crs' ?
425  $this->role_data[IL_CRS_ADMIN] :
426  $this->role_data[IL_GRP_ADMIN];
427 
428 
429  $query = "
430  SELECT COUNT(rolesusers.usr_id) cnt
431 
432  FROM object_data rdata
433 
434  LEFT JOIN rbac_ua rolesusers
435  ON rolesusers.rol_id = rdata.obj_id
436 
437  WHERE rdata.obj_id = %s
438  ";
439 
440  $query .= ' AND '.$ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
441  $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
442 
443  $data = $ilDB->fetchAssoc($res);
444 
445  return (int)$data['cnt'] > 0;
446  }
447 
448 
449 }
450 ?>