ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusObjectives.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
27{
28 public static function _getNotAttempted(int $a_obj_id): array
29 {
30 $users = array();
31
32 $members = self::getMembers($a_obj_id);
33 if ($members) {
34 // diff in progress, completed and failed (use stored result in LPStatusWrapper)
35 $users = array_diff(
36 (array) $members,
38 );
39 $users = array_diff(
40 (array) $members,
42 );
43 $users = array_diff(
44 (array) $members,
46 );
47 }
48 return $users;
49 }
50
51 public static function _getInProgress(int $a_obj_id): array
52 {
53 $objective_results = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
54 $usr_ids = (array) ($objective_results['user_status'][self::LP_STATUS_IN_PROGRESS_NUM] ?? []);
55
56 if ($usr_ids) {
57 // Exclude all non members
58 $usr_ids = array_intersect(self::getMembers($a_obj_id), $usr_ids);
59 }
60
61 if ($usr_ids) {
62 return $usr_ids;
63 } else {
64 return array();
65 }
66 }
67
68 public static function _getCompleted(int $a_obj_id): array
69 {
70 $objective_results = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
71 $usr_ids = (array) ($objective_results['user_status'][self::LP_STATUS_COMPLETED_NUM] ?? []);
72
73 if ($usr_ids) {
74 // Exclude all non members
75 $usr_ids = array_intersect(self::getMembers($a_obj_id), $usr_ids);
76 }
77
78 return $usr_ids ?: array();
79 }
80
81 public static function _getFailed(int $a_obj_id): array
82 {
83 $objective_results = ilLPStatusWrapper::_getStatusInfo($a_obj_id);
84 $usr_ids = (array) ($objective_results['user_status'][self::LP_STATUS_FAILED_NUM] ?? []);
85
86 if ($usr_ids) {
87 // Exclude all non members
88 $usr_ids = array_intersect(self::getMembers($a_obj_id), $usr_ids);
89 }
90
91 return $usr_ids;
92 }
93
94 public static function _getStatusInfo(int $a_obj_id): array
95 {
96 global $DIC;
97
98 $ilDB = $DIC['ilDB'];
99
100 $status_info = array();
101 $status_info['user_status'] = array();
102 $status_info['objectives'] = ilCourseObjective::_getObjectiveIds(
103 $a_obj_id,
104 true
105 );
106 $status_info['num_objectives'] = count($status_info['objectives']);
107
108 if ($status_info['num_objectives']) {
109 $in = $ilDB->in(
110 'objective_id',
111 $status_info['objectives'],
112 false,
113 'integer'
114 );
115
117 $a_obj_id,
118 $status_info['objectives']
119 ) as $user_id => $user_status) {
120 $status_info['user_status'][$user_status][] = $user_id;
121 }
122
123 // change event should lead to "in progress" - see determineStatus()
125 $a_obj_id
126 ) as $user_id) {
127 if (!isset(
128 $status_info['user_status'][ilLPStatus::LP_STATUS_IN_PROGRESS_NUM]
129 ) ||
130 !in_array(
131 $user_id,
132 $status_info['user_status'][ilLPStatus::LP_STATUS_IN_PROGRESS_NUM]
133 )) {
134 $status_info['user_status'][ilLPStatus::LP_STATUS_IN_PROGRESS_NUM][] = $user_id;
135 }
136 }
137
138 // Read title/description
139 $query = "SELECT * FROM crs_objectives WHERE " . $in;
140 $res = $ilDB->query($query);
141 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
142 $status_info['objective_title'][$row->objective_id] = $row->title;
143 $status_info['objective_description'][$row->objective_id] = $row->description;
144 }
145 }
146 return $status_info;
147 }
148
149 public function determineStatus(
150 int $a_obj_id,
151 int $a_usr_id,
152 ?object $a_obj = null
153 ): int {
154 // the status completed depends on:
155 // $status_info['num_objectives'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
156 // - ilCourseObjective::_getObjectiveIds($a_obj_id);
157 // - table crs_objectives manipulated in
158 // - ilCourseObjective
159
160 // $status_info['objective_result'] (ilLPStatusWrapper::_getStatusInfo($a_obj_id);)
161 // table crs_objective_status (must not contain a dataset)
162 // ilCourseObjectiveResult -> added ilLPStatusWrapper::_updateStatus()
163
164 $status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
165 switch ($this->ilObjDataCache->lookupType($a_obj_id)) {
166 case "crs":
167 if (ilChangeEvent::hasAccessed($a_obj_id, $a_usr_id)) {
168 // an initial test (only) should also lead to "in progress"
170
172 $a_obj_id,
173 true
174 );
175 if ($objectives) {
176 // #14051 - getSummarizedObjectiveStatusForLP() might return null
178 $a_obj_id,
180 $a_usr_id
181 );
182 if ($objtv_status !== null) {
183 $status = $objtv_status;
184 }
185 }
186 }
187 break;
188 }
189 return $status;
190 }
191
196 protected static function getMembers(int $a_obj_id): array
197 {
198 $member_obj = ilCourseParticipants::_getInstanceByObjId($a_obj_id);
199 return $member_obj->getMembers();
200 }
201
205 public static function _lookupCompletedForObject(
206 int $a_obj_id,
207 ?array $a_user_ids = null
208 ): array {
209 if (!$a_user_ids) {
210 $a_user_ids = self::getMembers($a_obj_id);
211 if (!$a_user_ids) {
212 return array();
213 }
214 }
215 return self::_lookupStatusForObject(
216 $a_obj_id,
217 self::LP_STATUS_COMPLETED_NUM,
218 $a_user_ids
219 );
220 }
221
225 public static function _lookupFailedForObject(
226 int $a_obj_id,
227 ?array $a_user_ids = null
228 ): array {
229 return array();
230 }
231
235 public static function _lookupInProgressForObject(
236 int $a_obj_id,
237 ?array $a_user_ids = null
238 ): array {
239 if (!$a_user_ids) {
240 $a_user_ids = self::getMembers($a_obj_id);
241 if (!$a_user_ids) {
242 return array();
243 }
244 }
245 return self::_lookupStatusForObject(
246 $a_obj_id,
247 self::LP_STATUS_IN_PROGRESS_NUM,
248 $a_user_ids
249 );
250 }
251}
static hasAccessed(int $a_obj_id, int $a_usr_id)
Has accessed.
static lookupUsersInProgress(int $a_obj_id)
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
static _getInstanceByObjId(int $a_obj_id)
static getSummarizedObjectiveStatusForLP(int $a_obj_id, array $a_objective_ids, int $a_user_id=0)
determineStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getFailed(int $a_obj_id)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get failed users for object.
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get completed users for object.
static _getStatusInfo(int $a_obj_id)
static _getCompleted(int $a_obj_id)
static _getInProgress(int $a_obj_id)
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
Get in progress users for object.
static getMembers(int $a_obj_id)
static _getNotAttempted(int $a_obj_id)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status 'in_progress'.
static _getFailed(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _getStatusInfo(int $a_obj_id)
Reads informations about the object e.g test results, tlt, number of visits.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$objectives