ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPObjectStatisticsDailyTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
29{
30 protected ?array $preselected;
31
35 public function __construct(
36 ?object $a_parent_obj,
37 string $a_parent_cmd,
38 ?array $a_preselect = null,
39 bool $a_load_items = true
40 ) {
41 $this->preselected = $a_preselect;
42
43 $this->setId("lpobjstatdlytbl");
44 parent::__construct($a_parent_obj, $a_parent_cmd);
45 }
46
47 public function init(): void
48 {
49 $this->setShowRowsSelector(true);
50 $this->initFilter();
51
52 $this->addColumn("", "", "1", true);
53 $this->addColumn($this->lng->txt("trac_title"), "title");
54
55 $all_columns = $this->getSelectableColumns();
56 foreach ($this->getSelectedColumns() as $col_name => $col_info) {
57 $column_definition = $all_columns[$col_name];
58 $this->addColumn(
59 $column_definition['txt'],
60 $column_definition['sortable'] ? $column_definition['field'] : '',
61 $column_definition['width']
62 );
63 }
64 for ($loop = 0; $loop < 24; $loop += 2) {
65 $this->addColumn(
66 str_pad((string) $loop, 2, "0", STR_PAD_LEFT) . ":00-<br />" .
67 str_pad((string) ($loop + 2), 2, "0", STR_PAD_LEFT) . ":00 ",
68 "hour" . $loop
69 );
70 }
71 $this->addColumn($this->lng->txt("total"), "sum");
72 $this->setTitle($this->lng->txt("trac_object_stat_daily"));
73
74 // $this->setSelectAllCheckbox("item_id");
75 $this->addMultiCommand(
76 "showDailyGraph",
77 $this->lng->txt("trac_show_graph")
78 );
79 $this->setResetCommand("resetDailyFilter");
80 $this->setFilterCommand("applyDailyFilter");
81
82 $this->setFormAction(
83 $this->ctrl->getFormAction(
84 $this->getParentObject(),
85 $this->getParentCmd()
86 )
87 );
88 $this->setRowTemplate(
89 "tpl.lp_object_statistics_daily_row.html",
90 "components/ILIAS/Tracking"
91 );
92 $this->setEnableHeader(true);
93 $this->setEnableNumInfo(true);
94 $this->setEnableTitle(true);
95 $this->setDefaultOrderField("title");
96 $this->setDefaultOrderDirection("asc");
97
98 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
99 }
100
101 protected function isForwardingToFormDispatcher(): bool
102 {
103 return true;
104 }
105
106 public function getSelectableColumns(): array
107 {
108 $columns = [];
109 $columns['obj_id'] = [
110 'field' => 'obj_id',
111 'txt' => $this->lng->txt('object_id'),
112 'default' => false,
113 'optional' => true,
114 'sortable' => true,
115 'width' => '5%'
116 ];
117 $columns['reference_ids'] = [
118 'field' => 'reference_ids',
119 'txt' => $this->lng->txt('trac_reference_ids_column'),
120 'default' => false,
121 'optional' => true,
122 'sortable' => true,
123 'width' => '5%'
124 ];
125 $columns['paths'] = [
126 'field' => 'paths',
127 'txt' => $this->lng->txt('trac_paths'),
128 'default' => false,
129 'optional' => true,
130 'sortable' => false,
131 'width' => '25%'
132 ];
133 return $columns;
134 }
135
136
137 public function numericOrdering(string $a_field): bool
138 {
139 $alphabetic_ordering = [
140 'title'
141 ];
142 if (!in_array($a_field, $alphabetic_ordering)) {
143 return true;
144 }
145 return false;
146 }
147
151 public function initFilter(): void
152 {
153 $this->setDisableFilterHiding(true);
154
155 // object type selection
156 $si = new ilSelectInputGUI($this->lng->txt("obj_type"), "type");
157 $si->setOptions($this->getPossibleTypes(true, false, true));
158 $this->addFilterItem($si);
159 $si->readFromSession();
160 if (!$si->getValue()) {
161 $si->setValue("crs");
162 }
163 $this->filter["type"] = $si->getValue();
164
165 // title/description
166 $ti = new ilTextInputGUI(
167 $this->lng->txt("trac_title_description"),
168 "query"
169 );
170 $ti->setMaxLength(64);
171 $ti->setSize(20);
172 $this->addFilterItem($ti);
173 $ti->readFromSession();
174 $this->filter["query"] = $ti->getValue();
175
176 // read_count/spent_seconds
177 $si = new ilSelectInputGUI($this->lng->txt("trac_figure"), "figure");
178 $si->setOptions(
179 array("read_count" => $this->lng->txt("trac_read_count"),
180 "spent_seconds" => $this->lng->txt("trac_spent_seconds")
181 )
182 );
183 $this->addFilterItem($si);
184 $si->readFromSession();
185 if (!$si->getValue()) {
186 $si->setValue("read_count");
187 }
188 $this->filter["measure"] = $si->getValue();
189
190 // year/month
191 $si = new ilSelectInputGUI(
192 $this->lng->txt("year") . " / " . $this->lng->txt("month"),
193 "yearmonth"
194 );
195 $si->setOptions($this->getMonthsFilter());
196 $this->addFilterItem($si);
197 $si->readFromSession();
198 if (!$si->getValue()) {
199 $si->setValue(date("Y-m"));
200 }
201 $this->filter["yearmonth"] = $si->getValue();
202 $this->filter = $this->initRepositoryFilter($this->filter);
203 }
204
205 public function getItems(): void
206 {
207 $data = array();
208
209 $objects = [];
210 if ($this->filter["type"] != "prtf") {
211 // JF, 2016-06-06
212 $objects = $this->searchObjects(
213 $this->getCurrentFilter(true),
214 "",
215 null,
216 false
217 );
218
219 if ($this->filter["type"] == "blog") {
221 $this->filter["query"]
222 ) as $obj_id) {
223 $objects[$obj_id] = array($obj_id);
224 }
225 }
226 } else {
227 // portfolios are not part of repository
229 $this->filter["query"]
230 ) as $obj_id) {
231 $objects[$obj_id] = array($obj_id);
232 }
233 }
234
235 if ($objects) {
236 $yearmonth = explode("-", $this->filter["yearmonth"]);
237 if (sizeof($yearmonth) == 1) {
239 $objects,
240 $yearmonth[0]
241 );
242 } else {
244 $objects,
245 (string) $yearmonth[0],
246 (string) $yearmonth[1]
247 );
248 }
249
250 foreach ($stat_objects as $obj_id => $hours) {
251 $data[$obj_id]["obj_id"] = $obj_id;
252 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
253 $data[$obj_id]['reference_ids'] = $this->findReferencesForObjId($obj_id);
254
255 foreach ($hours as $hour => $values) {
256 // table data
257 $hour_transf = floor($hour / 2) * 2;
258 $data[$obj_id]["hour" . $hour_transf] =
259 ($data[$obj_id]["hour" . $hour_transf] ?? 0) + (int) $values[$this->filter["measure"]];
260 $data[$obj_id]["sum"] =
261 ($data[$obj_id]["sum"] ?? 0) + (int) $values[$this->filter["measure"]];
262
263 // graph data
264 $data[$obj_id]["graph"]["hour" . $hour] = $values[$this->filter["measure"]];
265 }
266 }
267
268 // add objects with no usage data
269 foreach ($objects as $obj_id => $ref_ids) {
270 if (!isset($data[$obj_id])) {
271 $data[$obj_id]["obj_id"] = $obj_id;
272 $data[$obj_id]['reference_ids'] = $this->findReferencesForObjId($obj_id);
273 $data[$obj_id]["title"] = ilObject::_lookupTitle($obj_id);
274 }
275 }
276 }
277 $this->setData($data);
278 }
279
283 protected function fillRow(array $a_set): void
284 {
285 $type = ilObject::_lookupType($a_set["obj_id"]);
286 $this->tpl->setVariable("OBJ_ID", $a_set["obj_id"]);
287 $this->tpl->setVariable(
288 "ICON_SRC",
289 ilObject::_getIcon(0, "tiny", $type)
290 );
291 $this->tpl->setVariable("ICON_ALT", $this->lng->txt($type));
292 $this->tpl->setVariable("TITLE_TEXT", $a_set["title"]);
293
294 if ($this->preselected && in_array(
295 $a_set["obj_id"],
296 $this->preselected
297 )) {
298 $this->tpl->setVariable("CHECKBOX_STATE", " checked=\"checked\"");
299 }
300
301 $this->tpl->setCurrentBlock("hour");
302 for ($loop = 0; $loop < 24; $loop += 2) {
303 $value = (int) ($a_set["hour" . $loop] ?? 0);
304 if ($this->filter["measure"] != "spent_seconds") {
305 $value = $this->anonymizeValue($value);
306 } else {
307 $value = $this->formatSeconds($value, true);
308 }
309 $this->tpl->setVariable("HOUR_VALUE", $value);
310 $this->tpl->parseCurrentBlock();
311 }
312
313 if ($this->filter["measure"] == "spent_seconds") {
314 $sum = $this->formatSeconds((int) ($a_set["sum"] ?? 0), true);
315 } else {
316 $sum = $this->anonymizeValue((int) ($a_set["sum"] ?? 0));
317 }
318 $this->tpl->setVariable("TOTAL", $sum);
319
320 // optional columns
321 if ($this->isColumnSelected('obj_id')) {
322 $this->tpl->setVariable('OBJ_ID_COL_VALUE', (string) $a_set['obj_id']);
323 }
324 if ($this->isColumnSelected('reference_ids')) {
325 $this->tpl->setVariable('REF_IDS', implode(', ', $a_set['reference_ids']));
326 }
327 if ($this->isColumnSelected('paths')) {
328 $paths = [];
329 foreach ($a_set['reference_ids'] as $reference_id) {
330 $path_gui = new ilPathGUI();
331 $path_gui->enableTextOnly(false);
332 $path_gui->enableHideLeaf(false);
333 $path_gui->setUseImages(true);
334 $paths[] = $path_gui->getPath(ROOT_FOLDER_ID, $reference_id);
335 }
336 $this->tpl->setVariable('PATHS', implode('<br />', $paths));
337 }
338 }
339
340 public function getGraph(array $a_graph_items): string
341 {
342 global $DIC;
343
344 $lng = $DIC['lng'];
345
347 $chart->setSize("700", "500");
348
349 $legend = new ilChartLegend();
350 $chart->setLegend($legend);
351
352 $max_value = 0;
353 foreach ($this->getData() as $object) {
354 if (in_array($object["obj_id"], $a_graph_items)) {
355 $series = $chart->getDataInstance(ilChartGrid::DATA_LINES);
356 $series->setLabel(ilObject::_lookupTitle($object["obj_id"]));
357
358 for ($loop = 0; $loop < 24; $loop++) {
359 $value = (int) ($object["graph"]["hour" . $loop] ?? 0);
360 $max_value = max($max_value, $value);
361 if ($this->filter["measure"] != "spent_seconds") {
362 $value = $this->anonymizeValue($value, true);
363 }
364 $series->addPoint($loop, $value);
365 }
366
367 $chart->addData($series);
368 }
369 }
370
371 $value_ticks = $this->buildValueScale(
372 $max_value,
373 ($this->filter["measure"] != "spent_seconds"),
374 ($this->filter["measure"] == "spent_seconds")
375 );
376
377 $labels = array();
378 for ($loop = 0; $loop < 24; $loop++) {
379 $labels[$loop] = str_pad((string) $loop, 2, "0", STR_PAD_LEFT);
380 }
381 $chart->setTicks($labels, $value_ticks, true);
382
383 return $chart->getHTML();
384 }
385
386 protected function fillMetaExcel(ilExcel $a_excel, int &$a_row): void
387 {
388 }
389
390 protected function fillRowExcel(
391 ilExcel $a_excel,
392 int &$a_row,
393 array $a_set
394 ): void {
395 $a_excel->setCell($a_row, 0, ilObject::_lookupTitle($a_set["obj_id"]));
396
397 $col = 0;
398
399 // optional columns
400 if ($this->isColumnSelected('obj_id')) {
401 $a_excel->setCell($a_row, ++$col, (string) $a_set['obj_id']);
402 }
403 if ($this->isColumnSelected('reference_ids')) {
404 $a_excel->setCell($a_row, ++$col, implode(', ', $a_set['reference_ids']));
405 }
406 if ($this->isColumnSelected('paths')) {
407 $paths = [];
408 foreach ($a_set['reference_ids'] as $reference_id) {
409 $path_gui = new ilPathGUI();
410 $path_gui->enableTextOnly(true);
411 $path_gui->enableHideLeaf(false);
412 $path_gui->setUseImages(false);
413 $paths[] = $path_gui->getPath(ROOT_FOLDER_ID, $reference_id);
414 }
415 /*
416 * The strings returned by the PathGUI have a linebreak at the end,
417 * which has to be removed or it messes up how the paths are displayed in excel.
418 */
419 $a_excel->setCell($a_row, ++$col, substr(implode(', ', $paths), 0, -1));
420 }
421
422 for ($loop = 0; $loop < 24; $loop += 2) {
423 $value = (int) ($a_set["hour" . $loop] ?? 0);
424 if ($this->filter["measure"] != "spent_seconds") {
425 $value = $this->anonymizeValue($value);
426 }
427
428 $a_excel->setCell($a_row, ++$col, $value);
429 }
430
431 if ($this->filter["measure"] == "spent_seconds") {
432 // keep seconds
433 // $sum = $this->formatSeconds((int)$a_set["sum"]);
434 $sum = (int) ($a_set["sum"] ?? 0);
435 } else {
436 $sum = $this->anonymizeValue((int) ($a_set["sum"] ?? 0));
437 }
438 $a_excel->setCell($a_row, ++$col, $sum);
439 }
440
441 protected function fillMetaCSV(ilCSVWriter $a_csv): void
442 {
443 }
444
445 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
446 {
447 $a_csv->addColumn(ilObject::_lookupTitle($a_set["obj_id"]));
448
449 // optional columns
450 if ($this->isColumnSelected('obj_id')) {
451 $a_csv->addColumn($a_set["obj_id"]);
452 }
453 if ($this->isColumnSelected('reference_ids')) {
454 $a_csv->addColumn(implode(', ', $a_set['reference_ids']));
455 }
456 if ($this->isColumnSelected('paths')) {
457 $paths = [];
458 foreach ($a_set['reference_ids'] as $reference_id) {
459 $path_gui = new ilPathGUI();
460 $path_gui->enableTextOnly(true);
461 $path_gui->enableHideLeaf(false);
462 $path_gui->setUseImages(false);
463 $paths[] = $path_gui->getPath(ROOT_FOLDER_ID, $reference_id);
464 }
465 /*
466 * The strings returned by the PathGUI have a linebreak at the end,
467 * which has to be removed or it messes up how the paths are displayed in excel.
468 */
469 $a_csv->addColumn(substr(implode(', ', $paths), 0, -1));
470 }
471
472 for ($loop = 0; $loop < 24; $loop += 2) {
473 $value = (int) ($a_set["hour" . $loop] ?? 0);
474 if ($this->filter["measure"] != "spent_seconds") {
475 $value = $this->anonymizeValue($value);
476 }
477
478 $a_csv->addColumn($value);
479 }
480
481 if ($this->filter["measure"] == "spent_seconds") {
482 // keep seconds
483 // $sum = $this->formatSeconds((int)$a_set["sum"]);
484 $sum = (int) ($a_set["sum"] ?? 0);
485 } else {
486 $sum = $this->anonymizeValue((int) ($a_set["sum"] ?? 0));
487 }
488 $a_csv->addColumn($sum);
489
490 $a_csv->addRow();
491 }
492}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_col)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByType(int $a_type, string $a_id)
const TYPE_GRID
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
fillMetaExcel(ilExcel $a_excel, int &$a_row)
Add meta information to excel export.
numericOrdering(string $a_field)
Should this field be sorted numeric?
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
__construct(?object $a_parent_obj, string $a_parent_cmd, ?array $a_preselect=null, bool $a_load_items=true)
Constructor.
fillMetaCSV(ilCSVWriter $a_csv)
Add meta information to csv export.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
TableGUI class for learning progress.
formatSeconds(int $seconds, bool $a_shorten_zero=false)
anonymizeValue($a_value, bool $a_force_number=false)
initRepositoryFilter(array $filter)
getPossibleTypes(bool $a_split_learning_resources=false, bool $a_include_digilib=false, bool $a_allow_undefined_lp=false)
findReferencesForObjId(int $a_obj_id)
getCurrentFilter(bool $as_query=false)
getMonthsFilter($a_short=false)
buildValueScale(int $a_max_value, bool $a_anonymize=false, bool $a_format_seconds=false)
searchObjects(array $filter, string $permission, ?array $preset_obj_ids=null, bool $a_check_lp_activation=true)
Search objects that match current filters.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupTitle(int $obj_id)
This class represents a selection list property in a property form.
isColumnSelected(string $col)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setFilterCommand(string $a_val, string $a_caption="")
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
setExportFormats(array $formats)
Set available export formats.
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
setDisableFilterHiding(bool $a_val=true)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
ilLanguage $lng
This class represents a text property in a property form.
static getWorkspaceBlogs(?string $a_title=null)
static getPortfolios(?string $a_title=null)
static getObjectDailyStatistics(array $a_ref_ids, string $a_year, ?string $a_month=null)
const ROOT_FOLDER_ID
Definition: constants.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26