ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilScormPlaceholderValues.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
12  private $language;
13 
18 
22  private $dateHelper;
23 
27  private $objectHelper;
28 
32  private $utilHelper;
33 
37  private $objectLPHelper;
38 
42  private $lpStatusHelper;
43 
53  public function __construct(
54  ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
55  ilLanguage $language = null,
61  ) {
62  if (null === $language) {
63  global $DIC;
64  $language = $DIC->language();
65  }
66  $this->language = $language;
67 
68  if (null === $defaultPlaceholderValues) {
69  $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
70  }
71  $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
72 
73  if (null === $dateHelper) {
75  }
76  $this->dateHelper = $dateHelper;
77 
78  if (null === $objectHelper) {
80  }
81  $this->objectHelper = $objectHelper;
82 
83  if (null === $utilHelper) {
85  }
86  $this->utilHelper = $utilHelper;
87 
88  if (null === $objectLPHelper) {
90  }
91  $this->objectLPHelper = $objectLPHelper;
92 
93  if (null === $lpStatusHelper) {
95  }
96  $this->lpStatusHelper = $lpStatusHelper;
97  }
98 
113  public function getPlaceholderValues(int $userId, int $objId) : array
114  {
115  $this->language->loadLanguageModule('certificate');
116 
117  $object = $this->objectHelper->getInstanceByObjId($objId);
118  $points = $object->getPointsInPercent();
119  $txtPoints = number_format($points, 1, $this->language->txt('lang_sep_decimal'), $this->language->txt('lang_sep_thousand')) . ' %';
120  if (is_null($points)) {
121  $txtPoints = $this->language->txt('certificate_points_notavailable');
122  }
123 
124  $max_points = $object->getMaxPoints();
125  $txtMaxPoints = $max_points;
126  if (is_null($max_points)) {
127  $txtMaxPoints = $this->language->txt('certificate_points_notavailable');
128  } elseif ($max_points != floor($max_points)) {
129  $txtMaxPoints = number_format($max_points, 1, $this->language->txt('lang_sep_decimal'), $this->language->txt('lang_sep_thousand'));
130  }
131 
132  $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
133 
134  $placeHolders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
135 
136  $placeHolders['SCORM_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
137  $placeHolders['SCORM_POINTS'] = $txtPoints;
138  $placeHolders['SCORM_POINTS_MAX'] = $txtMaxPoints;
139 
140  $placeHolders['DATE_COMPLETED'] = '';
141  $placeHolders['DATETIME_COMPLETED'] = '';
142 
143  if ($completionDate !== false &&
144  $completionDate !== null &&
145  $completionDate !== ''
146  ) {
147  $placeHolders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate);
148  $placeHolders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate);
149  }
150 
151  $olp = $this->objectLPHelper->getInstance($object->getId());
152  $collection = $olp->getCollectionInstance();
153 
154  if ($collection) {
155  $counter = 0;
156  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
157  if ($collection->isAssignedEntry($item_id)) {
158  $placeHolders['SCO_T_' . $counter] = $sahs_item['title'];
159  $a_scores = $collection->getScoresForUserAndCP_Node_Id($item_id, $userId);
160 
161  $placeHolders['SCO_P_' . $counter] = $this->language->txt('certificate_points_notavailable');
162  if ($a_scores['raw'] !== null) {
163  $placeHolders['SCO_P_' . $counter] = number_format(
164  $a_scores['raw'],
165  1,
166  $this->language->txt('lang_sep_decimal'),
167  $this->language->txt('lang_sep_thousand')
168  );
169  }
170 
171  $placeHolders['SCO_PM_' . $counter] = $this->language->txt('certificate_points_notavailable');
172  if ($a_scores['max'] !== null) {
173  $placeHolders['SCO_PM_' . $counter] = number_format(
174  $a_scores['max'],
175  1,
176  $this->language->txt('lang_sep_decimal'),
177  $this->language->txt('lang_sep_thousand')
178  );
179  }
180 
181  $placeHolders['SCO_PP_' . $counter] = $this->language->txt('certificate_points_notavailable');
182  if ($a_scores['scaled'] !== null) {
183  $placeHolders['SCO_PP_' . $counter] = number_format(
184  ($a_scores['scaled'] * 100),
185  1,
186  $this->language->txt('lang_sep_decimal'),
187  $this->language->txt('lang_sep_thousand')
188  );
189 
190  $placeHolders['SCO_PP_' . $counter] .= ' %';
191  }
192 
193  $counter++;
194  }
195  }
196  }
197 
198  return $placeHolders;
199  }
200 
210  public function getPlaceholderValuesForPreview(int $userId, int $objId) : array
211  {
212  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
213 
214  $object = $this->objectHelper->getInstanceByObjId($objId);
215 
216  $placeholders['SCORM_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
217 
218  $placeholders['SCORM_POINTS'] = number_format(
219  80.7,
220  1,
221  $this->language->txt('lang_sep_decimal'),
222  $this->language->txt('lang_sep_thousand')
223  ) . ' %';
224 
225  $placeholders['SCORM_POINTS_MAX'] = number_format(
226  90,
227  0,
228  $this->language->txt('lang_sep_decimal'),
229  $this->language->txt('lang_sep_thousand')
230  );
231 
232  $insert_tags = array();
233  foreach ($placeholders as $id => $caption) {
234  $insert_tags[$id] = $caption;
235  }
236 
237  $olp = $this->objectLPHelper->getInstance($objId);
238  $collection = $olp->getCollectionInstance();
239 
240  if ($collection) {
241  $counter = 0;
242  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
243  if ($collection->isAssignedEntry($item_id)) {
244  $insert_tags['SCO_T_' . $counter] = $sahs_item['title'];
245 
246  $insert_tags['SCO_P_' . $counter] = number_format(
247  30.3,
248  1,
249  $this->language->txt('lang_sep_decimal'),
250  $this->language->txt('lang_sep_thousand')
251  );
252 
253  $insert_tags['SCO_PM_' . $counter] = number_format(
254  90.9,
255  1,
256  $this->language->txt('lang_sep_decimal'),
257  $this->language->txt('lang_sep_thousand')
258  );
259 
260  $insert_tags['SCO_PP_' . $counter] = number_format(
261  33.3333,
262  1,
263  $this->language->txt('lang_sep_decimal'),
264  $this->language->txt('lang_sep_thousand')
265  ) . ' %';
266 
267  $counter++;
268  }
269  }
270  }
271 
272  return $insert_tags;
273  }
274 }
Collection of basic placeholder values that can be used.
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
Just a wrapper class to create Unit Test for other classes.
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
__construct(ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ilLanguage $language=null, ilCertificateDateHelper $dateHelper=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateObjectLPHelper $objectLPHelper=null, ilCertificateLPStatusHelper $lpStatusHelper=null)
language handling