ILIAS  release_7 Revision v7.30-3-g800a261c036
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 private $tree;
39 protected $ilObjDataCache;
40
41
42 public function __construct($a_obj_id)
43 {
44 global $DIC;
45
46 $ilDB = $DIC['ilDB'];
47
48 parent::__construct($a_obj_id);
49 $this->db = $ilDB;
50 $this->tree = $DIC->repositoryTree();
51 $this->ilObjDataCache = $DIC['ilObjDataCache'];
52 }
53
54
55 public static function _getNotAttempted($a_obj_id): array
56 {
57 $users = array();
58
59 $members = self::getMembers($a_obj_id);
60 if ($members) {
61 // diff in progress and completed (use stored result in LPStatusWrapper)
62 $users = array_diff((array) $members, ilLPStatusWrapper::_getInProgress($a_obj_id));
63 $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
64 $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
65 }
66
67 return $users;
68 }
69
70 public static function _getInProgress($a_obj_id)
71 {
72 include_once './Services/Tracking/classes/class.ilChangeEvent.php';
73 $users = ilChangeEvent::lookupUsersInProgress($a_obj_id);
74
75 include_once './Services/Object/classes/class.ilObjectLP.php';
76 $olp = ilObjectLP::getInstance($a_obj_id);
77 $collection = $olp->getCollectionInstance();
78 if ($collection) {
79 foreach ($collection->getItems() as $item_id) {
80 $item_id = ilObject::_lookupObjId($item_id);
81
82 // merge arrays of users with status 'in progress'
83 $users = array_unique(array_merge((array) $users, ilLPStatusWrapper::_getInProgress($item_id)));
84 $users = array_unique(array_merge((array) $users, ilLPStatusWrapper::_getCompleted($item_id)));
85 }
86 }
87
88 // Exclude all users with status completed.
89 $users = array_diff((array) $users, ilLPStatusWrapper::_getCompleted($a_obj_id));
90 // Exclude all users with status failed.
91 $users = array_diff((array) $users, ilLPStatusWrapper::_getFailed($a_obj_id));
92
93 if ($users) {
94 // Exclude all non members
95 $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
96 }
97
98 return $users;
99 }
100
108 public static function _getCompleted($a_obj_id)
109 {
110 global $DIC;
111
112 $ilObjDataCache = $DIC['ilObjDataCache'];
113
114 include_once './Services/Object/classes/class.ilObjectLP.php';
115 $olp = ilObjectLP::getInstance($a_obj_id);
116 $collection = $olp->getCollectionInstance();
117 if ($collection) {
118 $grouped_items = $collection->getGroupedItemsForLPStatus();
119 }
120 if (!sizeof($grouped_items)) {
121 // #11513 - empty collections cannot be completed
122 return array();
123 } else {
124 // New handling for optional assignments
125 $counter = 0;
126 $users = array();
127 foreach ($grouped_items as $grouping_id => $grouping) {
128 $isGrouping = $grouping_id ? true : false;
129 $grouping_completed = array();
130 $grouping_completed_users_num = array();
131 foreach ((array) $grouping['items'] as $item) {
132 $item_id = $ilObjDataCache->lookupObjId($item);
133 $tmp_users = ilLPStatusWrapper::_getCompleted($item_id);
134 if ($isGrouping) {
135 // Iterated through all grouped items and count the number of fullfiled items
136 foreach ($tmp_users as $tmp_user_id) {
137 ++$grouping_completed_users_num[$tmp_user_id];
138 }
139 } else {
140 if (!$counter++) {
141 $users = $tmp_users;
142 } else {
143 $users = array_intersect($users, $tmp_users);
144 }
145 }
146 }
147 if ($isGrouping) {
148 // Iterate through all "grouping_completed_users_num"
149 // All users with completed items greater equal than "num_obligatory" are completed
150 foreach ($grouping_completed_users_num as $tmp_user_id => $grouping_num_completed) {
151 if ($grouping_num_completed >= $grouping['num_obligatory']) {
152 $grouping_completed[] = $tmp_user_id;
153 }
154 }
155
156 // build intersection of users
157 if (!$counter++) {
158 $users = $grouping_completed;
159 } else {
160 $users = array_intersect($users, $grouping_completed);
161 }
162 }
163 }
164 }
165
166 $users = array_diff($users, ilLPStatusWrapper::_getFailed($a_obj_id));
167
168 if ($users) {
169 // Exclude all non members
170 $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
171 }
172
173 return (array) $users;
174 }
175
176 public static function _getFailed($a_obj_id)
177 {
178 global $DIC;
179
180 $ilObjDataCache = $DIC['ilObjDataCache'];
181
182 $users = array();
183
184 include_once './Services/Object/classes/class.ilObjectLP.php';
185 $olp = ilObjectLP::getInstance($a_obj_id);
186 $collection = $olp->getCollectionInstance();
187 if ($collection) {
188 foreach ($collection->getGroupedItemsForLPStatus() as $grouping_id => $grouping) {
189 $isGrouping = $grouping_id ? true : false;
190
191 $gr_failed = array();
192 $gr_failed_users_num = array();
193 $counter = 0;
194 foreach ((array) $grouping['items'] as $item) {
195 $item_id = $ilObjDataCache->lookupObjId($item);
196 $tmp_users = ilLPStatusWrapper::_getFailed($item_id);
197
198 if ($isGrouping) {
199 foreach ($tmp_users as $tmp_user_id) {
200 ++$gr_failed_users_num[$tmp_user_id];
201 }
202 } else {
203 // One item failed is sufficient for status failed.
204 $gr_failed = array_merge($gr_failed, $tmp_users);
205 }
206 $counter++;
207 }
208 if ($isGrouping) {
209 $allowed_failed = count($grouping['items']) - $grouping['num_obligatory'];
210 // Itereate over all failed users and check whether the allowd_failed value exceeded
211 foreach ($gr_failed_users_num as $tmp_user_id => $num_failed) {
212 if ($num_failed > $allowed_failed) {
213 $gr_failed[] = $tmp_user_id;
214 }
215 }
216 }
217 $users = array_unique(array_merge($users, $gr_failed));
218 }
219 }
220
221 if ($users) {
222 // Exclude all non members
223 $users = array_intersect(self::getMembers($a_obj_id), (array) $users);
224 }
225
226 return array_unique($users);
227 }
228
229 public static function _getStatusInfo($a_obj_id)
230 {
231 $status_info = array();
232
233 include_once './Services/Object/classes/class.ilObjectLP.php';
234 $olp = ilObjectLP::getInstance($a_obj_id);
235 $collection = $olp->getCollectionInstance();
236 if ($collection) {
237 $status_info['collections'] = $collection->getItems();
238 $status_info['num_collections'] = count($status_info['collections']);
239 }
240
241 return $status_info;
242 }
243
244 public static function _getTypicalLearningTime($a_obj_id)
245 {
246 global $DIC;
247
248 $ilObjDataCache = $DIC['ilObjDataCache'];
249
250 if ($ilObjDataCache->lookupType($a_obj_id) == 'sahs') {
251 return parent::_getTypicalLearningTime($a_obj_id);
252 }
253
254 $tlt = 0;
255 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
256 foreach ($status_info['collections'] as $item) {
258 }
259 return $tlt;
260 }
261
270 public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
271 {
272 global $DIC;
273
274 $ilObjDataCache = $DIC['ilObjDataCache'];
275
276 $status['completed'] = true;
277 $status['failed'] = false;
278 $status['in_progress'] = false;
279
280 switch ($ilObjDataCache->lookupType($a_obj_id)) {
281 case "crs":
282 case "fold":
283 case "grp":
284 case "lso":
285 include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
286 if (ilChangeEvent::hasAccessed($a_obj_id, $a_user_id)) {
287 $status['in_progress'] = true;
288 }
289
290 include_once './Services/Object/classes/class.ilObjectLP.php';
291 $olp = ilObjectLP::getInstance($a_obj_id);
292 $collection = $olp->getCollectionInstance();
293 if ($collection) {
294 $grouped_items = $collection->getGroupedItemsForLPStatus();
295 }
296 if (!sizeof($grouped_items)) {
297 // #11513 - empty collections cannot be completed
298 $status['completed'] = false;
299 } else {
300 foreach ($grouped_items as $grouping_id => $grouping) {
301 $isGrouping = $grouping_id ? true : false;
302 $status = self::determineGroupingStatus($status, $grouping, $a_user_id, $isGrouping);
303 }
304 }
305
306 if ($status['completed']) {
307 if (!$this->isMember((int) $a_obj_id, (int) $a_user_id)) {
309 }
310
312 }
313
314 if ($status['failed']) {
316 }
317
318 if ($status['in_progress']) {
320 }
321 break;
322 }
324 }
325
335 public static function determineGroupingStatus($status, $gr_info, $user_id, $is_grouping)
336 {
337 global $DIC;
338
339 $ilObjDataCache = $DIC['ilObjDataCache'];
340
341 $items = $gr_info['items'];
342 if ($is_grouping) {
343 $max_allowed_failed = count($items) - $gr_info['num_obligatory'];
344 $required_completed = $gr_info['num_obligatory'];
345 } else {
346 $max_allowed_failed = 0;
347 $required_completed = count($items);
348 }
349
350 // Required for grouping with a number of obligatory items
351 $num_failed = 0;
352 $num_completed = 0;
353
354 foreach ($items as $item_id) {
355 $item_id = $ilObjDataCache->lookupObjId($item_id);
356 $gr_status = ilLPStatusWrapper::_determineStatus($item_id, $user_id);
357
358 if ($gr_status == self::LP_STATUS_FAILED_NUM) {
359 if (++$num_failed > $max_allowed_failed) {
360 $status['failed'] = true;
361 $status['completed'] = false;
362 return $status;
363 }
364 }
365 if ($gr_status == self::LP_STATUS_COMPLETED_NUM) {
366 if (++$num_completed >= $required_completed) {
367 return $status;
368 }
369 }
370 }
371 // Not completed since returned above
372 $status['completed'] = false;
373 return $status;
374 }
375
381 protected function isMember(int $objId, int $usrId): bool
382 {
383 switch ($this->ilObjDataCache->lookupType($objId)) {
384 case 'crs':
385 $participants = ilCourseParticipant::_getInstanceByObjId($objId, $usrId);
386 return $participants->isMember();
387
388 case 'grp':
390 return $participants->isMember($usrId);
391
392 case 'fold':
393 $folderRefIds = ilObject::_getAllReferences($objId);
394 $folderRefId = current($folderRefIds);
395 if ($crsRefId = $this->tree->checkForParentType($folderRefId, 'crs')) {
396 $participants = ilCourseParticipant::_getInstanceByObjId(ilObject::_lookupObjId($crsRefId), $usrId);
397 return $participants->isMember();
398 }
399
400 if ($grpRefId = $this->tree->checkForParentType($folderRefId, 'grp')) {
402 return $participants->isMember($usrId);
403 }
404 break;
405
406 case 'lso':
408 return $participants->isMember($usrId);
409 }
410
411 return true;
412 }
413
419 protected static function getMembers($a_obj_id)
420 {
421 global $DIC;
422
423 $ilObjDataCache = $DIC['ilObjDataCache'];
424 $tree = $DIC['tree'];
425
426 switch ($ilObjDataCache->lookupType($a_obj_id)) {
427 case 'crs':
428 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
429 $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
430 return $member_obj->getMembers();
431
432 case 'grp':
433 include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
434 $member_obj = ilGroupParticipants::_getInstanceByObjId($a_obj_id);
435 return $member_obj->getMembers();
436
437 case 'fold':
438 $folder_ref_ids = ilObject::_getAllReferences($a_obj_id);
439 $folder_ref_id = current($folder_ref_ids);
440 if ($crs_id = $tree->checkForParentType($folder_ref_id, 'crs')) {
441 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
443 return $member_obj->getMembers();
444 }
445 break;
446
447 case 'lso':
449 return $member_obj->getMembers();
450 break;
451 }
452
453 return array();
454 }
455
463 public static function _lookupCompletedForObject($a_obj_id, $a_user_ids = null)
464 {
465 if (!$a_user_ids) {
466 $a_user_ids = self::getMembers($a_obj_id);
467 if (!$a_user_ids) {
468 return array();
469 }
470 }
471 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
472 }
473
481 public static function _lookupFailedForObject($a_obj_id, $a_user_ids = null)
482 {
483 if (!$a_user_ids) {
484 $a_user_ids = self::getMembers($a_obj_id);
485 if (!$a_user_ids) {
486 return array();
487 }
488 }
489 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_FAILED_NUM, $a_user_ids);
490 }
491
499 public static function _lookupInProgressForObject($a_obj_id, $a_user_ids = null)
500 {
501 if (!$a_user_ids) {
502 $a_user_ids = self::getMembers($a_obj_id);
503 if (!$a_user_ids) {
504 return array();
505 }
506 }
507 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
508 }
509}
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static lookupUsersInProgress($a_obj_id)
Lookup users in progress.
static hasAccessed($a_obj_id, $a_usr_id)
Has accessed.
static _getInstanceByObjId($a_obj_id, $a_usr_id)
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
isMember(int $objId, int $usrId)
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
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB
$objId
Definition: xapitoken.php:39