ILIAS  Release_4_2_x_branch Revision 61807
 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  private $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 $participants_status = array();
47 
54  protected function __construct($a_obj_id,$a_usr_id)
55  {
56  global $ilDB,$lng;
57 
58  $this->obj_id = $a_obj_id;
59  $this->usr_id = $a_usr_id;
60  $this->type = ilObject::_lookupType($a_obj_id);
61  $ref_ids = ilObject::_getAllReferences($this->obj_id);
62  $this->ref_id = current($ref_ids);
63 
64  $this->readParticipant();
65  $this->readParticipantStatus();
66  }
67 
72  public function getUserId()
73  {
74  return $this->usr_id;
75  }
76 
77  public function isBlocked()
78  {
79  return (bool) $this->participants_status[$this->getUserId()]['blocked'];
80  }
81 
82  public function isAssigned()
83  {
84  return (bool) $this->participants;
85  }
86 
87  public function isMember()
88  {
89  return (bool) $this->members;
90  }
91 
92  public function isAdmin()
93  {
94  return $this->admins;
95  }
96 
97  public function isTutor()
98  {
99  return (bool) $this->tutors;
100  }
101 
102  public function isParticipant()
103  {
104  return (bool) $this->participants;
105  }
106 
107 
112  protected function readParticipant()
113  {
114  global $rbacreview,$ilObjDataCache,$ilLog;
115 
116  $rolf = $rbacreview->getRoleFolderOfObject($this->ref_id);
117 
118  if(!isset($rolf['ref_id']) or !$rolf['ref_id'])
119  {
120  $title = $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($this->ref_id));
121  #$ilLog->write(__METHOD__.': Found object without role folder. Ref_id: '.$this->ref_id.', title: '.$title);
122  #$ilLog->logStack();
123  return false;
124  }
125 
126  $this->roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
127 
128  $users = array();
129  $this->participants = array();
130  $this->members = $this->admins = $this->tutors = array();
131 
132  foreach($this->roles as $role_id)
133  {
134  $title = $ilObjDataCache->lookupTitle($role_id);
135  switch(substr($title,0,8))
136  {
137  case 'il_crs_m':
138  $this->role_data[IL_CRS_MEMBER] = $role_id;
139  if($rbacreview->isAssigned($this->getUserId(),$role_id))
140  {
141  $this->participants = true;
142  $this->members = true;
143  }
144  break;
145 
146  case 'il_crs_a':
147  $this->role_data[IL_CRS_ADMIN] = $role_id;
148  if($rbacreview->isAssigned($this->getUserId(),$role_id))
149  {
150  $this->participants = true;
151  $this->admins = true;
152  }
153  break;
154 
155  case 'il_crs_t':
156  $this->role_data[IL_CRS_TUTOR] = $role_id;
157  if($rbacreview->isAssigned($this->getUserId(),$role_id))
158  {
159  $this->participants = true;
160  $this->tutors = true;
161  }
162  break;
163 
164  case 'il_grp_a':
165  $this->role_data[IL_GRP_ADMIN] = $role_id;
166  if($rbacreview->isAssigned($this->getUserId(),$role_id))
167  {
168  $this->participants = true;
169  $this->admins = true;
170  }
171  break;
172 
173  case 'il_grp_m':
174  $this->role_data[IL_GRP_MEMBER] = $role_id;
175  if($rbacreview->isAssigned($this->getUserId(),$role_id))
176  {
177  $this->participants = true;
178  $this->members = true;
179  }
180  break;
181 
182  default:
183  if($rbacreview->isAssigned($this->getUserId(),$role_id))
184  {
185  $this->participants = true;
186  $this->members = true;
187  }
188  break;
189  }
190  }
191  }
192 
197  protected function readParticipantStatus()
198  {
199  global $ilDB;
200 
201  $query = "SELECT * FROM crs_members ".
202  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
203  'AND usr_id = '.$ilDB->quote($this->getUserId(),'integer');
204 
205  $res = $ilDB->query($query);
206  $this->participants_status = array();
207  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
208  {
209  $this->participants_status[$this->getUserId()]['blocked'] = $row->blocked;
210  $this->participants_status[$this->getUserId()]['notification'] = $row->notification;
211  $this->participants_status[$this->getUserId()]['passed'] = $row->passed;
212  }
213  }
214 
225  public function add($a_usr_id,$a_role)
226  {
227  global $rbacadmin,$ilLog,$ilAppEventHandler,$rbacreview;
228 
229 
230  if($rbacreview->isAssignedToAtLeastOneGivenRole($a_usr_id,$this->roles))
231  {
232  return false;
233  }
234 
235  switch($a_role)
236  {
237  case IL_CRS_ADMIN:
238  $this->admins = true;
239  break;
240 
241  case IL_CRS_TUTOR:
242  $this->tutors = true;
243  break;
244 
245  case IL_CRS_MEMBER:
246  $this->members = true;
247  break;
248 
249  case IL_GRP_ADMIN:
250  $this->admins = true;
251  break;
252 
253  case IL_GRP_MEMBER:
254  $this->members = true;
255  break;
256  }
257 
258  $rbacadmin->assignUser($this->role_data[$a_role],$a_usr_id);
259  $this->addDesktopItem($a_usr_id);
260 
261  // Delete subscription request
262  $this->deleteSubscriber($a_usr_id);
263 
264  include_once './Services/Membership/classes/class.ilWaitingList.php';
265  ilWaitingList::deleteUserEntry($a_usr_id,$this->obj_id);
266 
267  if($this->type == 'crs')
268  {
269  // Add event: used for ecs accounts
270  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addParticipant');
271  $ilAppEventHandler->raise("Modules/Course", "addParticipant", array('obj_id' => $this->obj_id, 'usr_id' => $a_usr_id,'role_id' => $a_role));
272  }
273  return true;
274  }
275 
283  public function delete($a_usr_id)
284  {
285  global $rbacadmin,$ilDB, $ilAppEventHandler;
286 
287  $this->dropDesktopItem($a_usr_id);
288  foreach($this->roles as $role_id)
289  {
290  $rbacadmin->deassignUser($role_id,$a_usr_id);
291  }
292 
293  $query = "DELETE FROM crs_members ".
294  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
295  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer');
296  $res = $ilDB->manipulate($query);
297 
298  if($this->type == 'crs')
299  {
300  // Add event: used for ecs accounts
301  $ilAppEventHandler->raise("Modules/Course", "deleteParticipant", array('obj_id' => $this->obj_id, 'usr_id' => $a_usr_id));
302  }
303 
304  return true;
305  }
306 
312  public function deleteSubscriber($a_usr_id)
313  {
314  global $ilDB;
315 
316  $query = "DELETE FROM il_subscribers ".
317  "WHERE usr_id = ".$ilDB->quote($a_usr_id ,'integer')." ".
318  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
319  $res = $ilDB->manipulate($query);
320 
321  return true;
322  }
323 
331  public function addDesktopItem($a_usr_id)
332  {
333  if(!ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
334  {
335  ilObjUser::_addDesktopItem($a_usr_id, $this->ref_id,$this->type);
336  }
337  return true;
338  }
339 
347  function dropDesktopItem($a_usr_id)
348  {
349  if(ilObjUser::_isDesktopItem($a_usr_id, $this->ref_id,$this->type))
350  {
351  ilObjUser::_dropDesktopItem($a_usr_id, $this->ref_id,$this->type);
352  }
353 
354  return true;
355  }
356 
365  public function updateNotification($a_usr_id,$a_notification)
366  {
367  global $ilDB;
368 
369  $this->participants_status[$a_usr_id]['notification'] = (int) $a_notification;
370 
371  $query = "SELECT * FROM crs_members ".
372  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
373  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
374  $res = $ilDB->query($query);
375  if($res->numRows())
376  {
377  $query = "UPDATE crs_members SET ".
378  "notification = ".$ilDB->quote((int) $a_notification ,'integer')." ".
379  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
380  "AND usr_id = ".$ilDB->quote($a_usr_id ,'integer');
381  }
382  else
383  {
384  $query = "INSERT INTO crs_members (notification,obj_id,usr_id,passed,blocked) ".
385  "VALUES ( ".
386  $ilDB->quote((int) $a_notification ,'integer').", ".
387  $ilDB->quote($this->obj_id ,'integer').", ".
388  $ilDB->quote($a_usr_id ,'integer').", ".
389  $ilDB->quote(0,'integer').", ".
390  $ilDB->quote(0,'integer').
391  ")";
392 
393  }
394  $res = $ilDB->manipulate($query);
395  return true;
396  }
397 
405  public function checkLastAdmin($a_usr_ids)
406  {
407  global $ilDB;
408 
409  $admin_role_id =
410  $this->type == 'crs' ?
411  $this->role_data[IL_CRS_ADMIN] :
412  $this->role_data[IL_GRP_ADMIN];
413 
414 
415  $query = "
416  SELECT COUNT(rolesusers.usr_id) cnt
417 
418  FROM object_data rdata
419 
420  LEFT JOIN rbac_ua rolesusers
421  ON rolesusers.rol_id = rdata.obj_id
422 
423  WHERE rdata.obj_id = %s
424  ";
425 
426  $query .= ' AND '.$ilDB->in('rolesusers.usr_id', $a_usr_ids, true, 'integer');
427  $res = $ilDB->queryF($query, array('integer'), array($admin_role_id));
428 
429  $data = $ilDB->fetchAssoc($res);
430 
431  return (int)$data['cnt'] > 0;
432  }
433 
434 
435 }
436 ?>