ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLPStatusCollectionTLT.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Tracking/classes/class.ilLPStatus.php';
5
16{
17 public static function _getInProgress($a_obj_id)
18 {
19 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
20
21 $users = array();
22 if (is_array($status_info['in_progress'])) {
23 foreach ($status_info['in_progress'] as $in_progress) {
24 $users = array_merge($users, $in_progress);
25 }
26 $users = array_unique($users);
27 }
28
29 $users = array_diff($users, ilLPStatusWrapper::_getCompleted($a_obj_id));
30
31 return $users;
32 }
33
34 public static function _getCompleted($a_obj_id)
35 {
36 $status_info = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
37
38 $counter = 0;
39 $users = array();
40 foreach ($status_info['items'] as $item_id) {
41 $tmp_users = $status_info['completed'][$item_id];
42
43 if (!$counter++) {
44 $users = $tmp_users;
45 } else {
46 $users = array_intersect($users, $tmp_users);
47 }
48 }
49 $users = array_unique($users);
50
51 return $users;
52 }
53
54 public static function _getStatusInfo($a_obj_id, $a_include_tlt_data = false)
55 {
56 global $DIC;
57
58 $ilDB = $DIC['ilDB'];
59
60 $status_info = array();
61
62 include_once "Services/Object/classes/class.ilObjectLP.php";
63 $olp = ilObjectLP::getInstance($a_obj_id);
64 $collection = $olp->getCollectionInstance();
65 if ($collection) {
66 $status_info["items"] = $collection->getItems($a_obj_id);
67
68 include_once './Services/MetaData/classes/class.ilMDEducational.php';
69 foreach ($status_info["items"] as $item_id) {
70 $status_info["in_progress"][$item_id] = array();
71 $status_info["completed"][$item_id] = array();
72
73 $status_info["tlt"][$item_id] = ilMDEducational::_getTypicalLearningTimeSeconds($a_obj_id, $item_id);
74 }
75
76 $ref_ids = ilObject::_getAllReferences($a_obj_id);
77 $ref_id = end($ref_ids);
78 $possible_items = $collection->getPossibleItems($ref_id);
79 $chapter_ids = array_intersect(
80 array_keys($possible_items),
81 $status_info["items"]
82 );
83
84 // fix order (adapt from possible items)
85 $status_info["items"] = $chapter_ids;
86
87 if ($chapter_ids) {
88 foreach ($chapter_ids as $item_id) {
89 $status_info["item_titles"][$item_id] = $possible_items[$item_id]["title"];
90 }
91
92 $set = $ilDB->query("SELECT obj_id,usr_id,spent_seconds" .
93 " FROM lm_read_event" .
94 " WHERE " . $ilDB->in("obj_id", $chapter_ids, "", "integer"));
95 while ($row = $ilDB->fetchAssoc($set)) {
96 if ($row["spent_seconds"] < $status_info["tlt"][$row["obj_id"]]) {
97 $status_info["in_progress"][$row["obj_id"]][] = $row["usr_id"];
98 } else {
99 $status_info["completed"][$row["obj_id"]][] = $row["usr_id"];
100 }
101
102 if ($a_include_tlt_data) {
103 $status_info["tlt_users"][$row["obj_id"]][$row["usr_id"]] = $row["spent_seconds"];
104 }
105 }
106 }
107 }
108
109 if (!$a_include_tlt_data) {
110 unset($status_info["tlt"]);
111 }
112
113 return $status_info;
114 }
115
116 public function determineStatus($a_obj_id, $a_user_id, $a_obj = null)
117 {
118 $info = self::_getStatusInfo($a_obj_id);
119
120 $completed_once = false;
121
122 if (is_array($info["completed"])) {
123 $completed = true;
124 foreach ($info["completed"] as $user_ids) {
125 // must have completed all items to complete collection
126 if (!in_array($a_user_id, $user_ids)) {
127 $completed = false;
128 break;
129 } else {
130 $completed_once = true;
131 }
132 }
133 if ($completed) {
135 }
136 }
137
138 // #14997
139 if ($completed_once) {
141 }
142
143 if (is_array($info["in_progress"])) {
144 foreach ($info["in_progress"] as $user_ids) {
145 if (in_array($a_user_id, $user_ids)) {
147 }
148 }
149 }
150
152 }
153}
An exception for terminatinating execution or to throw for unit testing.
static _getStatusInfo($a_obj_id, $a_include_tlt_data=false)
determineStatus($a_obj_id, $a_user_id, $a_obj=null)
Determine status.
static _getStatusInfo($a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
static _getCompleted($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
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
static _getTypicalLearningTimeSeconds($a_rbac_id, $a_obj_id=0)
static getInstance($a_obj_id)
static _getAllReferences($a_id)
get all reference ids of object
global $ilDB
$DIC
Definition: xapitoken.php:46