ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLPStatusCollection.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
33 include_once './Services/Tracking/classes/class.ilLPStatus.php';
34 include_once './Services/Tracking/classes/class.ilLPStatusWrapper.php';
35 
37 {
38  public function __construct($a_obj_id)
39  {
40  global $ilDB;
41 
42  parent::__construct($a_obj_id);
43  $this->db = $ilDB;
44  }
45 
46  public static function _getNotAttempted($a_obj_id)
47  {
48  $users = array();
49 
50  $members = self::getMembers($a_obj_id);
51  if ($members) {
52  // diff in progress and completed (use stored result in LPStatusWrapper)
53  $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
54  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
55  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
56  }
57 
58  return $users;
59  }
60 
61  public static function _getInProgress($a_obj_id)
62  {
63  include_once './Services/Tracking/classes/class.ilChangeEvent.php';
65 
66  include_once './Services/Object/classes/class.ilObjectLP.php';
67  $olp = ilObjectLP::getInstance($a_obj_id);
68  $collection = $olp->getCollectionInstance();
69  if ($collection) {
70  foreach ($collection->getItems() as $item_id) {
71  $item_id = ilObject::_lookupObjId($item_id);
72 
73  // merge arrays of users with status 'in progress'
74  $users = array_unique(array_merge((array) $users, ilLPStatusWrapper::_getInProgress($item_id)));
75  $users = array_unique(array_merge((array) $users, ilLPStatusWrapper::_getCompleted($item_id)));
76  }
77  }
78 
79  // Exclude all users with status completed.
80  $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
81  // Exclude all users with status failed.
82  $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
83 
84  if ($users) {
85  // Exclude all non members
86  $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
87  }
88 
89  return $users;
90  }
91 
99  public static function _getCompleted($a_obj_id)
100  {
101  global $ilObjDataCache;
102 
103  include_once './Services/Object/classes/class.ilObjectLP.php';
104  $olp = ilObjectLP::getInstance($a_obj_id);
105  $collection = $olp->getCollectionInstance();
106  if ($collection) {
107  $grouped_items = $collection->getGroupedItemsForLPStatus();
108  }
109  if (!sizeof($grouped_items)) {
110  // #11513 - empty collections cannot be completed
111  return array();
112  } else {
113  // New handling for optional assignments
114  $counter = 0;
115  $users = array();
116  foreach ($grouped_items as $grouping_id => $grouping) {
117  $isGrouping = $grouping_id ? true : false;
118  $grouping_completed = array();
119  $grouping_completed_users_num = array();
120  foreach ((array) $grouping['items'] as $item) {
121  $item_id = $ilObjDataCache->lookupObjId($item);
122  $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
123  if ($isGrouping) {
124  // Iterated through all grouped items and count the number of fullfiled items
125  foreach ($tmp_users as $tmp_user_id) {
126  ++$grouping_completed_users_num[$tmp_user_id];
127  }
128  } else {
129  if (!$counter++) {
130  $users = $tmp_users;
131  } else {
132  $users = array_intersect($users, $tmp_users);
133  }
134  }
135  }
136  if ($isGrouping) {
137  // Iterate through all "grouping_completed_users_num"
138  // All users with completed items greater equal than "num_obligatory" are completed
139  foreach ($grouping_completed_users_num as $tmp_user_id => $grouping_num_completed) {
140  if ($grouping_num_completed >= $grouping['num_obligatory']) {
141  $grouping_completed[] = $tmp_user_id;
142  }
143  }
144 
145  // build intersection of users
146  if (!$counter++) {
147  $users = $grouping_completed;
148  } else {
149  $users = array_intersect($users, $grouping_completed);
150  }
151  }
152  }
153  }
154 
155  $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
156 
157  if ($users) {
158  // Exclude all non members
159  $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
160  }
161 
162  return (array) $users;
163  }
164 
165  public static function _getFailed($a_obj_id)
166  {
167  global $ilObjDataCache;
168 
169  $users = array();
170 
171  include_once './Services/Object/classes/class.ilObjectLP.php';
172  $olp = ilObjectLP::getInstance($a_obj_id);
173  $collection = $olp->getCollectionInstance();
174  if ($collection) {
175  foreach ($collection->getGroupedItemsForLPStatus() as $grouping_id => $grouping) {
176  $isGrouping = $grouping_id ? true : false;
177 
178  $gr_failed = array();
179  $gr_failed_users_num = array();
180  $counter = 0;
181  foreach ((array) $grouping['items'] as $item) {
182  $item_id = $ilObjDataCache->lookupObjId($item);
183  $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
184 
185  if ($isGrouping) {
186  foreach ($tmp_users as $tmp_user_id) {
187  ++$gr_failed_users_num[$tmp_user_id];
188  }
189  } else {
190  // One item failed is sufficient for status failed.
191  $gr_failed = array_merge($gr_failed, $tmp_users);
192  }
193  $counter++;
194  }
195  if ($isGrouping) {
196  $allowed_failed = count($grouping['items']) - $grouping['num_obligatory'];
197  // Itereate over all failed users and check whether the allowd_failed value exceeded
198  foreach ($gr_failed_users_num as $tmp_user_id => $num_failed) {
199  if ($num_failed > $allowed_failed) {
200  $gr_failed[] = $tmp_user_id;
201  }
202  }
203  }
204  $users = array_unique(array_merge($users, $gr_failed));
205  }
206  }
207 
208  if ($users) {
209  // Exclude all non members
210  $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
211  }
212 
213  return array_unique($users);
214  }
215 
216  public static function _getStatusInfo($a_obj_id)
217  {
218  $status_info = array();
219 
220  include_once './Services/Object/classes/class.ilObjectLP.php';
221  $olp = ilObjectLP::getInstance($a_obj_id);
222  $collection = $olp->getCollectionInstance();
223  if ($collection) {
224  $status_info['collections'] = $collection->getItems();
225  $status_info['num_collections'] = count($status_info['collections']);
226  }
227 
228  return $status_info;
229  }
230 
231  public static function _getTypicalLearningTime($a_obj_id)
232  {
233  global $ilObjDataCache;
234 
235  if ($ilObjDataCache->lookupType($a_obj_id) == 'sahs') {
236  return parent::_getTypicalLearningTime($a_obj_id);
237  }
238 
239  $tlt = 0;
240  $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
241  foreach ($status_info['collections'] as $item) {
242  $tlt += ilLPStatusWrapper::_getTypicalLearningTime($ilObjDataCache->lookupObjId($item));
243  }
244  return $tlt;
245  }
246 
255  public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
256  {
257  global $ilObjDataCache;
258 
259  $status['completed'] = true;
260  $status['failed'] = false;
261  $status['in_progress'] = false;
262 
263  switch ($ilObjDataCache->lookupType($a_obj_id)) {
264  case "crs":
265  case "fold":
266  case "grp":
267  include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
268  if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id)) {
269  $status['in_progress'] = true;
270  }
271 
272  include_once './Services/Object/classes/class.ilObjectLP.php';
273  $olp = ilObjectLP::getInstance($a_obj_id);
274  $collection = $olp->getCollectionInstance();
275  if ($collection) {
276  $grouped_items = $collection->getGroupedItemsForLPStatus();
277  }
278  if (!sizeof($grouped_items)) {
279  // #11513 - empty collections cannot be completed
280  $status['completed'] = false;
281  } else {
282  foreach ($grouped_items as $grouping_id => $grouping) {
283  $isGrouping = $grouping_id ? true : false;
284  $status = self::determineGroupingStatus($status, $grouping, $a_user_id, $isGrouping);
285  }
286  }
287 
288  if ($status['completed']) {
289  return self::LP_STATUS_COMPLETED_NUM;
290  }
291  if ($status['failed']) {
292  return self::LP_STATUS_FAILED_NUM;
293  }
294  if ($status['in_progress']) {
295  return self::LP_STATUS_IN_PROGRESS_NUM;
296  }
297  break;
298  }
299  return self::LP_STATUS_NOT_ATTEMPTED_NUM;
300  }
301 
311  public static function determineGroupingStatus($status, $gr_info, $user_id, $is_grouping)
312  {
313  global $ilObjDataCache;
314 
315  $items = $gr_info['items'];
316  if ($is_grouping) {
317  $max_allowed_failed = count($items) - $gr_info['num_obligatory'];
318  $required_completed = $gr_info['num_obligatory'];
319  } else {
320  $max_allowed_failed = 0;
321  $required_completed = count($items);
322  }
323 
324  // Required for grouping with a number of obligatory items
325  $num_failed = 0;
326  $num_completed = 0;
327 
328  foreach ($items as $item_id) {
329  $item_id = $ilObjDataCache->lookupObjId($item_id);
330  $gr_status = ilLPStatusWrapper::_determineStatus($item_id, $user_id);
331 
332  if ($gr_status == self::LP_STATUS_FAILED_NUM) {
333  if (++$num_failed > $max_allowed_failed) {
334  $status['failed'] = true;
335  $status['completed'] = false;
336  return $status;
337  }
338  }
339  if ($gr_status == self::LP_STATUS_COMPLETED_NUM) {
340  if (++$num_completed >= $required_completed) {
341  return $status;
342  }
343  }
344  }
345  // Not completed since returned above
346  $status['completed'] = false;
347  return $status;
348  }
349 
355  protected static function getMembers($a_obj_id)
356  {
357  global $ilObjDataCache, $tree;
358 
359  switch ($ilObjDataCache->lookupType($a_obj_id)) {
360  case 'crs':
361  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
362  $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
363  return $member_obj->getMembers();
364 
365  case 'grp':
366  include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
367  $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
368  return $member_obj->getMembers();
369 
370  case 'fold':
371  $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
372  $folder_ref_id = current($folder_ref_ids);
373  if ($crs_id = $tree->checkForParentType($folder_ref_id, 'crs')) {
374  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
376  return $member_obj->getMembers();
377  }
378  break;
379  }
380 
381  return array();
382  }
383 
391  public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
392  {
393  if (!$a_user_ids) {
394  $a_user_ids = self::getMembers($a_obj_id);
395  if (!$a_user_ids) {
396  return array();
397  }
398  }
399  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
400  }
401 
409  public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
410  {
411  if (!$a_user_ids) {
412  $a_user_ids = self::getMembers($a_obj_id);
413  if (!$a_user_ids) {
414  return array();
415  }
416  }
417  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_FAILED_NUM, $a_user_ids);
418  }
419 
427  public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
428  {
429  if (!$a_user_ids) {
430  $a_user_ids = self::getMembers($a_obj_id);
431  if (!$a_user_ids) {
432  return array();
433  }
434  }
435  return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
436  }
437 }
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
static _getInProgress($a_obj_id)
Static function to read users who have the status &#39;in_progress&#39;.
static _getCompleted($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
static determineGroupingStatus($status, $gr_info, $user_id, $is_grouping)
Determine grouping status $ilObjDataCache.
static getMembers($a_obj_id)
Get members for object.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static _getAllReferences($a_id)
get all reference ids of object
static _getFailed($a_obj_id)
Static function to read the users who have the status &#39;completed&#39;.
$counter
static _getTypicalLearningTime($a_obj_id)
static _lookupObjId($a_id)
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
static _getCompleted($a_obj_id)
Get completed users New handling for optional grouped assignments.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
Create styles array
The data for the language used.
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
$users
Definition: authpage.php:44
global $ilDB
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
static _getTypicalLearningTime($a_obj_id)
Reads Typical learning time.
static getInstance($a_obj_id)
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static _determineStatus($a_obj_id, $a_usr_id)
Determine status.
static lookupUsersInProgress($a_obj_id)
Lookup users in progress.