ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilXapiResultsCronjob.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
35{
36 public const LAST_RUN_TS_SETTING_NAME = 'cron_xapi_res_eval_last_run';
37
38 protected int $thisRunTS;
39
40 protected int $lastRunTS;
41
42 protected ilLogger $log;
43
44 private \ILIAS\DI\Container $dic;
45
46 public function __construct()
47 {
48 global $DIC; /* @var \ILIAS\DI\Container $DIC */
49 $this->dic = $DIC;
50
51 $DIC->language()->loadLanguageModule('cmix');
52
53 $this->log = ilLoggerFactory::getLogger('cmix');
54
55 $this->initThisRunTS();
56 $this->readLastRunTS();
57 }
58
59 protected function initThisRunTS(): void
60 {
61 $this->thisRunTS = time();
62 }
63
64 protected function readLastRunTS(): void
65 {
66 $settings = new ilSetting('cmix');
67 // Check return value of $settings->get, since this is string but a int is needed for lastRunTS
68 $this->lastRunTS = (int) $settings->get(self::LAST_RUN_TS_SETTING_NAME, "0");
69 }
70
71 protected function writeThisAsLastRunTS(): void
72 {
73 $settings = new ilSetting('cmix');
74 $settings->set(self::LAST_RUN_TS_SETTING_NAME, (string) $this->thisRunTS);
75 }
76
77 public function getThisRunTS(): int
78 {
79 return $this->thisRunTS;
80 }
81
82 public function getLastRunTS(): int
83 {
84 return $this->lastRunTS;
85 }
86
87 public function getId(): string
88 {
89 return 'xapi_results_evaluation';
90 }
91
92 public function getTitle(): string
93 {
94 return $this->dic->language()->txt("cron_xapi_results_evaluation");
95 }
96
97 public function getDescription(): string
98 {
99 return $this->dic->language()->txt("cron_xapi_results_evaluation_desc");
100 }
101
102 public function hasAutoActivation(): bool
103 {
104 return false;
105 }
106
107 public function hasFlexibleSchedule(): bool
108 {
109 return true;
110 }
111
113 {
114 return JobScheduleType::DAILY;
115 }
116
117 public function getDefaultScheduleValue(): ?int
118 {
119 return null;
120 }
121
122 public function run(): JobResult
123 {
124 $objects = $this->getObjectsToBeReported();
125 $objectIds = [];
126
127 foreach ($objects as $objId) {
128 $this->log->debug('handle object (' . $objId . ')');
129
130 $filter = $this->buildReportFilter();
131
133
134 $evaluation = new ilXapiStatementEvaluation($this->log, $object);
135
136 if ($object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
137 $this->log->debug('skipped object due to launch mode (' . $objId . ')');
138 continue;
139 }
140
141 $report = $this->getXapiStatementsReport($object, $filter);
142
143 $evaluation->evaluateReport($report);
144
145 //$this->log->debug('update lp for object (' . $objId . ')');
146 //ilLPStatusWrapper::_refreshStatus($objId);
147
148 $objectIds[] = $objId;
149 }
150
153 $objectIds
154 );
155
156 $result = new JobResult();
157 $result->setStatus(JobResult::STATUS_OK);
158
159 $this->writeThisAsLastRunTS();
160 return $result;
161 }
162
163 protected function getXapiStatementsReport(
164 ilObject $object,
167 $filter->setActivityId($object->getActivityId());
168
169 $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
170 $object->getId(),
171 $object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
172 $filter
173 );
174
176 $object->getLrsType()->getBasicAuth(),
177 $linkBuilder
178 );
179
180 return $request->queryReport($object->getId());
181 }
182
184 {
185 $filter = new ilCmiXapiStatementsReportFilter();
186
187 $start = $end = null;
188
189 if ($this->getLastRunTS() !== 0) {
190 $filter->setStartDate(new ilCmiXapiDateTime($this->getLastRunTS(), IL_CAL_UNIX));
191 $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
192 }
193
194 $filter->setEndDate(new ilCmiXapiDateTime($this->getThisRunTS(), IL_CAL_UNIX));
195 $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
196
197 $this->log->debug("use filter from ($start) until ($end)");
198
199 return $filter;
200 }
201
205 protected function getObjectsToBeReported(): array
206 {
207 return array_unique(array_merge(
210 ));
211 }
212}
const IL_CAL_UNIX
const IL_CAL_DATETIME
static updateFetchedUntilForObjects(ilCmiXapiDateTime $fetchedUntil, array $objectIds)
static getCmixObjectsHavingUsersMissingProxySuccess()
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
Class ilObject Basic functions for all objects.
ILIAS Setting Class.
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
getXapiStatementsReport(ilObject $object, ilCmiXapiStatementsReportFilter $filter)
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57