ILIAS  release_8 Revision v8.24
class.ilLPObjectStatisticsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
4
30{
32
33 public function __construct(int $a_mode, int $a_ref_id = 0)
34 {
35 global $DIC;
36
37 $this->cronManager = $DIC->cron()->manager();
38
39 parent::__construct($a_mode, $a_ref_id);
40
41 if (!$this->ref_id) {
42 if ($this->http->wrapper()->query()->has('ref_id')) {
43 $this->ref_id = $this->http->wrapper()->query()->retrieve(
44 'ref_id',
45 $this->refinery->kindlyTo()->int()
46 );
47 }
48 }
49 }
50
51 protected function initItemIdFromPost(): array
52 {
53 if ($this->http->wrapper()->post()->has('item_id')) {
54 return $this->http->wrapper()->post()->retrieve(
55 'item_id',
56 $this->refinery->kindlyTo()->dictOf(
57 $this->refinery->kindlyTo()->string()
58 )
59 );
60 }
61 return [];
62 }
63
64 protected function setTabs(): void
65 {
66 $this->tabs_gui->addSubTab(
67 'trac_object_stat_access',
68 $this->lng->txt('trac_object_stat_access'),
69 $this->ctrl->getLinkTarget($this, 'accessFilter')
70 );
71 $this->tabs_gui->addSubTab(
72 'trac_object_stat_daily',
73 $this->lng->txt('trac_object_stat_daily'),
74 $this->ctrl->getLinkTarget($this, 'dailyFilter')
75 );
76 $this->tabs_gui->addSubTab(
77 'trac_object_stat_lp',
78 $this->lng->txt('trac_object_stat_lp'),
79 $this->ctrl->getLinkTarget($this, 'learningProgressFilter')
80 );
81 $this->tabs_gui->addSubTab(
82 'trac_object_stat_types',
83 $this->lng->txt('trac_object_stat_types'),
84 $this->ctrl->getLinkTarget($this, 'typesFilter')
85 );
86
87 if ($this->rbacsystem->checkAccess("visible,read", $this->ref_id)) {
88 $this->tabs_gui->addSubTab(
89 'trac_object_stat_admin',
90 $this->lng->txt('trac_object_stat_admin'),
91 $this->ctrl->getLinkTarget($this, 'admin')
92 );
93 }
94 }
95
96 public function executeCommand(): void
97 {
98 $this->ctrl->setReturn($this, "");
99 $this->setTabs();
100
101 switch ($this->ctrl->getNextClass()) {
102 case "illpobjectstatisticstablegui":
103 $lp_table = new ilLPObjectStatisticsTableGUI(
104 $this,
105 "access",
106 null
107 );
108 $lp_table->init();
109 $this->ctrl->forwardCommand($lp_table);
110 break;
111
112 case "illpobjectstatisticsdailytablegui":
113 $lp_table = new ilLPObjectStatisticsDailyTableGUI(
114 $this,
115 "daily",
116 null
117 );
118 $lp_table->init();
119 $this->ctrl->forwardCommand($lp_table);
120 break;
121
122 case "illpobjectstatisticslptablegui":
123 $lp_table = new ilLPObjectStatisticsLPTableGUI(
124 $this,
125 "learningProgress",
126 null
127 );
128 $lp_table->init();
129 $this->ctrl->forwardCommand($lp_table);
130 break;
131
132 default:
133 $cmd = $this->__getDefaultCommand();
134 $this->$cmd();
135 }
136 }
137
138 public function applyAccessFilter(): void
139 {
140 $lp_table = new ilLPObjectStatisticsTableGUI(
141 $this,
142 "access",
143 null
144 );
145 $lp_table->init();
146 $lp_table->resetOffset();
147 $lp_table->writeFilterToSession();
148 $this->access();
149 }
150
151 public function resetAccessFilter(): void
152 {
153 $lp_table = new ilLPObjectStatisticsTableGUI(
154 $this,
155 "access",
156 null
157 );
158 $lp_table->init();
159 $lp_table->resetOffset();
160 $lp_table->resetFilter();
161 $this->access();
162 }
163
164 public function accessFilter(): void
165 {
166 $this->access(false);
167 }
168
169 public function access(bool $a_load_data = true): void
170 {
171 $this->tabs_gui->activateSubTab('trac_object_stat_access');
172 $this->showAggregationInfo();
173 $lp_table = new ilLPObjectStatisticsTableGUI(
174 $this,
175 "access",
176 null
177 );
178 $lp_table->init();
179 if ($a_load_data) {
180 $lp_table->getItems();
181 } else {
182 $lp_table->disable("content");
183 $lp_table->disable("header");
184 }
185 $this->tpl->setContent($lp_table->getHTML());
186 }
187
188 public function showAccessGraph(): void
189 {
190 if (!$this->initItemIdFromPost()) {
191 $this->tpl->setOnScreenMessage(
192 'failure',
193 $this->lng->txt("no_checkbox")
194 );
195 $this->access();
196 }
197
198 $this->tabs_gui->activateSubTab('trac_object_stat_access');
199 $lp_table = new ilLPObjectStatisticsTableGUI(
200 $this,
201 "access",
202 $this->initItemIdFromPost()
203 );
204 $lp_table->init();
205 $lp_table->getItems();
206 $this->tpl->setContent(
207 $lp_table->getGraph(
208 $this->initItemIdFromPost()
209 ) . $lp_table->getHTML()
210 );
211 }
212
213 public function applyTypesFilter(): void
214 {
215 $lp_table = new ilLPObjectStatisticsTypesTableGUI(
216 $this,
217 "types",
218 null,
219 false
220 );
221 $lp_table->resetOffset();
222 $lp_table->writeFilterToSession();
223 $this->types();
224 }
225
226 public function resetTypesFilter(): void
227 {
228 $lp_table = new ilLPObjectStatisticsTypesTableGUI(
229 $this,
230 "types",
231 null,
232 false
233 );
234 $lp_table->resetOffset();
235 $lp_table->resetFilter();
236 $this->types();
237 }
238
239 public function typesFilter(): void
240 {
241 $this->types(false);
242 }
243
244 public function types(bool $a_load_data = true): void
245 {
246 $this->tabs_gui->activateSubTab('trac_object_stat_types');
247 $this->showCronJobInfo();
248
249 $lp_table = new ilLPObjectStatisticsTypesTableGUI(
250 $this,
251 "types",
252 null,
253 $a_load_data
254 );
255
256 if (!$a_load_data) {
257 $lp_table->disable("content");
258 $lp_table->disable("header");
259 }
260
261 $this->tpl->setContent($lp_table->getHTML());
262 }
263
264 public function showTypesGraph(): void
265 {
266 if (!$this->initItemIdFromPost()) {
267 $this->tpl->setOnScreenMessage(
268 'failure',
269 $this->lng->txt("no_checkbox")
270 );
271 $this->types();
272 return;
273 }
274
275 $this->tabs_gui->activateSubTab('trac_object_stat_types');
276
277 $lp_table = new ilLPObjectStatisticsTypesTableGUI(
278 $this,
279 "types",
280 $this->initItemIdFromPost()
281 );
282
283 $this->tpl->setContent(
284 $lp_table->getGraph(
285 $this->initItemIdFromPost()
286 ) . $lp_table->getHTML()
287 );
288 }
289
290 public function applyDailyFilter(): void
291 {
292 $lp_table = new ilLPObjectStatisticsDailyTableGUI(
293 $this,
294 "daily",
295 null
296 );
297 $lp_table->init();
298 $lp_table->resetOffset();
299 $lp_table->writeFilterToSession();
300 $this->daily();
301 }
302
303 public function resetDailyFilter(): void
304 {
305 $lp_table = new ilLPObjectStatisticsDailyTableGUI(
306 $this,
307 "daily",
308 null
309 );
310 $lp_table->init();
311 $lp_table->resetOffset();
312 $lp_table->resetFilter();
313 $this->daily();
314 }
315
316 public function dailyFilter(): void
317 {
318 $this->daily(false);
319 }
320
321 public function daily(bool $a_load_data = true): void
322 {
323 $this->tabs_gui->activateSubTab('trac_object_stat_daily');
324
325 $this->showAggregationInfo();
326
327 $lp_table = new ilLPObjectStatisticsDailyTableGUI(
328 $this,
329 "daily",
330 null
331 );
332 $lp_table->init();
333
334 if ($a_load_data) {
335 $lp_table->getItems();
336 } else {
337 $lp_table->disable("content");
338 $lp_table->disable("header");
339 }
340 $this->tpl->setContent($lp_table->getHTML());
341 }
342
343 public function showDailyGraph(): void
344 {
345 if (!$this->initItemIdFromPost()) {
346 $this->tpl->setOnScreenMessage(
347 'failure',
348 $this->lng->txt("no_checkbox")
349 );
350 $this->daily();
351 return;
352 }
353
354 $this->tabs_gui->activateSubTab('trac_object_stat_daily');
355
356 $lp_table = new ilLPObjectStatisticsDailyTableGUI(
357 $this,
358 "daily",
359 $this->initItemIdFromPost()
360 );
361 $lp_table->init();
362 $lp_table->getItems();
363 $this->tpl->setContent(
364 $lp_table->getGraph(
365 $this->initItemIdFromPost()
366 ) . $lp_table->getHTML()
367 );
368 }
369
370 public function admin(): void
371 {
372 $this->tabs_gui->activateSubTab('trac_object_stat_admin');
373
374 $this->showAggregationInfo(false);
375
376 if ($this->rbacsystem->checkAccess('write', $this->ref_id)) {
377 $this->toolbar->addButton(
378 $this->lng->txt("trac_sync_obj_stats"),
379 $this->ctrl->getLinkTarget($this, "adminSync")
380 );
381 }
382
383 if ($this->access->checkAccess("delete", "", $this->ref_id)) {
384 $lp_table = new ilLPObjectStatisticsAdminTableGUI($this, "admin");
385 $this->tpl->setContent($lp_table->getHTML());
386 }
387 }
388
389 public function adminSync(): void
390 {
392
393 $this->tpl->setOnScreenMessage(
394 'success',
395 $this->lng->txt(
396 "trac_sync_obj_stats_success"
397 ),
398 true
399 );
400 $this->ctrl->redirect($this, "admin");
401 }
402
403 public function confirmDeleteData(): void
404 {
405 if (!$this->initItemIdFromPost()) {
406 $this->tpl->setOnScreenMessage(
407 'failure',
408 $this->lng->txt("no_checkbox")
409 );
410 $this->admin();
411 return;
412 }
413
414 $this->tabs_gui->clearTargets();
415 $this->tabs_gui->setBackTarget(
416 $this->lng->txt("back"),
417 $this->ctrl->getLinkTarget($this, "admin")
418 );
419
420 // display confirmation message
421 $cgui = new ilConfirmationGUI();
422 $cgui->setFormAction($this->ctrl->getFormAction($this));
423 $cgui->setHeaderText($this->lng->txt("trac_sure_delete_data"));
424 $cgui->setCancel($this->lng->txt("cancel"), "admin");
425 $cgui->setConfirm($this->lng->txt("delete"), "deleteData");
426
427 // list objects that should be deleted
428 foreach ($this->initItemIdFromPost() as $i) {
429 $caption = $this->lng->txt(
430 "month_" . str_pad(
431 substr($i, 5),
432 2,
433 "0",
434 STR_PAD_LEFT
435 ) . "_long"
436 ) .
437 " " . substr($i, 0, 4);
438
439 $cgui->addItem("item_id[]", $i, $caption);
440 }
441
442 $this->tpl->setContent($cgui->getHTML());
443 }
444
445 public function deleteData(): void
446 {
447 if (!$this->initItemIdFromPost()) {
448 $this->tpl->setOnScreenMessage(
449 'failure',
450 $this->lng->txt("no_checkbox")
451 );
452 $this->admin();
453 return;
454 }
455
457 $this->tpl->setOnScreenMessage(
458 'success',
459 $this->lng->txt("trac_data_deleted")
460 );
461 $this->admin();
462 }
463
464 public function applyLearningProgressFilter(): void
465 {
466 $lp_table = new ilLPObjectStatisticsLPTableGUI(
467 $this,
468 "learningProgress",
469 null
470 );
471 $lp_table->init();
472 $lp_table->resetOffset();
473 $lp_table->writeFilterToSession();
474 $this->learningProgress();
475 }
476
477 public function resetLearningProgressFilter(): void
478 {
479 $lp_table = new ilLPObjectStatisticsLPTableGUI(
480 $this,
481 "learningProgress",
482 null
483 );
484 $lp_table->init();
485 $lp_table->resetOffset();
486 $lp_table->resetFilter();
487 $this->learningProgress();
488 }
489
490 public function learningProgressFilter(): void
491 {
492 $this->learningProgress(false);
493 }
494
495 public function learningProgress(bool $a_load_data = true): void
496 {
497 $this->tabs_gui->activateSubTab('trac_object_stat_lp');
498
499 $this->showCronJobInfo();
500
501 $lp_table = new ilLPObjectStatisticsLPTableGUI(
502 $this,
503 "learningProgress",
504 null
505 );
506 $lp_table->init();
507 if ($a_load_data) {
508 $lp_table->loadItems();
509 } else {
510 $lp_table->disable("content");
511 $lp_table->disable("header");
512 }
513 $this->tpl->setContent($lp_table->getHTML());
514 }
515
517 {
518 if (!$this->initItemIdFromPost()) {
519 $this->tpl->setOnScreenMessage(
520 'failure',
521 $this->lng->txt("no_checkbox")
522 );
523 $this->learningProgress();
524 return;
525 }
526
527 $this->tabs_gui->activateSubTab('trac_object_stat_lp');
528 $lp_table = new ilLPObjectStatisticsLPTableGUI(
529 $this,
530 "learningProgress",
531 $this->initItemIdFromPost(),
532 true
533 );
534 $lp_table->init();
535 $lp_table->loadItems();
536 $this->tpl->setContent(
537 $lp_table->getGraph(
538 $this->initItemIdFromPost()
539 ) . $lp_table->getHTML()
540 );
541 }
542
543 public function showLearningProgressDetails(): void
544 {
545 $item_id = 0;
546 if ($this->http->wrapper()->query()->has('item_id')) {
547 $item_id = $this->http->wrapper()->query()->retrieve(
548 'item_id',
549 $this->refinery->kindlyTo()->int()
550 );
551 }
552 $lp_table = new ilLPObjectStatisticsLPTableGUI(
553 $this,
554 "showLearningProgressDetails",
555 array($item_id),
556 false,
557 true
558 );
559 $lp_table->init();
560 $lp_table->loadItems();
561 $a_tpl = new ilTemplate(
562 "tpl.lp_object_statistics_lp_details.html",
563 true,
564 true,
565 "Services/Tracking"
566 );
567 $a_tpl->setVariable("CONTENT", $lp_table->getHTML());
568 $a_tpl->setVariable('CLOSE_IMG_TXT', $this->lng->txt('close'));
569 echo $a_tpl->get();
570 exit();
571 }
572
573 protected function showAggregationInfo(bool $a_show_link = true): void
574 {
577 new ilDateTime($info["tstamp"], IL_CAL_UNIX)
578 );
579
580 $link = "";
581 if ($a_show_link && $this->access->checkAccess(
582 "write",
583 "",
584 $this->ref_id
585 )) {
586 $link = " <a href=\"" . $this->ctrl->getLinkTarget(
587 $this,
588 "admin"
589 ) . "\">&raquo;" .
590 $this->lng->txt("trac_log_info_link") . "</a>";
591 }
592
593 $this->tpl->setOnScreenMessage(
594 'info',
595 sprintf(
596 $this->lng->txt(
597 "trac_log_info"
598 ),
599 $info_date,
600 $info["counter"]
601 ) . $link
602 );
603 }
604
605 protected function showCronJobInfo(): void
606 {
607 if (!$this->cronManager->isJobActive("lp_object_statistics")) {
608 $this->tpl->setOnScreenMessage(
609 'info',
610 $this->lng->txt("trac_cron_info")
611 );
612 }
613 }
614}
const IL_CAL_UNIX
static _syncObjectStats(?int $a_now=null, int $a_minimum=20000)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
learningProgress(bool $a_load_data=true)
showAggregationInfo(bool $a_show_link=true)
__construct(int $a_mode, int $a_ref_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
static getObjectStatisticsLogInfo()
Get last update info for object statistics.
static deleteObjectStatistics(array $a_months)
global $DIC
Definition: feed.php:28
exit
Definition: login.php:28
$i
Definition: metadata.php:41
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc