ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseParticipants.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 include_once('./Services/Membership/classes/class.ilParticipants.php');
25 
36 {
37  protected static $instances = array();
38 
45  public function __construct($a_obj_id)
46  {
47  $this->type = 'crs';
48 
49  $this->NOTIFY_DISMISS_SUBSCRIBER = 1;
50  $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
51  $this->NOTIFY_DISMISS_MEMBER = 3;
52  $this->NOTIFY_BLOCK_MEMBER = 4;
53  $this->NOTIFY_UNBLOCK_MEMBER = 5;
54  $this->NOTIFY_ACCEPT_USER = 6;
55  $this->NOTIFY_ADMINS = 7;
56  $this->NOTIFY_STATUS_CHANGED = 8;
57  $this->NOTIFY_SUBSCRIPTION_REQUEST = 9;
58 
59  $this->NOTIFY_REGISTERED = 10;
60  $this->NOTIFY_UNSUBSCRIBE = 11;
61  $this->NOTIFY_WAITING_LIST = 12;
62 
63  parent::__construct($a_obj_id);
64  }
65 
74  public static function _getInstanceByObjId($a_obj_id)
75  {
76  if(isset(self::$instances[$a_obj_id]) and self::$instances[$a_obj_id])
77  {
78  return self::$instances[$a_obj_id];
79  }
80  return self::$instances[$a_obj_id] = new ilCourseParticipants($a_obj_id);
81  }
82 
87  public static function getMemberRoles($a_ref_id)
88  {
89  global $rbacreview;
90 
91  $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
92  $lrol = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
93 
94  $roles = array();
95  foreach($lrol as $role)
96  {
98  switch(substr($title,0,8))
99  {
100  case 'il_crs_a':
101  case 'il_crs_t':
102  case 'il_crs_m':
103  continue;
104 
105  default:
106  $roles[$role] = $role;
107  }
108  }
109  return $roles;
110  }
111 
121  public function updatePassed($a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
122  {
123  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
124 
125  return self::_updatePassed($this->obj_id, $a_usr_id, $a_passed, $a_manual, $a_no_origin);
126  }
127 
138  public static function _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
139  {
140  global $ilDB, $ilUser;
141 
142  // #11600
143  $origin = -1;
144  if($a_manual)
145  {
146  $origin = $ilUser->getId();
147  }
148 
149  $query = "SELECT passed FROM obj_members ".
150  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
151  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
152  $res = $ilDB->query($query);
153  if($res->numRows())
154  {
155  // #9284 - only needs updating when status has changed
156  $old = $ilDB->fetchAssoc($res);
157  if((int)$old["passed"] != (int)$a_passed)
158  {
159 
160  $query = "UPDATE obj_members SET ".
161  "passed = ".$ilDB->quote((int) $a_passed,'integer').", ".
162  "origin = ".$ilDB->quote($origin,'integer').", ".
163  "origin_ts = ".$ilDB->quote(time(),'integer')." ".
164  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
165  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
166  }
167  }
168  else
169  {
170  // when member is added we should not set any date
171  // see ilObjCourse::checkLPStatusSync()
172  if($a_no_origin && !$a_passed)
173  {
174  $origin = 0;
175  $origin_ts = 0;
176  }
177  else
178  {
179  $origin_ts = time();
180  }
181 
182  $query = "INSERT INTO obj_members (passed,obj_id,usr_id,notification,blocked,origin,origin_ts) ".
183  "VALUES ( ".
184  $ilDB->quote((int) $a_passed,'integer').", ".
185  $ilDB->quote($a_obj_id,'integer').", ".
186  $ilDB->quote($a_usr_id,'integer').", ".
187  $ilDB->quote(0,'integer').", ".
188  $ilDB->quote(0,'integer').", ".
189  $ilDB->quote($origin,'integer').", ".
190  $ilDB->quote($origin_ts,'integer').")";
191  }
192  $res = $ilDB->manipulate($query);
193  return true;
194  }
195 
202  function getPassedInfo($a_usr_id)
203  {
204  global $ilDB;
205 
206  $sql = "SELECT origin, origin_ts".
207  " FROM obj_members".
208  " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer").
209  " AND usr_id = ".$ilDB->quote($a_usr_id, "integer");
210  $set = $ilDB->query($sql);
211  $row = $ilDB->fetchAssoc($set);
212  if($row["origin"])
213  {
214  return array("user_id" => $row["origin"],
215  "timestamp" => new ilDateTime($row["origin_ts"], IL_CAL_UNIX));
216  }
217  }
218 
219  // Subscription
220  function sendNotification($a_type, $a_usr_id)
221  {
222  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
223 
224  global $ilObjDataCache,$ilUser;
225 
226  switch($a_type)
227  {
228  case $this->NOTIFY_DISMISS_SUBSCRIBER:
231  $mail->setRefId($this->ref_id);
232  $mail->setRecipients(array($a_usr_id));
233  $mail->send();
234  break;
235 
236  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
239  $mail->setRefId($this->ref_id);
240  $mail->setRecipients(array($a_usr_id));
241  $mail->send();
242  break;
243 
244  case $this->NOTIFY_DISMISS_MEMBER:
247  $mail->setRefId($this->ref_id);
248  $mail->setRecipients(array($a_usr_id));
249  $mail->send();
250  break;
251 
252  case $this->NOTIFY_BLOCK_MEMBER:
255  $mail->setRefId($this->ref_id);
256  $mail->setRecipients(array($a_usr_id));
257  $mail->send();
258  break;
259 
260  case $this->NOTIFY_UNBLOCK_MEMBER:
263  $mail->setRefId($this->ref_id);
264  $mail->setRecipients(array($a_usr_id));
265  $mail->send();
266  break;
267 
268  case $this->NOTIFY_ACCEPT_USER:
271  $mail->setRefId($this->ref_id);
272  $mail->setRecipients(array($a_usr_id));
273  $mail->send();
274  break;
275 
276  case $this->NOTIFY_STATUS_CHANGED:
279  $mail->setRefId($this->ref_id);
280  $mail->setRecipients(array($a_usr_id));
281  $mail->send();
282  break;
283 
284  case $this->NOTIFY_UNSUBSCRIBE:
287  $mail->setRefId($this->ref_id);
288  $mail->setRecipients(array($a_usr_id));
289  $mail->send();
290  break;
291 
292  case $this->NOTIFY_REGISTERED:
295  $mail->setRefId($this->ref_id);
296  $mail->setRecipients(array($a_usr_id));
297  $mail->send();
298  break;
299 
300  case $this->NOTIFY_WAITING_LIST:
301  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
302  $wl = new ilCourseWaitingList($this->obj_id);
303  $pos = $wl->getPosition($a_usr_id);
304 
307  $mail->setRefId($this->ref_id);
308  $mail->setRecipients(array($a_usr_id));
309  $mail->setAdditionalInformation(array('position' => $pos));
310  $mail->send();
311  break;
312 
313  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
314  $this->sendSubscriptionRequestToAdmins($a_usr_id);
315  break;
316 
317  case $this->NOTIFY_ADMINS:
318  $this->sendNotificationToAdmins($a_usr_id);
319  return true;
320  break;
321  }
322  return true;
323  }
324 
326  {
327  global $ilDB,$ilObjDataCache;
328 
329  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
332  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
333  $mail->setRefId($this->ref_id);
334  $mail->setRecipients($this->getNotificationRecipients());
335  $mail->send();
336  return true;
337  }
338 
339 
340  public function sendSubscriptionRequestToAdmins($a_usr_id)
341  {
342  global $ilDB,$ilObjDataCache;
343 
344  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
347  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
348  $mail->setRefId($this->ref_id);
349  $mail->setRecipients($this->getNotificationRecipients());
350  $mail->send();
351  return true;
352  }
353 
354 
355  public function sendNotificationToAdmins($a_usr_id)
356  {
357  global $ilDB,$ilObjDataCache;
358 
359  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
362  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
363  $mail->setRefId($this->ref_id);
364  $mail->setRecipients($this->getNotificationRecipients());
365  $mail->send();
366  return true;
367  }
368 
369 
370  function __buildStatusBody(&$user_obj)
371  {
372  global $ilDB;
373 
374  $body = $this->lng->txt('crs_status_changed_body')."\n";
375  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
376  $body .= $this->lng->txt('role').': ';
377 
378  if($this->isAdmin($user_obj->getId()))
379  {
380  $body .= $this->lng->txt('crs_admin')."\n";
381  }
382  if($this->isTutor($user_obj->getId()))
383  {
384  $body .= $this->lng->txt('crs_tutor')."\n";
385  }
386  if($this->isMember($user_obj->getId()))
387  {
388  $body .= $this->lng->txt('crs_member')."\n";
389  }
390  $body .= $this->lng->txt('status').': ';
391 
392  if($this->isNotificationEnabled($user_obj->getId()))
393  {
394  $body .= $this->lng->txt("crs_notify")."\n";
395  }
396  else
397  {
398  $body .= $this->lng->txt("crs_no_notify")."\n";
399  }
400  if($this->isBlocked($user_obj->getId()))
401  {
402  $body .= $this->lng->txt("crs_blocked")."\n";
403  }
404  else
405  {
406  $body .= $this->lng->txt("crs_unblocked")."\n";
407  }
408  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
409  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
410 
411  return $body;
412  }
413 
414  public static function getDateTimeOfPassed($a_obj_id, $a_usr_id)
415  {
416  global $ilDB;
417 
418  $sql = "SELECT origin_ts FROM obj_members".
419  " WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer").
420  " AND obj_id = ".$ilDB->quote($a_obj_id, "integer").
421  " AND passed = ".$ilDB->quote(1, "integer");
422  $res = $ilDB->query($sql);
423  $res = $ilDB->fetchAssoc($res);
424  if($res["origin_ts"])
425  {
426  return date("Y-m-d H:i:s", $res["origin_ts"]);
427  }
428  }
429 
430  public static function getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
431  {
432  global $ilDB;
433 
434  $res = array();
435 
436  $sql = "SELECT usr_id,obj_id FROM obj_members".
437  " WHERE ".$ilDB->in("usr_id", $a_usr_ids, "", "integer").
438  " AND ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
439  " AND passed = ".$ilDB->quote(1, "integer");
440  $set = $ilDB->query($sql);
441  while($row = $ilDB->fetchAssoc($set))
442  {
443  $res[] = $row;
444  }
445 
446  return $res;
447  }
448 }
449 
450 ?>