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