ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  const COMPONENT_NAME = 'Modules/Course';
38 
39  protected static $instances = array();
40 
41 
48  public function __construct($a_obj_id)
49  {
50  $this->type = 'crs';
51 
52  $this->NOTIFY_DISMISS_SUBSCRIBER = 1;
53  $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
54  $this->NOTIFY_DISMISS_MEMBER = 3;
55  $this->NOTIFY_BLOCK_MEMBER = 4;
56  $this->NOTIFY_UNBLOCK_MEMBER = 5;
57  $this->NOTIFY_ACCEPT_USER = 6;
58  $this->NOTIFY_ADMINS = 7;
59  $this->NOTIFY_STATUS_CHANGED = 8;
60  $this->NOTIFY_SUBSCRIPTION_REQUEST = 9;
61 
62  $this->NOTIFY_REGISTERED = 10;
63  $this->NOTIFY_UNSUBSCRIBE = 11;
64  $this->NOTIFY_WAITING_LIST = 12;
65 
66  parent::__construct(self::COMPONENT_NAME,$a_obj_id);
67  }
68 
77  public static function _getInstanceByObjId($a_obj_id)
78  {
79  if(isset(self::$instances[$a_obj_id]) and self::$instances[$a_obj_id])
80  {
81  return self::$instances[$a_obj_id];
82  }
83  return self::$instances[$a_obj_id] = new ilCourseParticipants($a_obj_id);
84  }
85 
90  public static function getMemberRoles($a_ref_id)
91  {
92  global $rbacreview;
93 
94  $lrol = $rbacreview->getRolesOfRoleFolder($a_ref_id,false);
95 
96  $roles = array();
97  foreach($lrol as $role)
98  {
100  switch(substr($title,0,8))
101  {
102  case 'il_crs_a':
103  case 'il_crs_t':
104  case 'il_crs_m':
105  continue;
106 
107  default:
108  $roles[$role] = $role;
109  }
110  }
111  return $roles;
112  }
113 
114  public function addSubscriber($a_usr_id)
115  {
116  global $ilAppEventHandler, $ilLog;
117 
118  parent::addSubscriber($a_usr_id);
119 
120  $ilLog->write(__METHOD__.': Raise new event: Modules/Course addSubscriber');
121  $ilAppEventHandler->raise(
122  "Modules/Course",
123  'addSubscriber',
124  array(
125  'obj_id' => $this->getObjId(),
126  'usr_id' => $a_usr_id
127  )
128  );
129  }
130 
140  public function updatePassed($a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
141  {
142  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
143 
144  return self::_updatePassed($this->obj_id, $a_usr_id, $a_passed, $a_manual, $a_no_origin);
145  }
146 
157  public static function _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
158  {
159  global $ilDB, $ilUser;
160 
161  // #11600
162  $origin = -1;
163  if($a_manual)
164  {
165  $origin = $ilUser->getId();
166  }
167 
168  $query = "SELECT passed FROM obj_members ".
169  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
170  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
171  $res = $ilDB->query($query);
172  if($res->numRows())
173  {
174  // #9284 - only needs updating when status has changed
175  $old = $ilDB->fetchAssoc($res);
176  if((int)$old["passed"] != (int)$a_passed)
177  {
178  $update_query = "UPDATE obj_members SET ".
179  "passed = ".$ilDB->quote((int) $a_passed,'integer').", ".
180  "origin = ".$ilDB->quote($origin,'integer').", ".
181  "origin_ts = ".$ilDB->quote(time(),'integer')." ".
182  "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
183  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer');
184  }
185  }
186  else
187  {
188  // when member is added we should not set any date
189  // see ilObjCourse::checkLPStatusSync()
190  if($a_no_origin && !$a_passed)
191  {
192  $origin = 0;
193  $origin_ts = 0;
194  }
195  else
196  {
197  $origin_ts = time();
198  }
199 
200  $update_query = "INSERT INTO obj_members (passed,obj_id,usr_id,notification,blocked,origin,origin_ts) ".
201  "VALUES ( ".
202  $ilDB->quote((int) $a_passed,'integer').", ".
203  $ilDB->quote($a_obj_id,'integer').", ".
204  $ilDB->quote($a_usr_id,'integer').", ".
205  $ilDB->quote(0,'integer').", ".
206  $ilDB->quote(0,'integer').", ".
207  $ilDB->quote($origin,'integer').", ".
208  $ilDB->quote($origin_ts,'integer').")";
209  }
210  if(strlen($update_query))
211  {
212  $ilDB->manipulate($update_query);
213  }
214  return true;
215  }
216 
223  function getPassedInfo($a_usr_id)
224  {
225  global $ilDB;
226 
227  $sql = "SELECT origin, origin_ts".
228  " FROM obj_members".
229  " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer").
230  " AND usr_id = ".$ilDB->quote($a_usr_id, "integer");
231  $set = $ilDB->query($sql);
232  $row = $ilDB->fetchAssoc($set);
233  if($row["origin"])
234  {
235  return array("user_id" => $row["origin"],
236  "timestamp" => new ilDateTime($row["origin_ts"], IL_CAL_UNIX));
237  }
238  }
239 
240  // Subscription
241  function sendNotification($a_type, $a_usr_id, $a_force_sending_mail = false)
242  {
243 
244  global $ilObjDataCache,$ilUser;
245 
246  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
248  $mail->forceSendingMail($a_force_sending_mail);
249 
250  switch($a_type)
251  {
252  case $this->NOTIFY_DISMISS_SUBSCRIBER:
254  $mail->setRefId($this->ref_id);
255  $mail->setRecipients(array($a_usr_id));
256  $mail->send();
257  break;
258 
259  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
261  $mail->setRefId($this->ref_id);
262  $mail->setRecipients(array($a_usr_id));
263  $mail->send();
264  break;
265 
266  case $this->NOTIFY_DISMISS_MEMBER:
268  $mail->setRefId($this->ref_id);
269  $mail->setRecipients(array($a_usr_id));
270  $mail->send();
271  break;
272 
273  case $this->NOTIFY_BLOCK_MEMBER:
275  $mail->setRefId($this->ref_id);
276  $mail->setRecipients(array($a_usr_id));
277  $mail->send();
278  break;
279 
280  case $this->NOTIFY_UNBLOCK_MEMBER:
282  $mail->setRefId($this->ref_id);
283  $mail->setRecipients(array($a_usr_id));
284  $mail->send();
285  break;
286 
287  case $this->NOTIFY_ACCEPT_USER:
289  $mail->setRefId($this->ref_id);
290  $mail->setRecipients(array($a_usr_id));
291  $mail->send();
292  break;
293 
294  case $this->NOTIFY_STATUS_CHANGED:
296  $mail->setRefId($this->ref_id);
297  $mail->setRecipients(array($a_usr_id));
298  $mail->send();
299  break;
300 
301  case $this->NOTIFY_UNSUBSCRIBE:
303  $mail->setRefId($this->ref_id);
304  $mail->setRecipients(array($a_usr_id));
305  $mail->send();
306  break;
307 
308  case $this->NOTIFY_REGISTERED:
310  $mail->setRefId($this->ref_id);
311  $mail->setRecipients(array($a_usr_id));
312  $mail->send();
313  break;
314 
315  case $this->NOTIFY_WAITING_LIST:
316  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
317  $wl = new ilCourseWaitingList($this->obj_id);
318  $pos = $wl->getPosition($a_usr_id);
319 
321  $mail->setRefId($this->ref_id);
322  $mail->setRecipients(array($a_usr_id));
323  $mail->setAdditionalInformation(array('position' => $pos));
324  $mail->send();
325  break;
326 
327  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
328  $this->sendSubscriptionRequestToAdmins($a_usr_id);
329  break;
330 
331  case $this->NOTIFY_ADMINS:
332  $this->sendNotificationToAdmins($a_usr_id);
333  return true;
334  break;
335  }
336  return true;
337  }
338 
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 sendSubscriptionRequestToAdmins($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  public function sendNotificationToAdmins($a_usr_id)
370  {
371  global $ilDB,$ilObjDataCache;
372 
373  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
376  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
377  $mail->setRefId($this->ref_id);
378  $mail->setRecipients($this->getNotificationRecipients());
379  $mail->send();
380  return true;
381  }
382 
383 
384  function __buildStatusBody(&$user_obj)
385  {
386  global $ilDB;
387 
388  $body = $this->lng->txt('crs_status_changed_body')."\n";
389  $body .= $this->lng->txt('login').': '.$user_obj->getLogin()."\n";
390  $body .= $this->lng->txt('role').': ';
391 
392  if($this->isAdmin($user_obj->getId()))
393  {
394  $body .= $this->lng->txt('crs_admin')."\n";
395  }
396  if($this->isTutor($user_obj->getId()))
397  {
398  $body .= $this->lng->txt('crs_tutor')."\n";
399  }
400  if($this->isMember($user_obj->getId()))
401  {
402  $body .= $this->lng->txt('crs_member')."\n";
403  }
404  $body .= $this->lng->txt('status').': ';
405 
406  if($this->isNotificationEnabled($user_obj->getId()))
407  {
408  $body .= $this->lng->txt("crs_notify")."\n";
409  }
410  else
411  {
412  $body .= $this->lng->txt("crs_no_notify")."\n";
413  }
414  if($this->isBlocked($user_obj->getId()))
415  {
416  $body .= $this->lng->txt("crs_blocked")."\n";
417  }
418  else
419  {
420  $body .= $this->lng->txt("crs_unblocked")."\n";
421  }
422  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
423  $body .= $this->lng->txt('crs_passed').': '.$passed."\n";
424 
425  return $body;
426  }
427 
428  public static function getDateTimeOfPassed($a_obj_id, $a_usr_id)
429  {
430  global $ilDB;
431 
432  $sql = "SELECT origin_ts FROM obj_members".
433  " WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer").
434  " AND obj_id = ".$ilDB->quote($a_obj_id, "integer").
435  " AND passed = ".$ilDB->quote(1, "integer");
436  $res = $ilDB->query($sql);
437  $res = $ilDB->fetchAssoc($res);
438  if($res["origin_ts"])
439  {
440  return date("Y-m-d H:i:s", $res["origin_ts"]);
441  }
442  }
443 
444  public static function getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
445  {
446  global $ilDB;
447 
448  $res = array();
449 
450  $sql = "SELECT usr_id,obj_id FROM obj_members".
451  " WHERE ".$ilDB->in("usr_id", $a_usr_ids, "", "integer").
452  " AND ".$ilDB->in("obj_id", $a_obj_ids, "", "integer").
453  " AND passed = ".$ilDB->quote(1, "integer");
454  $set = $ilDB->query($sql);
455  while($row = $ilDB->fetchAssoc($set))
456  {
457  $res[] = $row;
458  }
459 
460  return $res;
461  }
462 }
463 
464 ?>
getObjId()
get current obj_id
static getDateTimeOfPassed($a_obj_id, $a_usr_id)
isAdmin($a_usr_id)
is user admin
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
isNotificationEnabled($a_usr_id)
check if notification is enabled
__construct($a_obj_id)
Singleton constructor.
static _lookupTitle($a_id)
lookup object title
isMember($a_usr_id)
is user member
static getMemberRoles($a_ref_id)
Get member roles.
const IL_CAL_UNIX
static getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
$a_type
Definition: workflow.php:93
sendNotification($a_type, $a_usr_id, $a_force_sending_mail=false)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
getPassedInfo($a_usr_id)
Get info about passed status.
Date and time handling
$ilUser
Definition: imgupload.php:18
$old
isBlocked($a_usr_id)
Check if user is blocked.
Create styles array
The data for the language used.
hasPassed($a_usr_id)
Check if user has passed course.
static _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual=false, $a_no_origin=false)
Update passed status (static)
updatePassed($a_usr_id, $a_passed, $a_manual=false, $a_no_origin=false)
Update passed status.
getNotificationRecipients()
Get admin, tutor which have notification enabled.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
isTutor($a_usr_id)
is user tutor