ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningHistoryEntryCollector.php
Go to the documentation of this file.
1<?php
2
24{
26
28 {
29 $this->service = $service;
30 }
31
40 public function getEntries(
41 ?int $from = null,
42 ?int $to = null,
43 ?int $user_id = null,
44 ?array $classes = null
45 ): array {
46 $lng = $this->service->language();
47
48 $to = (is_null($to))
49 ? time()
50 : $to;
51 $from = (is_null($from))
52 ? time() - (365 * 24 * 60 * 60)
53 : $from;
54
55 $sort_array = [];
56 foreach ($this->service->provider()->getAllProviders(true, $user_id) as $provider) {
57 if (is_array($classes) && !in_array(get_class($provider), $classes, true)) {
58 continue;
59 }
60
61 foreach ($provider->getEntries($from, $to) as $e) {
62 $sort_array[] = array("entry" => $e,"ts" => $e->getTimestamp());
63 }
64 }
65
66 $sort_array = ilArrayUtil::sortArray($sort_array, "ts", "desc");
67
68 // add today entry
69 $entries = [];
70
71 if (date("Y-m-d", $to) === date("Y-m-d")) {
72 if (count($sort_array) === 0 ||
73 date("Y-m-d", (current($sort_array)["ts"])) !== date("Y-m-d")) {
74 $entries[] = $this->service->factory()->entry(
75 $lng->txt("lhist_no_entries"),
76 $lng->txt("lhist_no_entries"),
77 ilUtil::getImagePath("media/spacer.png"),
78 time(),
79 0
80 );
81 }
82 }
83
84
85 foreach ($sort_array as $s) {
86 $entries[] = $s["entry"];
87 }
88
89 return $entries;
90 }
91}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilLearningHistoryService $service)
getEntries(?int $from=null, ?int $to=null, ?int $user_id=null, ?array $classes=null)
Get entries.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$provider
Definition: ltitoken.php:80
global $lng
Definition: privfeed.php:31