ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilObjLTITool.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public const string TABLE_NAME = 'lti_consumer_settings';
30
34 public const string LAUNCH_METHOD_OWN_WIN = 'ownWin';
35 public const string LAUNCH_METHOD_NEW_WIN = 'newWin';
36 public const string LAUNCH_METHOD_EMBEDDED = 'embedded';
37
38 public const int HIGHSCORE_SHOW_ALL_TABLES = 1;
39 public const int HIGHSCORE_SHOW_TOP_TABLE = 2;
40 public const int HIGHSCORE_SHOW_OWN_TABLE = 3;
41
42 private int $tool_id = 0;
43 private ?ilLTITool $tool = null;
45 private string $custom_params = '';
47 private float $mastery_score = 0.5;
48 private float $score_maximum = 1.0;
49 private bool $use_xapi = false;
50 private string $custom_activity_id = '';
51 private bool $statements_report_enabled = false;
52 private bool $highscore_enabled = false;
53 private bool $highscore_achieved_ts = true;
54 private bool $highscore_percentage = true;
55 private bool $highscore_wtime = true;
56 private bool $highscore_own_table = true;
57 private bool $highscore_top_table = true;
58 private int $highscore_top_num = 10;
59
60 protected function initType(): void
61 {
62 $this->type = 'lti';
63 }
64
65 public function getToolId(): int
66 {
67 return $this->tool_id;
68 }
69
70 public function setToolId(int $tool_id): void
71 {
72 $this->tool_id = $tool_id;
73 $this->tool = null;
74 }
75
76 public function getTool(): ilLTITool
77 {
78 return $this->tool ??= new ilLTITool($this->getToolId());
79 }
80
81 public function getLaunchMethod(): string
82 {
84 }
85
86 public function setLaunchMethod(string $launch_method): void
87 {
88 $this->launch_method = $launch_method;
89 }
90
91 public function isLaunchMethodOwnWin(): bool
92 {
93 return $this->launch_method === self::LAUNCH_METHOD_OWN_WIN;
94 }
95
96 public function isLaunchMethodEmbedded(): bool
97 {
98 return $this->launch_method === self::LAUNCH_METHOD_EMBEDDED;
99 }
100
101 public function getCustomParams(): string
102 {
104 }
105
106 public function setCustomParams(string $custom_params): void
107 {
108 $this->custom_params = $custom_params;
109 }
110
114 public function getMasteryScore(): float
115 {
117 }
118
119 public function setMasteryScore(float $mastery_score): void
120 {
121 $this->mastery_score = $mastery_score;
122 }
123
128 public function getScoreMaximum(): float
129 {
131 }
132
133 public function setScoreMaximum(float $score_maximum): void
134 {
135 $this->score_maximum = $score_maximum;
136 }
137
141 public function getUseXapi(): bool
142 {
143 return $this->use_xapi && $this->getTool()->getUseXapi();
144 }
145
146 public function setUseXapi(bool $use_xapi): void
147 {
148 $this->use_xapi = $use_xapi;
149 }
150
154 public function getCustomActivityId(): string
155 {
157 }
158
159 public function setCustomActivityId(string $custom_activity_id): void
160 {
161 $this->custom_activity_id = $custom_activity_id;
162 }
163
167 public function getActivityId(): string
168 {
169 $tool_activity_id = $this->getTool()->getXapiActivityId();
170
171 return $tool_activity_id !== '' ? $tool_activity_id : $this->custom_activity_id;
172 }
173
177 public function isStatementsReportEnabled(): bool
178 {
180 }
181
182 public function setStatementsReportEnabled(bool $enabled): void
183 {
184 $this->statements_report_enabled = $enabled;
185 }
186
187 public function getHighscoreEnabled(): bool
188 {
190 }
191
192 public function setHighscoreEnabled(bool $enabled): void
193 {
194 $this->highscore_enabled = $enabled;
195 }
196
197 public function getHighscoreAchievedTS(): bool
198 {
200 }
201
202 public function setHighscoreAchievedTS(bool $shown): void
203 {
204 $this->highscore_achieved_ts = $shown;
205 }
206
207 public function getHighscorePercentage(): bool
208 {
210 }
211
212 public function setHighscorePercentage(bool $shown): void
213 {
214 $this->highscore_percentage = $shown;
215 }
216
217 public function getHighscoreWTime(): bool
218 {
220 }
221
222 public function setHighscoreWTime(bool $shown): void
223 {
224 $this->highscore_wtime = $shown;
225 }
226
227 public function getHighscoreOwnTable(): bool
228 {
230 }
231
232 public function getHighscoreTopTable(): bool
233 {
235 }
236
240 public function getHighscoreMode(): int
241 {
242 return match (true) {
243 $this->highscore_own_table && $this->highscore_top_table => self::HIGHSCORE_SHOW_ALL_TABLES,
244 $this->highscore_top_table => self::HIGHSCORE_SHOW_TOP_TABLE,
246 };
247 }
248
249 public function setHighscoreMode(int $mode): void
250 {
251 $this->highscore_own_table = $mode !== self::HIGHSCORE_SHOW_TOP_TABLE;
252 $this->highscore_top_table = $mode !== self::HIGHSCORE_SHOW_OWN_TABLE;
253 }
254
255 public function getHighscoreTopNum(): int
256 {
257 return $this->highscore_top_num > 0 ? $this->highscore_top_num : 10;
258 }
259
260 public function setHighscoreTopNum(int $top_num): void
261 {
262 $this->highscore_top_num = $top_num;
263 }
264
268 public function isMixedContentType(): bool
269 {
270 return true;
271 }
272
273 public function getContentType(): string
274 {
276 }
277
281 public function getProvider(): ilLTITool
282 {
283 return $this->getTool();
284 }
285
286 public static function getInstance(int $id = 0, bool $reference = true): self
287 {
288 return new self($id, $reference);
289 }
290
292 {
293 return $this->lti_1p1_credentials ??= new ilLTI1p1ConsumerObjectCredentials();
294 }
295
299 public function getCustomParamsArray(): array
300 {
302 }
303
309 public function syncKeywordsFromTool(): void
310 {
311 global $DIC;
312
313 $lom = $DIC->learningObjectMetadata();
314 $lom->manipulate($this->getId(), 0, $this->getType())
315 ->prepareDelete($lom->paths()->keywords())
316 ->execute();
317
318 $keywords = $this->getTool()->getKeywords();
319 if ($keywords !== []) {
320 $lom->manipulate($this->getId(), 0, $this->getType())
321 ->prepareCreateOrUpdate($lom->paths()->keywords(), ...$keywords)
322 ->execute();
323 }
324 }
325
326 protected function doRead(): void
327 {
328 global $DIC;
329
330 $db = $DIC->database();
331 $row = $db->fetchAssoc($db->queryF(
332 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE obj_id = %s',
333 ['integer'],
334 [$this->getId()]
335 ));
336 if ($row === null) {
337 return;
338 }
339
340 $this->setToolId((int) $row['provider_id']);
341 $this->setLaunchMethod((string) $row['launch_method']);
342 $this->setCustomParams((string) $row['custom_params']);
343 $this->mastery_score = (float) $row['mastery_score'];
344 $this->score_maximum = (float) ($row['score_maximum'] ?? 0) > 0 ? (float) $row['score_maximum'] : 1.0;
345 $this->use_xapi = (bool) $row['use_xapi'];
346 $this->custom_activity_id = (string) $row['activity_id'];
347 $this->statements_report_enabled = (bool) $row['show_statements'];
348 $this->highscore_enabled = (bool) $row['highscore_enabled'];
349 $this->highscore_achieved_ts = (bool) $row['highscore_achieved_ts'];
350 $this->highscore_percentage = (bool) $row['highscore_percentage'];
351 $this->highscore_wtime = (bool) $row['highscore_wtime'];
352 $this->highscore_own_table = (bool) $row['highscore_own_table'];
353 $this->highscore_top_table = (bool) $row['highscore_top_table'];
354 $this->highscore_top_num = (int) $row['highscore_top_num'];
355 $this->getLti1p1Credentials()->assignFromDbRow($row);
356 }
357
358 protected function doCreate(bool $clone_mode = false): void
359 {
360 global $DIC;
361
362 $DIC->database()->insert(
363 self::TABLE_NAME,
364 ['obj_id' => ['integer', $this->getId()]] + $this->getDbFields()
365 );
366 }
367
372 protected function doUpdate(): void
373 {
374 global $DIC;
375
376 $DIC->database()->update(
377 self::TABLE_NAME,
378 $this->getDbFields(),
379 ['obj_id' => ['integer', $this->getId()]]
380 );
381 }
382
387 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
388 {
389 global $DIC;
390
391 $this->cloneMetaData($new_obj);
392
393 $DIC->database()->update(
394 self::TABLE_NAME,
395 $this->getDbFields(),
396 ['obj_id' => ['integer', $new_obj->getId()]]
397 );
398 $new_obj->read();
399
400 (new ilLPObjSettings($this->getId()))->cloneSettings($new_obj->getId());
401 }
402
403 protected function doDelete(): void
404 {
405 global $DIC;
406
407 $db = $DIC->database();
408 // the scores and results of the users go with the object
409 foreach ([self::TABLE_NAME, 'lti_consumer_results', 'lti_consumer_grades'] as $table) {
411 'DELETE FROM ' . $table . ' WHERE obj_id = %s',
412 ['integer'],
413 [$this->getId()]
414 );
415 }
416 }
417
421 private function getDbFields(): array
422 {
423 return $this->getLti1p1Credentials()->getDbFields() + [
424 'provider_id' => ['integer', $this->getToolId()],
425 'launch_method' => ['text', $this->getLaunchMethod()],
426 'custom_params' => ['text', $this->getCustomParams()],
427 'mastery_score' => ['float', $this->mastery_score],
428 'score_maximum' => ['float', $this->score_maximum],
429 'use_xapi' => ['integer', (int) $this->use_xapi],
430 'activity_id' => ['text', $this->custom_activity_id],
431 'show_statements' => ['integer', (int) $this->statements_report_enabled],
432 'highscore_enabled' => ['integer', (int) $this->highscore_enabled],
433 'highscore_achieved_ts' => ['integer', (int) $this->highscore_achieved_ts],
434 'highscore_percentage' => ['integer', (int) $this->highscore_percentage],
435 'highscore_wtime' => ['integer', (int) $this->highscore_wtime],
436 'highscore_own_table' => ['integer', (int) $this->highscore_own_table],
437 'highscore_top_table' => ['integer', (int) $this->highscore_top_table],
438 'highscore_top_num' => ['integer', $this->highscore_top_num],
439 ];
440 }
441
451 public static function buildCustomParams(array $params): string
452 {
453 $notation = [];
454 foreach ($params as $name => $value) {
455 if ((string) $name !== '' && is_scalar($value)) {
456 $notation[] = $name . '=' . $value;
457 }
458 }
459
460 return implode(';', $notation);
461 }
462
463 public static function parseCustomParams(string $params): array
464 {
465 $parsed = [];
466 foreach (preg_split('/; ?/', $params) as $param) {
467 $param = explode('=', $param, 2);
468 if ($param[0] !== '') {
469 $parsed[$param[0]] = $param[1] ?? '';
470 }
471 }
472
473 return $parsed;
474 }
475}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
OAuth1 key and secret set on a single LTI consumer object, used instead of the provider credentials w...
An external tool ILIAS can launch, stored in lti_ext_provider.
A repository object of type lti: one external tool made available at one place of the repository.
doUpdate()
Only the columns this class knows are written, so that the settings of an object coming from an older...
const string LAUNCH_METHOD_NEW_WIN
static buildCustomParams(array $params)
The custom parameters in the notation foo=bar;foo2=bar2.
setHighscoreEnabled(bool $enabled)
isMixedContentType()
The reports of CmiXapi read the statements of an LTI object as generic xAPI of any kind.
setScoreMaximum(float $score_maximum)
getScoreMaximum()
The maximum score of the line item of the object in the Assignment and Grade Services.
setUseXapi(bool $use_xapi)
setToolId(int $tool_id)
setCustomActivityId(string $custom_activity_id)
setHighscoreAchievedTS(bool $shown)
setHighscoreTopNum(int $top_num)
setHighscorePercentage(bool $shown)
ilLTI1p1ConsumerObjectCredentials $lti_1p1_credentials
setHighscoreWTime(bool $shown)
setStatementsReportEnabled(bool $enabled)
const string LAUNCH_METHOD_OWN_WIN
The tool replaces the ILIAS page.
getMasteryScore()
The share of the maximum result, between 0 and 1, a user has to reach to complete the object.
doCreate(bool $clone_mode=false)
getProvider()
The name the reports of CmiXapi use for the tool.
getHighscoreMode()
Which rankings are shown: the one around the user, the best users or both.
const int HIGHSCORE_SHOW_TOP_TABLE
static parseCustomParams(string $params)
string $custom_activity_id
const string TABLE_NAME
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
The copy keeps the tool, the settings and the learning progress mode; the scores and results of the u...
setMasteryScore(float $mastery_score)
isStatementsReportEnabled()
True when every user may see their own statements, not only the users who may read the outcomes.
const string LAUNCH_METHOD_EMBEDDED
setLaunchMethod(string $launch_method)
getUseXapi()
True when the object reports on the xAPI statements of its tool, which has to send them.
setCustomParams(string $custom_params)
setHighscoreMode(int $mode)
static getInstance(int $id=0, bool $reference=true)
const int HIGHSCORE_SHOW_ALL_TABLES
const int HIGHSCORE_SHOW_OWN_TABLE
getActivityId()
The xAPI activity the statements of the object belong to.
syncKeywordsFromTool()
The keywords of the metadata are the ones of the tool: those of the object are replaced by them.
bool $statements_report_enabled
getCustomActivityId()
The activity the object names itself, which only counts when its tool has none.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
ilDBInterface $db
manipulateF(string $query, array $types, array $values)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:44