ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
DataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
22
23use ilDateTime;
28use ilObject;
29use ilObjectLP;
30use ilTrQuery;
31
33{
34 protected const KEY_OBJ_ID = "obj_id";
35 protected const KEY_USR_ID = "usr_id";
36 protected const KEY_OBJ_TITLE = "title";
37 protected const KEY_OBJ_DESCRIPTION = "description";
38 protected const KEY_OBJ_TYPE = "type";
39 protected const KEY_LP_STATUS = "status";
40 protected const KEY_LP_MODE = "lp_mode";
41 protected const KEY_LP_SPENT_SECONDS = "spent_seconds";
42 protected const KEY_LP_VISITS = "visits";
43 protected const KEY_LP_READ_COUNT = "read_count";
44 protected const KEY_LP_PERCENTAGE = "percentage";
45 protected const KEY_LP_STATUS_CHANGED = "status_changed";
46
47 public function __construct(
48 protected ilDBInterface $db,
49 protected InfoFactoryInterface $info_factory
50 ) {
51 }
52
53 public function retrieveViewInfo(
54 FilterInterface $filter
55 ): ViewInterface {
56 $object_ids = $filter->getObjectIds();
57 $user_ids = $filter->getUserIds();
58
59 $user_obj_id_mappings = [];
60 foreach ($user_ids as $usr_id) {
61 foreach ($object_ids as $obj_id) {
62 $olp = ilObjectLP::getInstance($obj_id);
63 $lp_mode = $olp->getCurrentMode();
64 $user_obj_id_mappings[$usr_id][$lp_mode][] = $obj_id;
65 }
66 }
67
69 $user_obj_id_mappings,
71 );
72
73 $object_infos = [];
74 $lp_infos = [];
75 $combined_infos = [];
76 foreach ($data as $entry) {
77 $obj_id = (int) $entry[self::KEY_OBJ_ID];
78 $usr_id = (int) $entry[self::KEY_USR_ID];
79 $obj_title = (string) $entry[self::KEY_OBJ_TITLE];
80 $percentage = (int) $entry[self::KEY_LP_PERCENTAGE];
81 $obj_description = ilObject::_lookupDescription($obj_id);
82 $lp_status = (int) $entry[self::KEY_LP_STATUS];
83 $obj_type = (string) $entry[self::KEY_OBJ_TYPE];
84 $lp_mode = (int) $entry[self::KEY_LP_MODE];
85 $spent_seconds = (int) $entry[self::KEY_LP_SPENT_SECONDS];
86 $status_changed = new ilDateTime($entry[self::KEY_LP_STATUS_CHANGED], IL_CAL_DATETIME);
87 $visits = (int) $entry[self::KEY_LP_VISITS];
88 $read_count = (int) $entry[self::KEY_LP_READ_COUNT];
89 $lp_info = $this->info_factory->lp(
90 $usr_id,
91 $obj_id,
92 $lp_status,
93 $percentage,
94 $lp_mode,
95 $spent_seconds,
96 $status_changed,
97 $visits,
98 $read_count,
99 $this->isPercentageAvailable($lp_mode)
100 );
101 $object_info = $this->info_factory->objectData(
102 $obj_id,
103 $obj_title,
104 $obj_description,
105 $obj_type,
106 );
107 $lp_infos[] = $lp_info;
108 $object_infos[] = $object_info;
109 $combined_infos[] = $this->info_factory->combined(
110 $lp_info,
111 $object_info
112 );
113 }
114
115 return $this->info_factory->view(
116 $this->info_factory->iterator()->objectData(...$object_infos),
117 $this->info_factory->iterator()->lp(...$lp_infos),
118 $this->info_factory->iterator()->combined(...$combined_infos)
119 );
120 }
121
122 protected function collectLPDataWithIlTryQuery(
123 array $user_obj_id_mappings,
124 bool $only_data_of_objects_with_lp_enabled = true
125 ): array {
126 $data = [];
127 foreach ($user_obj_id_mappings as $usr_id => $mode_mapping) {
128 foreach ($mode_mapping as $lp_mode => $obj_ids) {
129 $obj_ids = array_flip($obj_ids);
130 $new_data = [];
131 switch ($lp_mode) {
134 $usr_id,
135 0,
136 $obj_ids
137 );
138 break;
141 $usr_id,
142 0,
143 $obj_ids
144 );
145 break;
149 if ($usr_id) {
151 $usr_id,
152 0,
153 $obj_ids
154 );
155 }
156 break;
159 if ($only_data_of_objects_with_lp_enabled) {
160 break;
161 }
162 // no break
163 default:
165 $usr_id,
166 $obj_ids
167 );
168 break;
169 }
170 foreach ($new_data as $new) {
171 $new[self::KEY_LP_MODE] = $lp_mode;
172 $new[self::KEY_USR_ID] = $usr_id;
173 $data[] = $new;
174 }
175 }
176 }
177 return $data;
178 }
179
180 protected function isPercentageAvailable(
181 int $lp_mode
182 ): bool {
183 if (in_array(
184 $lp_mode,
185 [
186 ilLPObjSettings::LP_MODE_TLT,
187 ilLPObjSettings::LP_MODE_VISITS,
188 ilLPObjSettings::LP_MODE_SCORM,
189 ilLPObjSettings::LP_MODE_LTI_OUTCOME,
190 ilLPObjSettings::LP_MODE_CMIX_COMPLETED,
191 ilLPObjSettings::LP_MODE_CMIX_COMPL_WITH_FAILED,
192 ilLPObjSettings::LP_MODE_CMIX_PASSED,
193 ilLPObjSettings::LP_MODE_CMIX_PASSED_WITH_FAILED,
194 ilLPObjSettings::LP_MODE_CMIX_COMPLETED_OR_PASSED,
195 ilLPObjSettings::LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED,
196 ilLPObjSettings::LP_MODE_VISITED_PAGES,
197 ilLPObjSettings::LP_MODE_TEST_PASSED,
198 ilLPObjSettings::LP_MODE_COLLECTION
199 ]
200 )) {
201 return true;
202 }
203 return false;
204 }
205}
collectLPDataWithIlTryQuery(array $user_obj_id_mappings, bool $only_data_of_objects_with_lp_enabled=true)
__construct(protected ilDBInterface $db, protected InfoFactoryInterface $info_factory)
const IL_CAL_DATETIME
@classDescription Date and time handling
const int LP_MODE_COLLECTION_MOBS
const int LP_MODE_COLLECTION_MANUAL
const int LP_MODE_COLLECTION_TLT
Base class for object lp connectors.
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
static _lookupDescription(int $obj_id)
static getSCOsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_sco_ids)
static getObjectivesStatusForUser(int $a_user_id, int $a_obj_id, array $a_objective_ids)
static getSubItemsStatusForUser(int $a_user_id, int $a_parent_obj_id, array $a_item_ids)
Get subitems status.
static getObjectsStatusForUser(int $a_user_id, array $obj_refs)
Interface ilDBInterface.
if(!file_exists('../ilias.ini.php'))
$data
Definition: storeScorm.php:45