ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilScormPlaceholderValues.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private readonly ilLanguage $language;
30
31 public function __construct(
32 ?ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
33 ?ilLanguage $language = null,
39 ) {
40 if (null === $language) {
41 global $DIC;
42 $language = $DIC->language();
43 $language->loadLanguageModule('certificate');
44 }
45 $this->language = $language;
46
47 if (null === $defaultPlaceholderValues) {
48 $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
49 }
50 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
51
52 if (null === $dateHelper) {
54 }
55 $this->dateHelper = $dateHelper;
56
57 if (null === $objectHelper) {
59 }
60 $this->objectHelper = $objectHelper;
61
62 if (null === $utilHelper) {
64 }
65 $this->utilHelper = $utilHelper;
66
67 if (null === $objectLPHelper) {
69 }
70 $this->objectLPHelper = $objectLPHelper;
71
72 if (null === $lpStatusHelper) {
74 }
75 $this->lpStatusHelper = $lpStatusHelper;
76 }
77
89 public function getPlaceholderValues(int $userId, int $objId): array
90 {
91 $this->language->loadLanguageModule('certificate');
92
93 $object = $this->objectHelper->getInstanceByObjId($objId);
94 $points = $object->getPointsInPercent();
95 if (is_null($points)) {
96 $txtPoints = $this->language->txt('certificate_points_notavailable');
97 } else {
98 $txtPoints = number_format(
99 $points,
100 1,
101 $this->language->txt('lang_sep_decimal'),
102 $this->language->txt('lang_sep_thousand')
103 ) . ' %';
104 }
105
106 $max_points = $object->getMaxPoints();
107 $txtMaxPoints = (string) $max_points;
108 if (is_null($max_points)) {
109 $txtMaxPoints = $this->language->txt('certificate_points_notavailable');
110 } elseif ($max_points != floor($max_points)) {
111 $txtMaxPoints = number_format(
112 $max_points,
113 1,
114 $this->language->txt('lang_sep_decimal'),
115 $this->language->txt('lang_sep_thousand')
116 );
117 }
118
119 $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
120
121 $placeHolders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
122
123 $placeHolders['SCORM_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
124 $placeHolders['SCORM_POINTS'] = $txtPoints;
125 $placeHolders['SCORM_POINTS_MAX'] = $txtMaxPoints;
126
127 $placeHolders['DATE_COMPLETED'] = '';
128 $placeHolders['DATETIME_COMPLETED'] = '';
129
130 if ($completionDate !== '') {
132 $user = $this->objectHelper->getInstanceByObjId($userId);
133 $placeHolders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate, $user);
134 $placeHolders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate, $user);
135 }
136
137 $olp = $this->objectLPHelper->getInstance($object->getId());
138 $collection = $olp->getCollectionInstance();
139
140 if ($collection !== null) {
141 $counter = 0;
142 foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
143 if ($collection->isAssignedEntry($item_id)) {
144 $placeHolders['SCO_T_' . $counter] = $sahs_item['title'];
145 $a_scores = $collection->getScoresForUserAndCP_Node_Id($item_id, $userId);
146
147 $placeHolders['SCO_P_' . $counter] = $this->language->txt('certificate_points_notavailable');
148 if ($a_scores['raw'] !== null) {
149 $placeHolders['SCO_P_' . $counter] = number_format(
150 (float) $a_scores['raw'],
151 1,
152 $this->language->txt('lang_sep_decimal'),
153 $this->language->txt('lang_sep_thousand')
154 );
155 }
156
157 $placeHolders['SCO_PM_' . $counter] = $this->language->txt('certificate_points_notavailable');
158 if ($a_scores['max'] !== null) {
159 $placeHolders['SCO_PM_' . $counter] = number_format(
160 (float) $a_scores['max'],
161 1,
162 $this->language->txt('lang_sep_decimal'),
163 $this->language->txt('lang_sep_thousand')
164 );
165 }
166
167 $placeHolders['SCO_PP_' . $counter] = $this->language->txt('certificate_points_notavailable');
168 if ($a_scores['scaled'] !== null) {
169 $placeHolders['SCO_PP_' . $counter] = number_format(
170 (float) ($a_scores['scaled'] * 100),
171 1,
172 $this->language->txt('lang_sep_decimal'),
173 $this->language->txt('lang_sep_thousand')
174 );
175
176 $placeHolders['SCO_PP_' . $counter] .= ' %';
177 }
178
179 $counter++;
180 }
181 }
182 }
183
184 return $placeHolders;
185 }
186
192 public function getPlaceholderValuesForPreview(int $userId, int $objId): array
193 {
194 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
195
196 $object = $this->objectHelper->getInstanceByObjId($objId);
197
198 $placeholders['SCORM_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
199
200 $placeholders['SCORM_POINTS'] = number_format(
201 80.7,
202 1,
203 $this->language->txt('lang_sep_decimal'),
204 $this->language->txt('lang_sep_thousand')
205 ) . ' %';
206
207 $placeholders['SCORM_POINTS_MAX'] = number_format(
208 90,
209 0,
210 $this->language->txt('lang_sep_decimal'),
211 $this->language->txt('lang_sep_thousand')
212 );
213
214 $insert_tags = [];
215 foreach ($placeholders as $id => $caption) {
216 $insert_tags[$id] = $caption;
217 }
218
219 $olp = $this->objectLPHelper->getInstance($objId);
220 $collection = $olp->getCollectionInstance();
221
222 if ($collection !== null) {
223 $counter = 0;
224 foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
225 if ($collection->isAssignedEntry($item_id)) {
226 $insert_tags['SCO_T_' . $counter] = $sahs_item['title'];
227
228 $insert_tags['SCO_P_' . $counter] = number_format(
229 30.3,
230 1,
231 $this->language->txt('lang_sep_decimal'),
232 $this->language->txt('lang_sep_thousand')
233 );
234
235 $insert_tags['SCO_PM_' . $counter] = number_format(
236 90.9,
237 1,
238 $this->language->txt('lang_sep_decimal'),
239 $this->language->txt('lang_sep_thousand')
240 );
241
242 $insert_tags['SCO_PP_' . $counter] = number_format(
243 33.3333,
244 1,
245 $this->language->txt('lang_sep_decimal'),
246 $this->language->txt('lang_sep_thousand')
247 ) . ' %';
248
249 $counter++;
250 }
251 }
252 }
253
254 return $insert_tags;
255 }
256}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Just a wrapper class to create Unit Test for other classes.
Collection of basic placeholder values that can be used.
language handling
loadLanguageModule(string $a_module)
Load language module.
__construct(?ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ?ilLanguage $language=null, ?ilCertificateDateHelper $dateHelper=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilCertificateObjectLPHelper $objectLPHelper=null, ?ilCertificateLPStatusHelper $lpStatusHelper=null)
readonly ilCertificateObjectLPHelper $objectLPHelper
readonly ilDefaultPlaceholderValues $defaultPlaceholderValuesObject
readonly ilCertificateObjectHelper $objectHelper
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
readonly ilCertificateLPStatusHelper $lpStatusHelper
readonly ilCertificateUtilHelper $utilHelper
readonly ilCertificateDateHelper $dateHelper
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
global $DIC
Definition: shib_login.php:26
$counter
$objId
Definition: xapitoken.php:57