ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
24include_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->addRecommendation($a_usr_id);
94 return true;
95 }
96 return false;
97 }
98
103 public static function getMemberRoles($a_ref_id)
104 {
105 global $DIC;
106
107 $rbacreview = $DIC['rbacreview'];
108
109 $lrol = $rbacreview->getRolesOfRoleFolder($a_ref_id, false);
110
111 $roles = array();
112 foreach ($lrol as $role) {
113 $title = ilObject::_lookupTitle($role);
114 switch (substr($title, 0, 8)) {
115 case 'il_crs_a':
116 case 'il_crs_t':
117 case 'il_crs_m':
118 continue 2;
119
120 default:
121 $roles[$role] = $role;
122 }
123 }
124 return $roles;
125 }
126
127 public function addSubscriber($a_usr_id)
128 {
129 global $DIC;
130
131 $ilAppEventHandler = $DIC['ilAppEventHandler'];
132 $ilLog = $DIC['ilLog'];
133
134 parent::addSubscriber($a_usr_id);
135
136 $ilLog->write(__METHOD__ . ': Raise new event: Modules/Course addSubscriber');
137 $ilAppEventHandler->raise(
138 "Modules/Course",
139 'addSubscriber',
140 array(
141 'obj_id' => $this->getObjId(),
142 'usr_id' => $a_usr_id
143 )
144 );
145 }
146
156 public function updatePassed($a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
157 {
158 $this->participants_status[$a_usr_id]['passed'] = (int) $a_passed;
159
160 return self::_updatePassed($this->obj_id, $a_usr_id, $a_passed, $a_manual, $a_no_origin);
161 }
162
163
177 public static function _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual = false, $a_no_origin = false)
178 {
179 global $DIC;
180
181 $ilDB = $DIC['ilDB'];
182 $ilUser = $DIC['ilUser'];
183 $ilAppEventHandler = $DIC['ilAppEventHandler'];
188 // #11600
189 $origin = -1;
190 if ($a_manual) {
191 $origin = $ilUser->getId();
192 }
193
194 $query = "SELECT passed FROM obj_members " .
195 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
196 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
197 $res = $ilDB->query($query);
198 $update_query = '';
199 if ($res->numRows()) {
200 // #9284 - only needs updating when status has changed
201 $old = $ilDB->fetchAssoc($res);
202 if ((int) $old["passed"] != (int) $a_passed) {
203 $update_query = "UPDATE obj_members SET " .
204 "passed = " . $ilDB->quote((int) $a_passed, 'integer') . ", " .
205 "origin = " . $ilDB->quote($origin, 'integer') . ", " .
206 "origin_ts = " . $ilDB->quote(time(), 'integer') . " " .
207 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
208 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer');
209 }
210 } else {
211 // when member is added we should not set any date
212 // see ilObjCourse::checkLPStatusSync()
213 if ($a_no_origin && !$a_passed) {
214 $origin = 0;
215 $origin_ts = 0;
216 } else {
217 $origin_ts = time();
218 }
219
220 $update_query = "INSERT INTO obj_members (passed,obj_id,usr_id,notification,blocked,origin,origin_ts) " .
221 "VALUES ( " .
222 $ilDB->quote((int) $a_passed, 'integer') . ", " .
223 $ilDB->quote($a_obj_id, 'integer') . ", " .
224 $ilDB->quote($a_usr_id, 'integer') . ", " .
225 $ilDB->quote(0, 'integer') . ", " .
226 $ilDB->quote(0, 'integer') . ", " .
227 $ilDB->quote($origin, 'integer') . ", " .
228 $ilDB->quote($origin_ts, 'integer') . ")";
229 }
230 if (strlen($update_query)) {
231 $ilDB->manipulate($update_query);
232 if ($a_passed) {
233 $ilAppEventHandler->raise('Modules/Course', 'participantHasPassedCourse', array(
234 'obj_id' => $a_obj_id,
235 'usr_id' => $a_usr_id,
236 ));
237 }
238 }
239 return true;
240 }
241
248 public function getPassedInfo($a_usr_id)
249 {
250 global $DIC;
251
252 $ilDB = $DIC['ilDB'];
253
254 $sql = "SELECT origin, origin_ts" .
255 " FROM obj_members" .
256 " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer") .
257 " AND usr_id = " . $ilDB->quote($a_usr_id, "integer");
258 $set = $ilDB->query($sql);
259 $row = $ilDB->fetchAssoc($set);
260 if ($row["origin"]) {
261 return array("user_id" => $row["origin"],
262 "timestamp" => new ilDateTime($row["origin_ts"], IL_CAL_UNIX));
263 }
264 }
265
266 // Subscription
267 public function sendNotification($a_type, $a_usr_id, $a_force_sending_mail = false)
268 {
269 global $DIC;
270
271 $ilObjDataCache = $DIC['ilObjDataCache'];
272 $ilUser = $DIC['ilUser'];
273
274 include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
276 $mail->forceSendingMail($a_force_sending_mail);
277
278 switch ($a_type) {
279 case $this->NOTIFY_DISMISS_SUBSCRIBER:
281 $mail->setRefId($this->ref_id);
282 $mail->setRecipients(array($a_usr_id));
283 $mail->send();
284 break;
285
286 case $this->NOTIFY_ACCEPT_SUBSCRIBER:
288 $mail->setRefId($this->ref_id);
289 $mail->setRecipients(array($a_usr_id));
290 $mail->send();
291 break;
292
293 case $this->NOTIFY_DISMISS_MEMBER:
295 $mail->setRefId($this->ref_id);
296 $mail->setRecipients(array($a_usr_id));
297 $mail->send();
298 break;
299
300 case $this->NOTIFY_BLOCK_MEMBER:
302 $mail->setRefId($this->ref_id);
303 $mail->setRecipients(array($a_usr_id));
304 $mail->send();
305 break;
306
307 case $this->NOTIFY_UNBLOCK_MEMBER:
309 $mail->setRefId($this->ref_id);
310 $mail->setRecipients(array($a_usr_id));
311 $mail->send();
312 break;
313
314 case $this->NOTIFY_ACCEPT_USER:
316 $mail->setRefId($this->ref_id);
317 $mail->setRecipients(array($a_usr_id));
318 $mail->send();
319 break;
320
321 case $this->NOTIFY_STATUS_CHANGED:
323 $mail->setRefId($this->ref_id);
324 $mail->setRecipients(array($a_usr_id));
325 $mail->send();
326 break;
327
328 case $this->NOTIFY_UNSUBSCRIBE:
330 $mail->setRefId($this->ref_id);
331 $mail->setRecipients(array($a_usr_id));
332 $mail->send();
333 break;
334
335 case $this->NOTIFY_REGISTERED:
337 $mail->setRefId($this->ref_id);
338 $mail->setRecipients(array($a_usr_id));
339 $mail->send();
340 break;
341
342 case $this->NOTIFY_WAITING_LIST:
343 include_once('./Modules/Course/classes/class.ilCourseWaitingList.php');
344 $wl = new ilCourseWaitingList($this->obj_id);
345 $pos = $wl->getPosition($a_usr_id);
346
348 $mail->setRefId($this->ref_id);
349 $mail->setRecipients(array($a_usr_id));
350 $mail->setAdditionalInformation(array('position' => $pos));
351 $mail->send();
352 break;
353
354 case $this->NOTIFY_SUBSCRIPTION_REQUEST:
355 $this->sendSubscriptionRequestToAdmins($a_usr_id);
356 break;
357
358 case $this->NOTIFY_ADMINS:
359 $this->sendNotificationToAdmins($a_usr_id);
360 return true;
361 break;
362 }
363 return true;
364 }
365
366 public function sendUnsubscribeNotificationToAdmins($a_usr_id)
367 {
368 global $DIC;
369
370 $ilDB = $DIC['ilDB'];
371 $ilObjDataCache = $DIC['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 public function sendSubscriptionRequestToAdmins($a_usr_id)
385 {
386 global $DIC;
387
388 $ilDB = $DIC['ilDB'];
389 $ilObjDataCache = $DIC['ilObjDataCache'];
390
391 include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
394 $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
395 $mail->setRefId($this->ref_id);
396 $mail->setRecipients($this->getNotificationRecipients());
397 $mail->send();
398 return true;
399 }
400
401
402 public function sendNotificationToAdmins($a_usr_id)
403 {
404 global $DIC;
405
406 $ilDB = $DIC['ilDB'];
407 $ilObjDataCache = $DIC['ilObjDataCache'];
408
409 include_once './Modules/Course/classes/class.ilCourseMembershipMailNotification.php';
412 $mail->setAdditionalInformation(array('usr_id' => $a_usr_id));
413 $mail->setRefId($this->ref_id);
414 $mail->setRecipients($this->getNotificationRecipients());
415 $mail->send();
416 return true;
417 }
418
419
420 public function __buildStatusBody(&$user_obj)
421 {
422 global $DIC;
423
424 $ilDB = $DIC['ilDB'];
425
426 $body = $this->lng->txt('crs_status_changed_body') . "\n";
427 $body .= $this->lng->txt('login') . ': ' . $user_obj->getLogin() . "\n";
428 $body .= $this->lng->txt('role') . ': ';
429
430 if ($this->isAdmin($user_obj->getId())) {
431 $body .= $this->lng->txt('crs_admin') . "\n";
432 }
433 if ($this->isTutor($user_obj->getId())) {
434 $body .= $this->lng->txt('crs_tutor') . "\n";
435 }
436 if ($this->isMember($user_obj->getId())) {
437 $body .= $this->lng->txt('crs_member') . "\n";
438 }
439 $body .= $this->lng->txt('status') . ': ';
440
441 if ($this->isNotificationEnabled($user_obj->getId())) {
442 $body .= $this->lng->txt("crs_notify") . "\n";
443 } else {
444 $body .= $this->lng->txt("crs_no_notify") . "\n";
445 }
446 if ($this->isBlocked($user_obj->getId())) {
447 $body .= $this->lng->txt("crs_blocked") . "\n";
448 } else {
449 $body .= $this->lng->txt("crs_unblocked") . "\n";
450 }
451 $passed = $this->hasPassed($user_obj->getId()) ? $this->lng->txt('yes') : $this->lng->txt('no');
452 $body .= $this->lng->txt('crs_passed') . ': ' . $passed . "\n";
453
454 return $body;
455 }
456
457 public static function getDateTimeOfPassed($a_obj_id, $a_usr_id)
458 {
459 global $DIC;
460
461 $ilDB = $DIC['ilDB'];
462
463 $sql = "SELECT origin_ts FROM obj_members" .
464 " WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer") .
465 " AND obj_id = " . $ilDB->quote($a_obj_id, "integer") .
466 " AND passed = " . $ilDB->quote(1, "integer");
467 $res = $ilDB->query($sql);
468 $res = $ilDB->fetchAssoc($res);
469 if ($res["origin_ts"]) {
470 return date("Y-m-d H:i:s", $res["origin_ts"]);
471 }
472 }
473
474 public static function getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
475 {
476 global $DIC;
477
478 $ilDB = $DIC['ilDB'];
479
480 $res = array();
481
482 $sql = "SELECT usr_id,obj_id FROM obj_members" .
483 " WHERE " . $ilDB->in("usr_id", $a_usr_ids, "", "integer") .
484 " AND " . $ilDB->in("obj_id", $a_obj_ids, "", "integer") .
485 " AND passed = " . $ilDB->quote(1, "integer");
486 $set = $ilDB->query($sql);
487 while ($row = $ilDB->fetchAssoc($set)) {
488 $res[] = $row;
489 }
490
491 return $res;
492 }
493}
add()
Definition: add.php:2
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
updatePassed($a_usr_id, $a_passed, $a_manual=false, $a_no_origin=false)
Update passed status.
getPassedInfo($a_usr_id)
Get info about passed status.
addSubscriber($a_usr_id)
Add subscriber.
sendNotification($a_type, $a_usr_id, $a_force_sending_mail=false)
static getDateTimeOfPassed($a_obj_id, $a_usr_id)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
__construct($a_obj_id)
Singleton constructor.
add($a_usr_id, $a_role)
Add user to role.
static getPassedUsersForObjects(array $a_obj_ids, array $a_usr_ids)
static getMemberRoles($a_ref_id)
Get member roles.
@classDescription Date and time handling
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
isTutor($a_usr_id)
is user tutor
isMember($a_usr_id)
is user member
isAdmin($a_usr_id)
is user admin
addRecommendation($a_usr_id)
Add desktop item.
getNotificationRecipients()
Get admin, tutor which have notification enabled.
isNotificationEnabled($a_usr_id)
check if notification is enabled
getObjId()
get current obj_id
hasPassed($a_usr_id)
Check if user has passed course.
isBlocked($a_usr_id)
Check if user is blocked.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46