ILIAS  Release_5_0_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 $component = '';
42 
43  private $participants = false;
44  private $admins = false;
45  private $tutors = false;
46  private $members = false;
47 
48  private $numMembers = 0;
49 
50  private $participants_status = array();
51 
58  protected function __construct($a_component_name, $a_obj_id, $a_usr_id)
59  {
60  global $ilDB,$lng;
61 
62  $this->obj_id = $a_obj_id;
63  $this->usr_id = $a_usr_id;
64  $this->type = ilObject::_lookupType($a_obj_id);
65  $ref_ids = ilObject::_getAllReferences($this->obj_id);
66  $this->ref_id = current($ref_ids);
67 
68  $this->component = $a_component_name;
69 
70  $this->readParticipant();
71  $this->readParticipantStatus();
72  }
73 
79  protected function getComponent()
80  {
81  return $this->component;
82  }
83 
88  public function getUserId()
89  {
90  return $this->usr_id;
91  }
92 
93  public function isBlocked()
94  {
95  return (bool) $this->participants_status[$this->getUserId()]['blocked'];
96  }
97 
98  public function isAssigned()
99  {
100  return (bool) $this->participants;
101  }
102 
103  public function isMember()
104  {
105  return (bool) $this->members;
106  }
107 
108  public function isAdmin()
109  {
110  return $this->admins;
111  }
112 
113  public function isTutor()
114  {
115  return (bool) $this->tutors;
116  }
117 
118  public function isParticipant()
119  {
120  return (bool) $this->participants;
121  }
122 
123  public function getNumberOfMembers()
124  {
125  return $this->numMembers;
126  }
127 
128 
133  protected function readParticipant()
134  {
135  global $rbacreview,$ilObjDataCache,$ilLog;
136 
137  $this->roles = $rbacreview->getRolesOfRoleFolder($this->ref_id,false);
138 
139  $users = array();
140  $this->participants = array();
141  $this->members = $this->admins = $this->tutors = array();
142 
143  $member_roles = array();
144 
145  foreach($this->roles as $role_id)
146  {
147  $title = $ilObjDataCache->lookupTitle($role_id);
148  switch(substr($title,0,8))
149  {
150  case 'il_crs_m':
151  $member_roles[] = $role_id;
152  $this->role_data[IL_CRS_MEMBER] = $role_id;
153  if($rbacreview->isAssigned($this->getUserId(),$role_id))
154  {
155  $this->participants = true;
156  $this->members = true;
157  }
158  break;
159 
160  case 'il_crs_a':
161  $this->role_data[IL_CRS_ADMIN] = $role_id;
162  if($rbacreview->isAssigned($this->getUserId(),$role_id))
163  {
164  $this->participants = true;
165  $this->admins = true;
166  }
167  break;
168 
169  case 'il_crs_t':
170  $this->role_data[IL_CRS_TUTOR] = $role_id;
171  if($rbacreview->isAssigned($this->getUserId(),$role_id))
172  {
173  $this->participants = true;
174  $this->tutors = true;
175  }
176  break;
177 
178  case 'il_grp_a':
179  $this->role_data[IL_GRP_ADMIN] = $role_id;
180  if($rbacreview->isAssigned($this->getUserId(),$role_id))
181  {
182  $this->participants = true;
183  $this->admins = true;
184  }
185  break;
186 
187  case 'il_grp_m':
188  $member_roles[] = $role_id;
189  $this->role_data[IL_GRP_MEMBER] = $role_id;
190  if($rbacreview->isAssigned($this->getUserId(),$role_id))
191  {
192  $this->participants = true;
193  $this->members = true;
194  }
195  break;
196 
197  default:
198 
199  $member_roles[] = $role_id;
200  if($rbacreview->isAssigned($this->getUserId(),$role_id))
201  {
202  $this->participants = true;
203  $this->members = true;
204  }
205  break;
206  }
207  }
208  $this->numMembers = $rbacreview->getNumberOfAssignedUsers((array) $member_roles);
209  }
210 
215  protected function readParticipantStatus()
216  {
217  global $ilDB;
218 
219  $query = "SELECT * FROM obj_members ".
220  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
221  'AND usr_id = '.$ilDB->quote($this->getUserId(),'integer');
222 
223  $res = $ilDB->query($query);
224  $this->participants_status = array();
225  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
226  {
227  $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
228  $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
229  $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
230  }
231  }
232 
243  public function add($a_usr_id,$a_role)
244  {
245  global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
246 
247 
248  if($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id,$this->roles))
249  {
250  return false;
251  }
252 
253  switch($a_role)
254  {
255  case IL_CRS_ADMIN:
256  $this->admins = true;
257  break;
258 
259  case IL_CRS_TUTOR:
260  $this->tutors = true;
261  break;
262 
263  case IL_CRS_MEMBER:
264  $this->members = true;
265  break;
266 
267  case IL_GRP_ADMIN:
268  $this->admins = true;
269  break;
270 
271  case IL_GRP_MEMBER:
272  $this->members = true;
273  break;
274  }
275 
276  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
277  $this->addDesktopItem($a_usr_id);
278 
279  // Delete subscription request
280  $this->deleteSubscriber($a_usr_id);
281 
282  include_once './Services/Membership/classes/class.ilWaitingList.php';
283  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
284 
285  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
286  $ilAppEventHandler->raise(
287  $this->getComponent(),
288  "addParticipant",
289  array(
290  'obj_id' => $this->obj_id,
291  'usr_id' => $a_usr_id,
292  'role_id' => $a_role)
293  );
294  return true;
295  }
296 
304  public function delete($a_usr_id)
305  {
306  global $rbacadmin,$ilDB, $ilAppEventHandler;
307 
308  $this->dropDesktopItem($a_usr_id);
309  foreach($this->roles as $role_id)
310  {
311  $rbacadmin->deassignUser($role_id,$a_usr_id);
312  }
313 
314  $query = "DELETE FROM obj_members ".
315  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
316  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
317  $res = $ilDB->manipulate($query);
318 
319  $ilAppEventHandler->raise(
320  "Modules/Course",
321  "deleteParticipant",
322  array(
323  'obj_id' => $this->obj_id,
324  'usr_id' => $a_usr_id)
325  );
326  return true;
327  }
328 
334  public function deleteSubscriber($a_usr_id)
335  {
336  global $ilDB;
337 
338  $query = "DELETE FROM il_subscribers ".
339  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
340  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
341  $res = $ilDB->manipulate($query);
342 
343  return true;
344  }
345 
353  public function addDesktopItem($a_usr_id)
354  {
355  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
356  {
357  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
358  }
359  return true;
360  }
361 
369  function dropDesktopItem($a_usr_id)
370  {
371  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
372  {
373  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
374  }
375 
376  return true;
377  }
378 
387  public function updateNotification($a_usr_id,$a_notification)
388  {
389  global $ilDB;
390 
391  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
392 
393  $query = "SELECT * FROM obj_members ".
394  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
395  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
396  $res = $ilDB->query($query);
397  if($res->numRows())
398  {
399  $query = "UPDATE obj_members SET ".
400  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
401  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
402  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
403  }
404  else
405  {
406  $query = "INSERT INTO obj_members (notification,obj_id,usr_id,passed,blocked) ".
407  "VALUES ( ".
408  $ilDB->quote((int) $a_notification ,'integer').", ".
409  $ilDB->quote($this->obj_id ,'integer').", ".
410  $ilDB->quote($a_usr_id ,'integer').", ".
411  $ilDB->quote(0,'integer').", ".
412  $ilDB->quote(0,'integer').
413  ")";
414 
415  }
416  $res = $ilDB->manipulate($query);
417  return true;
418  }
419 
427  public function checkLastAdmin($a_usr_ids)
428  {
429  global $ilDB;
430 
431  $admin_role_id =
432  $this->type == 'crs' ?
433  $this->role_data[IL_CRS_ADMIN] :
434  $this->role_data[IL_GRP_ADMIN];
435 
436 
437  $query = "
438  SELECT COUNT(rolesusers.usr_id) cnt
439 
440  FROM object_data rdata
441 
442  LEFT JOIN rbac_ua rolesusers
443  ON rolesusers.rol_id = rdata.obj_id
444 
445  WHERE rdata.obj_id = %s
446  ";
447 
448  $query .= ' AND '.$ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
449  $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
450 
451  $data = $ilDB->fetchAssoc($res);
452 
453  return (int)$data['cnt'] > 0;
454  }
455 
456 
457 }
458 ?>