ILIAS  release_8 Revision v8.24
class.ilXapiResultsCronjob.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
31{
32 public const LAST_RUN_TS_SETTING_NAME = 'cron_xapi_res_eval_last_run';
33
34 protected int $thisRunTS;
35
36 protected int $lastRunTS;
37
38 protected ilLogger $log;
39
40 private \ILIAS\DI\Container $dic;
41
42 public function __construct()
43 {
44 global $DIC; /* @var \ILIAS\DI\Container $DIC */
45 $this->dic = $DIC;
46
47 $DIC->language()->loadLanguageModule('cmix');
48
49 $this->log = ilLoggerFactory::getLogger('cmix');
50
51 $this->initThisRunTS();
52 $this->readLastRunTS();
53 }
54
55 protected function initThisRunTS(): void
56 {
57 $this->thisRunTS = time();
58 }
59
60 protected function readLastRunTS(): void
61 {
62 $settings = new ilSetting('cmix');
63 // Check return value of $settings->get, since this is string but a int is needed for lastRunTS
64 $this->lastRunTS = (int) $settings->get(self::LAST_RUN_TS_SETTING_NAME, "0");
65 }
66
67 protected function writeThisAsLastRunTS(): void
68 {
69 $settings = new ilSetting('cmix');
70 $settings->set(self::LAST_RUN_TS_SETTING_NAME, (string) $this->thisRunTS);
71 }
72
73 public function getThisRunTS(): int
74 {
75 return $this->thisRunTS;
76 }
77
78 public function getLastRunTS(): int
79 {
80 return $this->lastRunTS;
81 }
82
83 public function getId(): string
84 {
85 return 'xapi_results_evaluation';
86 }
87
88 public function getTitle(): string
89 {
90 return $this->dic->language()->txt("cron_xapi_results_evaluation");
91 }
92
93 public function getDescription(): string
94 {
95 return $this->dic->language()->txt("cron_xapi_results_evaluation_desc");
96 }
97
98 public function hasAutoActivation(): bool
99 {
100 return false;
101 }
102
103 public function hasFlexibleSchedule(): bool
104 {
105 return true;
106 }
107
108 public function getDefaultScheduleType(): int
109 {
111 }
112
113 public function getDefaultScheduleValue(): ?int
114 {
115 return null;
116 }
117
118 public function run(): ilCronJobResult
119 {
120 $objects = $this->getObjectsToBeReported();
121 $objectIds = [];
122
123 foreach ($objects as $objId) {
124 $this->log->debug('handle object (' . $objId . ')');
125
126 $filter = $this->buildReportFilter();
127
129
130 $evaluation = new ilXapiStatementEvaluation($this->log, $object);
131
132 if ($object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
133 $this->log->debug('skipped object due to launch mode (' . $objId . ')');
134 continue;
135 }
136
137 $report = $this->getXapiStatementsReport($object, $filter);
138
139 $evaluation->evaluateReport($report);
140
141 //$this->log->debug('update lp for object (' . $objId . ')');
142 //ilLPStatusWrapper::_refreshStatus($objId);
143
144 $objectIds[] = $objId;
145 }
146
149 $objectIds
150 );
151
152 $result = new ilCronJobResult();
153 $result->setStatus(ilCronJobResult::STATUS_OK);
154
155 $this->writeThisAsLastRunTS();
156 return $result;
157 }
158
159 protected function getXapiStatementsReport(
160 ilObject $object,
163 $filter->setActivityId($object->getActivityId());
164
165 $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
166 $object->getId(),
167 $object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
168 $filter
169 );
170
172 $object->getLrsType()->getBasicAuth(),
173 $linkBuilder
174 );
175
176 return $request->queryReport($object->getId());
177 }
178
180 {
181 $filter = new ilCmiXapiStatementsReportFilter();
182
183 $start = $end = null;
184
185 if ($this->getLastRunTS() !== 0) {
186 $filter->setStartDate(new ilCmiXapiDateTime($this->getLastRunTS(), IL_CAL_UNIX));
187 $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
188 }
189
190 $filter->setEndDate(new ilCmiXapiDateTime($this->getThisRunTS(), IL_CAL_UNIX));
191 $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
192
193 $this->log->debug("use filter from ($start) until ($end)");
194
195 return $filter;
196 }
197
201 protected function getObjectsToBeReported(): array
202 {
203 return array_unique(array_merge(
206 ));
207 }
208}
const IL_CAL_UNIX
const IL_CAL_DATETIME
static updateFetchedUntilForObjects(ilCmiXapiDateTime $fetchedUntil, array $objectIds)
static getCmixObjectsHavingUsersMissingProxySuccess()
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static getObjectsHavingBypassProxyEnabledAndRegisteredUsers()
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
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...
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
getXapiStatementsReport(ilObject $object, ilCmiXapiStatementsReportFilter $filter)
global $DIC
Definition: feed.php:28
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$objId
Definition: xapitoken.php:57