ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ilLTIToolPlaceholderValues.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
35
36 public function __construct()
37 {
38 global $DIC;
39
40 $this->language = $DIC->language();
41 $this->language->loadLanguageModule('certificate');
42 $this->default_values = new ilDefaultPlaceholderValues();
43 $this->object_helper = new ilCertificateObjectHelper();
44 $this->util_helper = new ilCertificateUtilHelper();
45 $this->lp_status_helper = new ilCertificateLPStatusHelper();
46 $this->date_helper = new ilCertificateDateHelper();
47 }
48
59 public function getPlaceholderValues(int $userId, int $objId): array
60 {
61 $object = $this->object_helper->getInstanceByObjId($objId);
62 $placeholders = $this->default_values->getPlaceholderValues($userId, $objId);
63
64 $placeholders['OBJECT_TITLE'] = $this->util_helper->prepareFormOutput($object->getTitle());
65 $placeholders['OBJECT_DESCRIPTION'] = $this->util_helper->prepareFormOutput($object->getDescription());
66 $placeholders['MASTERY_SCORE'] = $this->util_helper->prepareFormOutput(
67 $object instanceof ilObjLTITool ? $this->formatPercentage($object->getMasteryScore()) : ''
68 );
69
70 $result = ilLTIToolResult::getByKeys($objId, $userId)?->getResult();
71 $placeholders['REACHED_SCORE'] = $this->util_helper->prepareFormOutput(
72 $result === null ? '' : $this->formatPercentage($result)
73 );
74
75 $placeholders['DATE_COMPLETED'] = '';
76 $placeholders['DATETIME_COMPLETED'] = '';
77 $completion_date = $this->lp_status_helper->lookupStatusChanged($objId, $userId);
78 if ($completion_date !== '') {
79 $user = $this->object_helper->getInstanceByObjId($userId);
80 $user = $user instanceof ilObjUser ? $user : null;
81 $placeholders['DATE_COMPLETED'] = $this->date_helper->formatDate($completion_date, $user);
82 $placeholders['DATETIME_COMPLETED'] = $this->date_helper->formatDateTime($completion_date, $user);
83 }
84
85 return $placeholders;
86 }
87
95 public function getPlaceholderValuesForPreview(int $userId, int $objId): array
96 {
97 $placeholders = $this->default_values->getPlaceholderValuesForPreview($userId, $objId);
98 foreach ([
99 'OBJECT_TITLE' => 'lti_cert_ph_object_title',
100 'OBJECT_DESCRIPTION' => 'lti_cert_ph_object_description',
101 'MASTERY_SCORE' => 'lti_cert_ph_mastery_score',
102 'REACHED_SCORE' => 'lti_cert_ph_reached_score',
103 ] as $placeholder => $txt) {
104 $placeholders[$placeholder] = $this->util_helper->prepareFormOutput($this->language->txt($txt));
105 }
106
107 return $placeholders;
108 }
109
110 private function formatPercentage(float $share): string
111 {
112 return sprintf('%0.2f %%', 100 * $share);
113 }
114}
Just a wrapper class to create Unit Test for other classes.
Collection of basic placeholder values that can be used.
The values of the placeholders of ilLTIToolPlaceholderDescription for a user of an LTI object.
getPlaceholderValuesForPreview(int $userId, int $objId)
ilCertificateLPStatusHelper $lp_status_helper
ilDefaultPlaceholderValues $default_values
static getByKeys(int $obj_id, int $usr_id)
The result of the user for the object, null when the tool has not reported any.
language handling
A repository object of type lti: one external tool made available at one place of the repository.
User class.
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57