ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TestPlaceholderValues.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\Certificate;
22 
27 {
28  private readonly \ilDefaultPlaceholderValues $defaultPlaceholderValuesObject;
29  private readonly \ilCertificateObjectHelper $objectHelper;
31  private readonly \ilCertificateUserObjectHelper $userObjectHelper;
32  private readonly \ilCertificateUtilHelper $utilHelper;
33  private readonly \ilCertificateLPStatusHelper $lpStatusHelper;
34  private readonly \ilCertificateDateHelper $dateHelper;
35  private readonly \ilLanguage $language;
36 
37  public function __construct(
38  ?\ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
39  ?\ilLanguage $language = null,
40  ?\ilCertificateObjectHelper $objectHelper = null,
41  ?CertificateTestObjectHelper $testObjectHelper = null,
42  ?\ilCertificateUserObjectHelper $userObjectHelper = null,
43  ?\ilCertificateLPStatusHelper $lpStatusHelper = null,
44  ?\ilCertificateUtilHelper $utilHelper = null,
45  ?\ilCertificateDateHelper $dateHelper = null
46  ) {
47  if (null === $language) {
48  global $DIC;
49  $language = $DIC->language();
50  $language->loadLanguageModule('certificate');
51  }
52  $this->language = $language;
53 
54  if (null === $defaultPlaceholderValues) {
55  $defaultPlaceholderValues = new \ilDefaultPlaceholderValues();
56  }
57  $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
58 
59  if (null === $objectHelper) {
60  $objectHelper = new \ilCertificateObjectHelper();
61  }
62  $this->objectHelper = $objectHelper;
63 
64  if (null === $testObjectHelper) {
65  $testObjectHelper = new CertificateTestObjectHelper();
66  }
67  $this->testObjectHelper = $testObjectHelper;
68 
69  if (null === $userObjectHelper) {
70  $userObjectHelper = new \ilCertificateUserObjectHelper();
71  }
72  $this->userObjectHelper = $userObjectHelper;
73 
74  if (null === $lpStatusHelper) {
75  $lpStatusHelper = new \ilCertificateLPStatusHelper();
76  }
77  $this->lpStatusHelper = $lpStatusHelper;
78 
79  if (null === $utilHelper) {
80  $utilHelper = new \ilCertificateUtilHelper();
81  }
82  $this->utilHelper = $utilHelper;
83 
84  if (null === $dateHelper) {
85  $dateHelper = new \ilCertificateDateHelper();
86  }
87  $this->dateHelper = $dateHelper;
88  }
89 
101  public function getPlaceholderValues(int $user_id, int $obj_id): array
102  {
104  $testObject = $this->objectHelper->getInstanceByObjId($obj_id);
105 
106  $active_id = $testObject->getActiveIdOfUser($user_id);
107  if ($active_id === null) {
108  throw new \ilInvalidCertificateException('No active id found for user ' . $user_id . ' and object ' . $obj_id);
109  }
110  $pass = $this->testObjectHelper->getResultPass($active_id);
111 
112  $result_array = $testObject->getTestResult($active_id);
113  if ($pass !== null) {
114  $result_array = $testObject->getTestResult($active_id, $pass);
115  }
116 
117  $passed = $this->language->txt('certificate_failed');
118  if ($result_array['test']['passed']) {
119  $passed = $this->language->txt('certificate_passed');
120  }
121 
122  $percentage = 0;
123  if ($result_array['test']['total_max_points']) {
124  $percentage = ($result_array['test']['total_reached_points'] / $result_array['test']['total_max_points']) * 100;
125  }
126 
127  $mark_obj = $testObject->getMarkSchema()->getMatchingMark($percentage);
128  $user_data = $this->userObjectHelper->lookupFields($user_id);
129 
130  $completionDate = false;
131  if ($user_data['usr_id'] > 0) {
132  $completionDate = $this->lpStatusHelper->lookupStatusChanged($obj_id, $user_id);
133  }
134 
135  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($user_id, $obj_id);
136 
137  $placeholders['RESULT_PASSED'] = $this->utilHelper->prepareFormOutput($passed);
138  $placeholders['RESULT_POINTS'] = $this->utilHelper->prepareFormOutput(
139  (string) $result_array['test']['total_reached_points']
140  );
141  $placeholders['RESULT_PERCENT'] = sprintf('%2.2f', $percentage) . '%';
142  $placeholders['MAX_POINTS'] = $this->utilHelper->prepareFormOutput(
143  (string) $result_array['test']['total_max_points']
144  );
145  $placeholders['RESULT_MARK_SHORT'] = $this->utilHelper->prepareFormOutput($mark_obj->getShortName());
146  $placeholders['RESULT_MARK_LONG'] = $this->utilHelper->prepareFormOutput($mark_obj->getOfficialName());
147  $placeholders['TEST_TITLE'] = $this->utilHelper->prepareFormOutput($testObject->getTitle());
148  $placeholders['DATE_COMPLETED'] = '';
149  $placeholders['DATETIME_COMPLETED'] = '';
150 
151  if ($completionDate !== false && $completionDate !== '') {
153  $user = $this->objectHelper->getInstanceByObjId($user_id);
154  $placeholders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate, $user);
155  $placeholders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate, $user);
156  }
157 
158  return $placeholders;
159  }
160 
166  public function getPlaceholderValuesForPreview(int $userId, int $objId): array
167  {
168  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
169 
170  $object = $this->objectHelper->getInstanceByObjId($objId);
171 
172  $placeholders['RESULT_PASSED'] = $this->utilHelper->prepareFormOutput(
173  $this->language->txt('certificate_var_result_passed')
174  );
175  $placeholders['RESULT_POINTS'] = $this->utilHelper->prepareFormOutput(
176  $this->language->txt('certificate_var_result_points')
177  );
178  $placeholders['RESULT_PERCENT'] = $this->utilHelper->prepareFormOutput(
179  $this->language->txt('certificate_var_result_percent')
180  );
181  $placeholders['MAX_POINTS'] = $this->utilHelper->prepareFormOutput(
182  $this->language->txt('certificate_var_max_points')
183  );
184  $placeholders['RESULT_MARK_SHORT'] = $this->utilHelper->prepareFormOutput(
185  $this->language->txt('certificate_var_result_mark_short')
186  );
187  $placeholders['RESULT_MARK_LONG'] = $this->utilHelper->prepareFormOutput(
188  $this->language->txt('certificate_var_result_mark_long')
189  );
190  $placeholders['TEST_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
191 
192  return $placeholders;
193  }
194 }
readonly ilDefaultPlaceholderValues $defaultPlaceholderValuesObject
$objId
Definition: xapitoken.php:57
__construct(?\ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ?\ilLanguage $language=null, ?\ilCertificateObjectHelper $objectHelper=null, ?CertificateTestObjectHelper $testObjectHelper=null, ?\ilCertificateUserObjectHelper $userObjectHelper=null, ?\ilCertificateLPStatusHelper $lpStatusHelper=null, ?\ilCertificateUtilHelper $utilHelper=null, ?\ilCertificateDateHelper $dateHelper=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly ilCertificateLPStatusHelper $lpStatusHelper
global $DIC
Definition: shib_login.php:22
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different from the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
readonly ilCertificateUserObjectHelper $userObjectHelper
readonly ilCertificateObjectHelper $objectHelper
readonly ilCertificateDateHelper $dateHelper
readonly ilCertificateUtilHelper $utilHelper
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()
description: > Example for rendring a language glyph.
Definition: language.php:41
readonly CertificateTestObjectHelper $testObjectHelper