ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCmiXapiPlaceholderValues.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 
15 {
20 
24  private $objectHelper;
25 
30 
34  private $utilHelper;
35 
39  private $lpStatusHelper;
40 
44  private $dateHelper;
45 
49  private $language;
50 
61  public function __construct(
62  ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
63  ilLanguage $language = null,
69  ) {
70  if (null === $language) {
71  global $DIC;
72  $language = $DIC->language();
73  }
74  $this->language = $language;
75 
76  if (null === $defaultPlaceholderValues) {
77  $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
78  }
79  $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
80 
81  if (null === $objectHelper) {
83  }
84  $this->objectHelper = $objectHelper;
85 
86  if (null === $userObjectHelper) {
88  }
89  $this->userObjectHelper = $userObjectHelper;
90 
91  if (null === $lpStatusHelper) {
93  }
94  $this->lpStatusHelper = $lpStatusHelper;
95 
96  if (null === $utilHelper) {
98  }
99  $this->utilHelper = $utilHelper;
100 
101  if (null === $dateHelper) {
103  }
104  $this->dateHelper = $dateHelper;
105  }
106 
107  public function getPlaceholderValuesForPreview(int $userId, int $objId)
108  {
109  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
110 
111  $placeholders['OBJECT_TITLE'] = $this->utilHelper->prepareFormOutput($this->language->txt('lti_cert_ph_object_title'));
112  $placeholders['OBJECT_DESCRIPTION'] = $this->utilHelper->prepareFormOutput($this->language->txt('lti_cert_ph_object_description'));
113 
114  $placeholders['MASTERY_SCORE'] = $this->utilHelper->prepareFormOutput($this->language->txt('lti_cert_ph_mastery_score'));
115  $placeholders['REACHED_SCORE'] = $this->utilHelper->prepareFormOutput($this->language->txt('lti_cert_ph_reached_score'));
116 
117  return $placeholders;
118  }
119 
120  public function getPlaceholderValues(int $userId, int $objId) : array
121  {
122  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
123 
124  /* @var ilObjLTIConsumer $object */
125  $object = $this->objectHelper->getInstanceByObjId($objId);
126 
127  $placeholders['OBJECT_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
128  $placeholders['OBJECT_DESCRIPTION'] = $this->utilHelper->prepareFormOutput($object->getDescription());
129 
130  $placeholders['REACHED_SCORE'] = $this->utilHelper->prepareFormOutput($this->getReachedScore((int) $objId, (int) $userId));
131 
132  return $placeholders;
133  }
134 
135  protected function getReachedScore(int $objectId, int $userId) : string
136  {
137  try {
139  $objectId,
140  $userId
141  );
142  } catch (ilCmiXapiException $e) {
143  $cmixResult = ilCmiXapiResult::getEmptyInstance();
144  }
145 
146  $reachedScore = sprintf('%0.2f %%', $cmixResult->getScore() * 100);
147 
148  return $reachedScore;
149  }
150 }
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
Collection of basic placeholder values that can be used.
$objId
Definition: xapitoken.php:39
getReachedScore(int $objectId, int $userId)
__construct(ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ilLanguage $language=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateUserObjectHelper $userObjectHelper=null, ilCertificateLPStatusHelper $lpStatusHelper=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateDateHelper $dateHelper=null)
global $DIC
Definition: goto.php:24
static getInstanceByObjIdAndUsrId($objId, $usrId)
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...
language()
Definition: language.php:2