ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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->NOTIFY_DISMISS_SUBSCRIBER = 1;
51  $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
52  $this->NOTIFY_DISMISS_MEMBER = 3;
53  $this->NOTIFY_BLOCK_MEMBER = 4;
54  $this->NOTIFY_UNBLOCK_MEMBER = 5;
55  $this->NOTIFY_ACCEPT_USER = 6;
56  $this->NOTIFY_ADMINS = 7;
57  $this->NOTIFY_STATUS_CHANGED = 8;
58  $this->NOTIFY_SUBSCRIPTION_REQUEST = 9;
59 
60  $this->NOTIFY_REGISTERED = 10;
61  $this->NOTIFY_UNSUBSCRIBE = 11;
62  $this->NOTIFY_WAITING_LIST = 12;
63 
64  // ref based constructor
65  $refs = ilObject::_getAllReferences($a_obj_id);
66  parent::__construct(self::COMPONENT_NAME, array_pop($refs));
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  return self::$instances[$a_obj_id];
81  }
82  return self::$instances[$a_obj_id] = new ilCourseParticipants($a_obj_id);
83  }
84 
90  public function add($a_usr_id, $a_role)
91  {
92  if (parent::add($a_usr_id, $a_role)) {
93  $this->addDesktopItem($a_usr_id);
94  return true;
95  }
96  return false;
97  }
98 
103  public static function getMemberRoles($a_ref_id)
104  {
105  global $rbacreview;
106 
107  $lrol = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
108 
109  $roles = array();
110  foreach ($lrol as $role) {
112  switch (substr($title, 0, 8)) {
113  case 'il_crs_a':
114  case 'il_crs_t':
115  case 'il_crs_m':
116  continue;
117 
118  default:
119  $roles[$role] = $role;
120  }
121  }
122  return $roles;
123  }
124 
125  public function addSubscriber($a_usr_id)
126  {
127  global $ilAppEventHandler, $ilLog;
128 
129  parent::addSubscriber($a_usr_id);
130 
131  $ilLog->write(__METHOD__ . ': Raise new event: Modules/Course addSubscriber');
132  $ilAppEventHandler->raise(
133  "Modules/Course",
134  'addSubscriber',
135  array(
136  'obj_id' => $this->getObjId(),
137  'usr_id' => $a_usr_id
138  )
139  );
140  }
141 
151  public function updatePassed($a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
152  {
153  $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
154 
155  return self::_updatePassed($this->obj_id, $a_usr_id, $a_passed, $a_manual, $a_no_origin);
156  }
157 
158 
172  public static function _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
173  {
174  global $ilDB, $ilUser, $ilAppEventHandler;
179  // #11600
180  $origin = -1;
181  if ($a_manual) {
182  $origin = $ilUser->getId();
183  }
184 
185  $query = "SELECT passed FROM obj_members " .
186  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
187  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
188  $res = $ilDB->query($query);
189  $update_query = '';
190  if ($res->numRows()) {
191  // #9284 - only needs updating when status has changed
192  $old = $ilDB->fetchAssoc($res);
193  if ((int) $old["passed"] != (int) $a_passed) {
194  $update_query = "UPDATE obj_members SET " .
195  "passed = " . $ilDB->quote((int) $a_passed, 'integer') . ", " .
196  "origin = " . $ilDB->quote($origin, 'integer') . ", " .
197  "origin_ts = " . $ilDB->quote(time(), 'integer') . " " .
198  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
199  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
200  }
201  } else {
202  // when member is added we should not set any date
203  // see ilObjCourse::checkLPStatusSync()
204  if ($a_no_origin && !$a_passed) {
205  $origin = 0;
206  $origin_ts = 0;
207  } else {
208  $origin_ts = time();
209  }
210 
211  $update_query = "INSERT INTO obj_members (passed,obj_id,usr_id,notification,blocked,origin,origin_ts) " .
212  "VALUES ( " .
213  $ilDB->quote((int) $a_passed, 'integer') . ", " .
214  $ilDB->quote($a_obj_id, 'integer') . ", " .
215  $ilDB->quote($a_usr_id, 'integer') . ", " .
216  $ilDB->quote(0, 'integer') . ", " .
217  $ilDB->quote(0, 'integer') . ", " .
218  $ilDB->quote($origin, 'integer') . ", " .
219  $ilDB->quote($origin_ts, 'integer') . ")";
220  }
221  if (strlen($update_query)) {
222  $ilDB->manipulate($update_query);
223  if ($a_passed) {
224  $ilAppEventHandler->raise('Modules/Course', 'participantHasPassedCourse', array(
225  'obj_id' => $a_obj_id,
226  'usr_id' => $a_usr_id,
227  ));
228  }
229  }
230  return true;
231  }
232 
239  public function getPassedInfo($a_usr_id)
240  {
241  global $ilDB;
242 
243  $sql = "SELECT origin, origin_ts" .
244  " FROM obj_members" .
245  " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer") .
246  " AND usr_id = " . $ilDB->quote($a_usr_id, "integer");
247  $set = $ilDB->query($sql);
248  $row = $ilDB->fetchAssoc($set);
249  if ($row["origin"]) {
250  return array("user_id" => $row["origin"],
251  "timestamp" => new ilDateTime($row["origin_ts"], IL_CAL_UNIX));
252  }
253  }
254 
255  // Subscription
256  public function sendNotification($a_type, $a_usr_id, $a_force_sending_mail = false)
257  {
258  global $ilObjDataCache,$ilUser;
259 
260  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
262  $mail->forceSendingMail($a_force_sending_mail);
263 
264  switch ($a_type) {
265  case $this->NOTIFY_DISMISS_SUBSCRIBER:
267  $mail->setRefId($this->ref_id);
268  $mail->setRecipients(array($a_usr_id));
269  $mail->send();
270  break;
271 
272  case $this->NOTIFY_ACCEPT_SUBSCRIBER:
274  $mail->setRefId($this->ref_id);
275  $mail->setRecipients(array($a_usr_id));
276  $mail->send();
277  break;
278 
279  case $this->NOTIFY_DISMISS_MEMBER:
281  $mail->setRefId($this->ref_id);
282  $mail->setRecipients(array($a_usr_id));
283  $mail->send();
284  break;
285 
286  case $this->NOTIFY_BLOCK_MEMBER:
288  $mail->setRefId($this->ref_id);
289  $mail->setRecipients(array($a_usr_id));
290  $mail->send();
291  break;
292 
293  case $this->NOTIFY_UNBLOCK_MEMBER:
295  $mail->setRefId($this->ref_id);
296  $mail->setRecipients(array($a_usr_id));
297  $mail->send();
298  break;
299 
300  case $this->NOTIFY_ACCEPT_USER:
302  $mail->setRefId($this->ref_id);
303  $mail->setRecipients(array($a_usr_id));
304  $mail->send();
305  break;
306 
307  case $this->NOTIFY_STATUS_CHANGED:
309  $mail->setRefId($this->ref_id);
310  $mail->setRecipients(array($a_usr_id));
311  $mail->send();
312  break;
313 
314  case $this->NOTIFY_UNSUBSCRIBE:
316  $mail->setRefId($this->ref_id);
317  $mail->setRecipients(array($a_usr_id));
318  $mail->send();
319  break;
320 
321  case $this->NOTIFY_REGISTERED:
323  $mail->setRefId($this->ref_id);
324  $mail->setRecipients(array($a_usr_id));
325  $mail->send();
326  break;
327 
328  case $this->NOTIFY_WAITING_LIST:
329  include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
330  $wl = new ilCourseWaitingList($this->obj_id);
331  $pos = $wl->getPosition($a_usr_id);
332 
334  $mail->setRefId($this->ref_id);
335  $mail->setRecipients(array($a_usr_id));
336  $mail->setAdditionalInformation(array('position' => $pos));
337  $mail->send();
338  break;
339 
340  case $this->NOTIFY_SUBSCRIPTION_REQUEST:
341  $this->sendSubscriptionRequestToAdmins($a_usr_id);
342  break;
343 
344  case $this->NOTIFY_ADMINS:
345  $this->sendNotificationToAdmins($a_usr_id);
346  return true;
347  break;
348  }
349  return true;
350  }
351 
352  public function sendUnsubscribeNotificationToAdmins($a_usr_id)
353  {
354  global $ilDB,$ilObjDataCache;
355 
356  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
359  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
360  $mail->setRefId($this->ref_id);
361  $mail->setRecipients($this->getNotificationRecipients());
362  $mail->send();
363  return true;
364  }
365 
366 
367  public function sendSubscriptionRequestToAdmins($a_usr_id)
368  {
369  global $ilDB,$ilObjDataCache;
370 
371  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
374  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
375  $mail->setRefId($this->ref_id);
376  $mail->setRecipients($this->getNotificationRecipients());
377  $mail->send();
378  return true;
379  }
380 
381 
382  public function sendNotificationToAdmins($a_usr_id)
383  {
384  global $ilDB,$ilObjDataCache;
385 
386  include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
389  $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
390  $mail->setRefId($this->ref_id);
391  $mail->setRecipients($this->getNotificationRecipients());
392  $mail->send();
393  return true;
394  }
395 
396 
397  public function __buildStatusBody(&$user_obj)
398  {
399  global $ilDB;
400 
401  $body = $this->lng->txt('crs_status_changed_body') . "\n";
402  $body .= $this->lng->txt('login') . ': ' . $user_obj->getLogin() . "\n";
403  $body .= $this->lng->txt('role') . ': ';
404 
405  if ($this->isAdmin($user_obj->getId())) {
406  $body .= $this->lng->txt('crs_admin') . "\n";
407  }
408  if ($this->isTutor($user_obj->getId())) {
409  $body .= $this->lng->txt('crs_tutor') . "\n";
410  }
411  if ($this->isMember($user_obj->getId())) {
412  $body .= $this->lng->txt('crs_member') . "\n";
413  }
414  $body .= $this->lng->txt('status') . ': ';
415 
416  if ($this->isNotificationEnabled($user_obj->getId())) {
417  $body .= $this->lng->txt("crs_notify") . "\n";
418  } else {
419  $body .= $this->lng->txt("crs_no_notify") . "\n";
420  }
421  if ($this->isBlocked($user_obj->getId())) {
422  $body .= $this->lng->txt("crs_blocked") . "\n";
423  } else {
424  $body .= $this->lng->txt("crs_unblocked") . "\n";
425  }
426  $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
427  $body .= $this->lng->txt('crs_passed') . ': ' . $passed . "\n";
428 
429  return $body;
430  }
431 
432  public static function getDateTimeOfPassed($a_obj_id, $a_usr_id)
433  {
434  global $ilDB;
435 
436  $sql = "SELECT origin_ts FROM obj_members" .
437  " WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer") .
438  " AND obj_id = " . $ilDB->quote($a_obj_id, "integer") .
439  " AND passed = " . $ilDB->quote(1, "integer");
440  $res = $ilDB->query($sql);
441  $res = $ilDB->fetchAssoc($res);
442  if ($res["origin_ts"]) {
443  return date("Y-m-d H:i:s", $res["origin_ts"]);
444  }
445  }
446 
447  public static function getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
448  {
449  global $ilDB;
450 
451  $res = array();
452 
453  $sql = "SELECT usr_id,obj_id FROM obj_members" .
454  " WHERE " . $ilDB->in("usr_id", $a_usr_ids, "", "integer") .
455  " AND " . $ilDB->in("obj_id", $a_obj_ids, "", "integer") .
456  " AND passed = " . $ilDB->quote(1, "integer");
457  $set = $ilDB->query($sql);
458  while ($row = $ilDB->fetchAssoc($set)) {
459  $res[] = $row;
460  }
461 
462  return $res;
463  }
464 }
getObjId()
get current obj_id
addDesktopItem($a_usr_id)
Add desktop item.
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)
static _getAllReferences($a_id)
get all reference ids of object
$a_type
Definition: workflow.php:92
sendNotification($a_type, $a_usr_id, $a_force_sending_mail=false)
add()
Definition: add.php:2
foreach($_POST as $key=> $value) $res
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
$query
$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.
add($a_usr_id, $a_role)
Add user to role.
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