ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
22
23use ilDateTime;
30use ilLPMarks;
32use ilObject;
33use ilObjectLP;
34use ilTrQuery;
35
37{
38 protected const KEY_OBJ_ID = "obj_id";
39 protected const KEY_USR_ID = "usr_id";
40 protected const KEY_OBJ_TITLE = "title";
41 protected const KEY_OBJ_DESCRIPTION = "description";
42 protected const KEY_OBJ_TYPE = "type";
43 protected const KEY_LP_STATUS = "status";
44 protected const KEY_LP_MODE = "lp_mode";
45 protected const KEY_LP_SPENT_SECONDS = "spent_seconds";
46 protected const KEY_LP_VISITS = "visits";
47 protected const KEY_LP_READ_COUNT = "read_count";
48 protected const KEY_LP_PERCENTAGE = "percentage";
49 protected const KEY_LP_STATUS_CHANGED = "status_changed";
50
51 public function __construct(
52 protected ilDBInterface $db,
53 protected InfoFactoryInterface $info_factory
54 ) {
55 }
56
57 public function retrieveViewInfo(
58 FilterInterface $filter
59 ): ViewInterface {
60 $object_ids = $filter->getObjectIds();
61 $user_ids = $filter->getUserIds();
62
63 $user_obj_id_mappings = [];
64 foreach ($user_ids as $usr_id) {
65 foreach ($object_ids as $obj_id) {
66 $olp = ilObjectLP::getInstance($obj_id);
67 $lp_mode = $olp->getCurrentMode();
68 $user_obj_id_mappings[$usr_id][$lp_mode][] = $obj_id;
69 }
70 }
71
73 $user_obj_id_mappings,
75 );
76
77 $object_infos = [];
78 $lp_infos = [];
79 $combined_infos = [];
80 foreach ($data as $entry) {
81 $obj_id = (int) $entry[self::KEY_OBJ_ID];
82 $usr_id = (int) $entry[self::KEY_USR_ID];
83 $obj_title = (string) $entry[self::KEY_OBJ_TITLE];
84 $percentage = (int) $entry[self::KEY_LP_PERCENTAGE];
85 $obj_description = ilObject::_lookupDescription($obj_id);
86 $lp_status = (int) $entry[self::KEY_LP_STATUS];
87 $obj_type = (string) $entry[self::KEY_OBJ_TYPE];
88 $lp_mode = (int) $entry[self::KEY_LP_MODE];
89 $spent_seconds = (int) $entry[self::KEY_LP_SPENT_SECONDS];
90 $status_changed = new ilDateTime($entry[self::KEY_LP_STATUS_CHANGED], IL_CAL_DATETIME);
91 $visits = (int) $entry[self::KEY_LP_VISITS];
92 $read_count = (int) $entry[self::KEY_LP_READ_COUNT];
93 $lp_info = $this->info_factory->lp(
94 $usr_id,
95 $obj_id,
96 $lp_status,
97 $percentage,
98 $lp_mode,
99 $spent_seconds,
100 $status_changed,
101 $visits,
102 $read_count,
103 $this->isPercentageAvailable($lp_mode)
104 );
105 $object_info = $this->info_factory->objectData(
106 $obj_id,
107 $obj_title,
108 $obj_description,
109 $obj_type,
110 );
111 $lp_infos[] = $lp_info;
112 $object_infos[] = $object_info;
113 $combined_infos[] = $this->info_factory->combined(
114 $lp_info,
115 $object_info
116 );
117 }
118
119 return $this->info_factory->view(
120 $this->info_factory->iterator()->objectData(...$object_infos),
121 $this->info_factory->iterator()->lp(...$lp_infos),
122 $this->info_factory->iterator()->combined(...$combined_infos)
123 );
124 }
125
126 protected function collectLPDataWithIlTryQuery(
127 array $user_obj_id_mappings,
128 bool $only_data_of_objects_with_lp_enabled = true
129 ): array {
130 $data = [];
131 foreach ($user_obj_id_mappings as $usr_id => $mode_mapping) {
132 foreach ($mode_mapping as $lp_mode => $obj_ids) {
133 $obj_ids = array_flip($obj_ids);
134 $new_data = [];
135 switch ($lp_mode) {
138 $usr_id,
139 0,
140 $obj_ids
141 );
142 break;
145 $usr_id,
146 0,
147 $obj_ids
148 );
149 break;
153 if ($usr_id) {
155 $usr_id,
156 0,
157 $obj_ids
158 );
159 }
160 break;
163 if ($only_data_of_objects_with_lp_enabled) {
164 break;
165 }
166 // no break
167 default:
169 $usr_id,
170 $obj_ids
171 );
172 break;
173 }
174 foreach ($new_data as $new) {
175 $new[self::KEY_LP_MODE] = $lp_mode;
176 $new[self::KEY_USR_ID] = $usr_id;
177 $data[] = $new;
178 }
179 }
180 }
181 return $data;
182 }
183
184 protected function isPercentageAvailable(
185 int $lp_mode
186 ): bool {
187 if (in_array(
188 $lp_mode,
189 [
190 ilLPObjSettings::LP_MODE_TLT,
191 ilLPObjSettings::LP_MODE_VISITS,
192 ilLPObjSettings::LP_MODE_SCORM,
193 ilLPObjSettings::LP_MODE_LTI_OUTCOME,
194 ilLPObjSettings::LP_MODE_CMIX_COMPLETED,
195 ilLPObjSettings::LP_MODE_CMIX_COMPL_WITH_FAILED,
196 ilLPObjSettings::LP_MODE_CMIX_PASSED,
197 ilLPObjSettings::LP_MODE_CMIX_PASSED_WITH_FAILED,
198 ilLPObjSettings::LP_MODE_CMIX_COMPLETED_OR_PASSED,
199 ilLPObjSettings::LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED,
200 ilLPObjSettings::LP_MODE_VISITED_PAGES,
201 ilLPObjSettings::LP_MODE_TEST_PASSED,
202 ilLPObjSettings::LP_MODE_COLLECTION
203 ]
204 )) {
205 return true;
206 }
207 return false;
208 }
209}
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
Class ilDBConstants.
@classDescription Date and time handling
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'))