ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilXapiResultsCronjob.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
17 const LAST_RUN_TS_SETTING_NAME = 'cron_xapi_res_eval_last_run';
18
22 protected $thisRunTS;
23
27 protected $lastRunTS;
28
32 protected $log;
33
34 public function __construct()
35 {
36 global $DIC; /* @var \ILIAS\DI\Container $DIC */
37
38 $DIC->language()->loadLanguageModule('cmix');
39
40 $this->log = ilLoggerFactory::getLogger('cmix');
41
42 $this->initThisRunTS();
43 $this->readLastRunTS();
44 }
45
46 protected function initThisRunTS()
47 {
48 $this->thisRunTS = time();
49 }
50
51 protected function readLastRunTS()
52 {
53 $settings = new ilSetting('cmix');
54 $this->lastRunTS = $settings->get(self::LAST_RUN_TS_SETTING_NAME, 0);
55 }
56
57 protected function writeThisAsLastRunTS()
58 {
59 $settings = new ilSetting('cmix');
60 $settings->set(self::LAST_RUN_TS_SETTING_NAME, $this->thisRunTS);
61 }
62
63 public function getThisRunTS()
64 {
65 return $this->thisRunTS;
66 }
67
68 public function getLastRunTS()
69 {
70 return $this->lastRunTS;
71 }
72
73 public function getId()
74 {
75 return 'xapi_results_evaluation';
76 }
77
78 public function getTitle()
79 {
80 global $DIC; /* @var \ILIAS\DI\Container $DIC */
81 return $DIC->language()->txt("cron_xapi_results_evaluation");
82 }
83
84 public function getDescription()
85 {
86 global $DIC; /* @var \ILIAS\DI\Container $DIC */
87 return $DIC->language()->txt("cron_xapi_results_evaluation_desc");
88 }
89
90 public function hasAutoActivation()
91 {
92 return false;
93 }
94
95 public function hasFlexibleSchedule()
96 {
97 return true;
98 }
99
100 public function getDefaultScheduleType()
101 {
103 }
104
105 public function getDefaultScheduleValue()
106 {
107 return;
108 }
109
110 public function hasCustomSettings()
111 {
112 return false;
113 }
114
115 public function run()
116 {
117 $objects = $this->getObjectsToBeReported();
118
119 foreach ($objects as $objId) {
120 $this->log->debug('handle object (' . $objId . ')');
121
122 $filter = $this->buildReportFilter();
123
125
126 $evaluation = new ilXapiStatementEvaluation($this->log, $object);
127
128 if ($object->getLaunchMode() != ilObjCmiXapi::LAUNCH_MODE_NORMAL) {
129 $this->log->debug('skipped object due to launch mode (' . $objId . ')');
130 continue;
131 }
132
133 $report = $this->getXapiStatementsReport($object, $filter);
134
135 $evaluation->evaluateReport($report);
136
137 //$this->log->debug('update lp for object (' . $objId . ')');
138 //ilLPStatusWrapper::_refreshStatus($objId);
139
140 $objectIds[] = $objId;
141 }
142
145 $objectIds
146 );
147
148 $result = new ilCronJobResult();
150
151 $this->writeThisAsLastRunTS();
152 return $result;
153 }
154
156 {
157 $filter->setActivityId($object->getActivityId());
158
159 $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
160 $object,
161 $object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
162 $filter
163 );
164
166 $object->getLrsType()->getBasicAuth(),
167 $linkBuilder
168 );
169
170 return $request->queryReport($object);
171 }
172
173 protected function buildReportFilter()
174 {
175 $filter = new ilCmiXapiStatementsReportFilter();
176
177 $start = $end = null;
178
179 if ($this->getLastRunTS()) {
180 $filter->setStartDate(new ilCmiXapiDateTime($this->getLastRunTS(), IL_CAL_UNIX));
181 $start = $filter->getStartDate()->get(IL_CAL_DATETIME);
182 }
183
184 $filter->setEndDate(new ilCmiXapiDateTime($this->getThisRunTS(), IL_CAL_UNIX));
185 $end = $filter->getEndDate()->get(IL_CAL_DATETIME);
186
187 $this->log->debug("use filter from ($start) until ($end)");
188
189 return $filter;
190 }
191
195 protected function getObjectsToBeReported() : array
196 {
197 $objects = array_unique(array_merge(
200 ));
201
202 return $objects;
203 }
204}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
static updateFetchedUntilForObjects(ilCmiXapiDateTime $fetchedUntil, $objectIds)
static getCmixObjectsHavingUsersMissingProxySuccess()
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
static getLogger($a_component_id)
Get component logger.
static getObjectsHavingBypassProxyEnabledAndRegisteredUsers()
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
ILIAS Setting Class.
getDefaultScheduleType()
Get schedule type.
hasAutoActivation()
Is to be activated on "installation".
hasFlexibleSchedule()
Can the schedule be configured?
getXapiStatementsReport(ilObjCmiXapi $object, ilCmiXapiStatementsReportFilter $filter)
hasCustomSettings()
Has cron job any custom setting which can be edited?
getDefaultScheduleValue()
Get schedule value.
$DIC
Definition: xapitoken.php:46
$objId
Definition: xapitoken.php:41