ILIAS  Release_4_4_x_branch Revision 61816
 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  {
97  $title = ilObject::_lookupTitle($role);
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  $query = "UPDATE obj_members SET ".
160  "passed = ".$ilDB->quote((int) $a_passed,'integer').", ".
161  "origin = ".$ilDB->quote($origin,'integer').", ".
162  "origin_ts = ".$ilDB->quote(time(),'integer')." ".
163  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
164  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
165  }
166  }
167  else
168  {
169  // when member is added we should not set any date
170  // see ilObjCourse::checkLPStatusSync()
171  if($a_no_origin && !$a_passed)
172  {
173  $origin = 0;
174  $origin_ts = 0;
175  }
176  else
177  {
178  $origin_ts = time();
179  }
180 
181  $query = "INSERT INTO obj_members (passed,obj_id,usr_id,notification,blocked,origin,origin_ts) ".
182  "VALUES ( ".
183  $ilDB->quote((int) $a_passed,'integer').", ".
184  $ilDB->quote($a_obj_id,'integer').", ".
185  $ilDB->quote($a_usr_id,'integer').", ".
186  $ilDB->quote(0,'integer').", ".
187  $ilDB->quote(0,'integer').", ".
188  $ilDB->quote($origin,'integer').", ".
189  $ilDB->quote($origin_ts,'integer').")";
190  }
191  $res = $ilDB->manipulate($query);
192  return true;
193  }
194 
201  function getPassedInfo($a_usr_id)
202  {
203  global $ilDB;
204 
205  $sql = "SELECT origin, origin_ts".
206  " FROM obj_members".
207  " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer").
208  " AND usr_id = ".$ilDB->quote($a_usr_id, "integer");
209  $set = $ilDB->query($sql);
210  $row = $ilDB->fetchAssoc($set);
211  if($row["origin"])
212  {
213  return array("user_id" => $row["origin"],
214  "timestamp" => new ilDateTime($row["origin_ts"], IL_CAL_UNIX));
215  }
216  }
217 
218  // Subscription
219  function sendNotification($a_type, $a_usr_id)
220  {
221  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
222 
223  global $ilObjDataCache,$ilUser;
224 
225  switch($a_type)
226  {
227  case $this->NOTIFY_DISMISS_SUBSCRIBER:
230  $mail->setRefId($this->ref_id);
231  $mail->setRecipients(array($a_usr_id));
232  $mail->send();
233  break;
234 
235  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
238  $mail->setRefId($this->ref_id);
239  $mail->setRecipients(array($a_usr_id));
240  $mail->send();
241  break;
242 
243  case $this->NOTIFY_DISMISS_MEMBER:
246  $mail->setRefId($this->ref_id);
247  $mail->setRecipients(array($a_usr_id));
248  $mail->send();
249  break;
250 
251  case $this->NOTIFY_BLOCK_MEMBER:
254  $mail->setRefId($this->ref_id);
255  $mail->setRecipients(array($a_usr_id));
256  $mail->send();
257  break;
258 
259  case $this->NOTIFY_UNBLOCK_MEMBER:
262  $mail->setRefId($this->ref_id);
263  $mail->setRecipients(array($a_usr_id));
264  $mail->send();
265  break;
266 
267  case $this->NOTIFY_ACCEPT_USER:
270  $mail->setRefId($this->ref_id);
271  $mail->setRecipients(array($a_usr_id));
272  $mail->send();
273  break;
274 
275  case $this->NOTIFY_STATUS_CHANGED:
278  $mail->setRefId($this->ref_id);
279  $mail->setRecipients(array($a_usr_id));
280  $mail->send();
281  break;
282 
283  case $this->NOTIFY_UNSUBSCRIBE:
286  $mail->setRefId($this->ref_id);
287  $mail->setRecipients(array($a_usr_id));
288  $mail->send();
289  break;
290 
291  case $this->NOTIFY_REGISTERED:
294  $mail->setRefId($this->ref_id);
295  $mail->setRecipients(array($a_usr_id));
296  $mail->send();
297  break;
298 
299  case $this->NOTIFY_WAITING_LIST:
300  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
301  $wl = new ilCourseWaitingList($this->obj_id);
302  $pos = $wl->getPosition($a_usr_id);
303 
306  $mail->setRefId($this->ref_id);
307  $mail->setRecipients(array($a_usr_id));
308  $mail->setAdditionalInformation(array('position' => $pos));
309  $mail->send();
310  break;
311 
312  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
313  $this->sendSubscriptionRequestToAdmins($a_usr_id);
314  break;
315 
316  case $this->NOTIFY_ADMINS:
317  $this->sendNotificationToAdmins($a_usr_id);
318  return true;
319  break;
320  }
321  return true;
322  }
323 
325  {
326  global $ilDB,$ilObjDataCache;
327 
328  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
331  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
332  $mail->setRefId($this->ref_id);
333  $mail->setRecipients($this->getNotificationRecipients());
334  $mail->send();
335  return true;
336  }
337 
338 
339  public function sendSubscriptionRequestToAdmins($a_usr_id)
340  {
341  global $ilDB,$ilObjDataCache;
342 
343  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
346  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
347  $mail->setRefId($this->ref_id);
348  $mail->setRecipients($this->getNotificationRecipients());
349  $mail->send();
350  return true;
351  }
352 
353 
354  public function sendNotificationToAdmins($a_usr_id)
355  {
356  global $ilDB,$ilObjDataCache;
357 
358  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
361  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
362  $mail->setRefId($this->ref_id);
363  $mail->setRecipients($this->getNotificationRecipients());
364  $mail->send();
365  return true;
366  }
367 
368 
369  function __buildStatusBody(&$user_obj)
370  {
371  global $ilDB;
372 
373  $body = $this->lng->txt('crs_status_changed_body')."\n";
374  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
375  $body .= $this->lng->txt('role').': ';
376 
377  if($this->isAdmin($user_obj->getId()))
378  {
379  $body .= $this->lng->txt('crs_admin')."\n";
380  }
381  if($this->isTutor($user_obj->getId()))
382  {
383  $body .= $this->lng->txt('crs_tutor')."\n";
384  }
385  if($this->isMember($user_obj->getId()))
386  {
387  $body .= $this->lng->txt('crs_member')."\n";
388  }
389  $body .= $this->lng->txt('status').': ';
390 
391  if($this->isNotificationEnabled($user_obj->getId()))
392  {
393  $body .= $this->lng->txt("crs_notify")."\n";
394  }
395  else
396  {
397  $body .= $this->lng->txt("crs_no_notify")."\n";
398  }
399  if($this->isBlocked($user_obj->getId()))
400  {
401  $body .= $this->lng->txt("crs_blocked")."\n";
402  }
403  else
404  {
405  $body .= $this->lng->txt("crs_unblocked")."\n";
406  }
407  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
408  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
409 
410  return $body;
411  }
412 
413  public static function getDateTimeOfPassed($a_obj_id, $a_usr_id)
414  {
415  global $ilDB;
416 
417  $sql = "SELECT origin_ts FROM obj_members".
418  " WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer").
419  " AND obj_id = ".$ilDB->quote($a_obj_id, "integer").
420  " AND passed = ".$ilDB->quote(1, "integer");
421  $res = $ilDB->query($sql);
422  $res = $ilDB->fetchAssoc($res);
423  if($res["origin_ts"])
424  {
425  return date("Y-m-d H:i:s", $res["origin_ts"]);
426  }
427  }
428 
429  public static function getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
430  {
431  global $ilDB;
432 
433  $res = array();
434 
435  $sql = "SELECT usr_id,obj_id FROM obj_members".
436  " WHERE ".$ilDB->in("usr_id", $a_usr_ids, "", "integer").
437  " AND ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
438  " AND passed = ".$ilDB->quote(1, "integer");
439  $set = $ilDB->query($sql);
440  while($row = $ilDB->fetchAssoc($set))
441  {
442  $res[] = $row;
443  }
444 
445  return $res;
446  }
447 }
448 
449 ?>