ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilCourseAppEventListener.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  private $logger = null;
15 
16  static protected $course_mode = array();
17  static protected $blocked_for_lp;
18 
22  public function __construct()
23  {
24  $this->logger = ilLoggerFactory::getInstance()->getLogger('crs');
25 
26  }
27 
31  public function getLogger()
32  {
33  return $this->logger;
34  }
35 
41  protected function handleUserAssignments($a_event, $a_parameters)
42  {
43  if($a_parameters['type'] != 'crs')
44  {
45  $this->getLogger()->debug('Ignoring event for type '. $a_parameters['type']);
46  return TRUE;
47  }
48 
49  if($a_event == 'assignUser')
50  {
51  $this->getLogger()->debug('Handling assign user event for type crs.');
52  $new_status = 1;
53  }
54  elseif($a_event == 'deassignUser')
55  {
56  $this->getLogger()->debug('Handling assign user event for type crs.');
57  $new_status = 0;
58  }
59 
60  ilLoggerFactory::getInstance()->getLogger('crs')->debug(print_r($a_parameters,TRUE));
61  ilLoggerFactory::getInstance()->getLogger('crs')->debug(print_r($new_status,TRUE));
62 
63  include_once './Modules/Course/classes/class.ilCourseParticipant.php';
65  $a_parameters['obj_id'],
66  $a_parameters['usr_id'],
67  $a_parameters['role_id'],
68  $new_status
69  );
70 
71  if($a_event == 'deassignUser')
72  {
73  self::doAutoFill($a_parameters['obj_id']);
74  }
75  }
76 
82  protected static function doAutoFill($a_obj_id)
83  {
84  // #16694
85  include_once("./Modules/Course/classes/class.ilObjCourse.php");
86  $ref_id = array_pop(ilObject::_getAllReferences($a_obj_id));
87  $course = new ilObjCourse($ref_id);
88  $course->handleAutoFill();
89  }
90 
98  static function handleEvent($a_component, $a_event, $a_parameter)
99  {
100  if($a_component == 'Services/AccessControl')
101  {
102  $listener = new self();
103  $listener->handleUserAssignments($a_event, $a_parameter);
104  }
105 
106  if($a_component == "Services/Tracking" && $a_event == "updateStatus")
107  {
108  // see ilObjCourseGUI::updateLPFromStatus()
109  if((bool)self::$blocked_for_lp)
110  {
111  return;
112  }
113 
114  // #13905
115  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
117  {
118  return;
119  }
120 
121  $obj_id = $a_parameter["obj_id"];
122  $user_id = $a_parameter["usr_id"];
123  $status = $a_parameter["status"];
124 
125  if($obj_id && $user_id)
126  {
127  if (ilObject::_lookupType($obj_id) != "crs")
128  {
129  return;
130  }
131 
132  // determine couse setting only once
133  if(!isset(self::$course_mode[$obj_id]))
134  {
135  include_once("./Modules/Course/classes/class.ilObjCourse.php");
136  $crs = new ilObjCourse($obj_id, false);
137  if($crs->getStatusDetermination() == ilObjCourse::STATUS_DETERMINATION_LP)
138  {
139  include_once './Services/Object/classes/class.ilObjectLP.php';
140  $olp = ilObjectLP::getInstance($obj_id);
141  $mode = $olp->getCurrentMode();
142  }
143  else
144  {
145  $mode = false;
146  }
147  self::$course_mode[$obj_id] = $mode;
148  }
149 
150  $is_completed = ($status == ilLPStatus::LP_STATUS_COMPLETED_NUM);
151 
152  // we are NOT using the members object because of performance issues
153  switch(self::$course_mode[$obj_id])
154  {
156  // #11600
157  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
158  ilCourseParticipants::_updatePassed($obj_id, $user_id, $is_completed, true);
159  break;
160 
163  // overwrites course passed status if it was set automatically (full sync)
164  // or toggle manually set passed status to completed (1-way-sync)
165  $do_update = $is_completed;
166  include_once "Modules/Course/classes/class.ilCourseParticipants.php";
167  if(!$do_update)
168  {
169  $part = new ilCourseParticipants($obj_id);
170  $passed = $part->getPassedInfo($user_id);
171  if(!is_array($passed) ||
172  $passed["user_id"] == -1)
173  {
174  $do_update = true;
175  }
176  }
177  if($do_update)
178  {
179  ilCourseParticipants::_updatePassed($obj_id, $user_id, $is_completed);
180  }
181  break;
182  }
183  }
184  }
185  }
186 
192  public static function setBlockedForLP($a_status)
193  {
194  self::$blocked_for_lp = (bool)$a_status;
195  }
196 }
197 
198 ?>
const LP_STATUS_COMPLETED_NUM
static updateMemberRoles($a_obj_id, $a_usr_id, $a_role_id, $a_status)
Update member roles ilDB $ilDB.
static doAutoFill($a_obj_id)
Trigger autofill from waiting list.
const STATUS_DETERMINATION_LP
static handleEvent($a_component, $a_event, $a_parameter)
Handle an event in a listener.
static _getAllReferences($a_id)
get all reference ids of object
static _enabledLearningProgress()
check wether learing progress is enabled or not
Class ilObjCourse.
handleUserAssignments($a_event, $a_parameters)
handle user assignments
static _lookupType($a_id, $a_reference=false)
lookup object type
$ref_id
Definition: sahs_server.php:39
static _updatePassed($a_obj_id, $a_usr_id, $a_passed, $a_manual=false, $a_no_origin=false)
Update passed status (static)
static getInstance($a_obj_id)
static setBlockedForLP($a_status)
Toggle LP blocking property status.