ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLearningHistoryEntryCollector.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $service;
17
23 {
24 $this->service = $service;
25 }
26
36 public function getEntries(int $from = null, int $to = null, int $user_id = null, array $classes = null)
37 {
38 $entries = array();
39 $lng = $this->service->language();
40
41 $to = (is_null($to))
42 ? time()
43 : $to;
44 $from = (is_null($from))
45 ? time() - (365 * 24 * 60 * 60)
46 : $from;
47
48 $sort_array = [];
49 foreach ($this->service->provider()->getAllProviders(true, $user_id) as $provider) {
50 if (is_array($classes) && !in_array(get_class($provider), $classes)) {
51 continue;
52 }
53
54 foreach ($provider->getEntries($from, $to) as $e) {
55 $sort_array[] = array("entry" => $e,"ts" => $e->getTimestamp());
56 }
57 }
58
59 $sort_array = ilUtil::sortArray($sort_array, "ts", "desc");
60
61 // add today entry
62 $entries = [];
63
64 if (date("Y-m-d", $to) == date("Y-m-d", time())) {
65 if (count($sort_array) == 0 ||
66 date("Y-m-d", (current($sort_array)["ts"])) != date("Y-m-d", time())) {
67 $entries[] = $this->service->factory()->entry(
68 $lng->txt("lhist_no_entries"),
69 $lng->txt("lhist_no_entries"),
70 ilUtil::getImagePath("spacer.png"),
71 time(),
72 0
73 );
74 }
75 }
76
77
78 foreach ($sort_array as $s) {
79 $entries[] = $s["entry"];
80 }
81
82 return $entries;
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
__construct(ilLearningHistoryService $service)
Constructor.
getEntries(int $from=null, int $to=null, int $user_id=null, array $classes=null)
Get entries.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$lng