ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestPlaceholderValues.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{
13
18
23
28
32 private $utilHelper;
33
38
42 private $dateHelper;
43
47 private $language;
48
59 public function __construct(
60 ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
61 ilLanguage $language = null,
68 ) {
69 if (null === $language) {
70 global $DIC;
71 $language = $DIC->language();
72 }
73 $this->language = $language;
74
75 if (null === $defaultPlaceholderValues) {
76 $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
77 }
78 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
79
80 if (null === $objectHelper) {
82 }
83 $this->objectHelper = $objectHelper;
84
85 if (null === $testObjectHelper) {
87 }
88 $this->testObjectHelper = $testObjectHelper;
89
90 if (null === $userObjectHelper) {
92 }
93 $this->userObjectHelper = $userObjectHelper;
94
95 if (null === $lpStatusHelper) {
97 }
98 $this->lpStatusHelper = $lpStatusHelper;
99
100 if (null === $utilHelper) {
102 }
103 $this->utilHelper = $utilHelper;
104
105 if (null === $dateHelper) {
107 }
108 $this->dateHelper = $dateHelper;
109 }
110
125 public function getPlaceholderValues(int $userId, int $objId) : array
126 {
128 $testObject = $this->objectHelper->getInstanceByObjId($objId);
129
130 $active_id = $testObject->getActiveIdOfUser($userId);
131 $pass = $this->testObjectHelper->getResultPass($active_id);
132
133 $result_array = &$testObject->getTestResult($active_id);
134 if (strlen($pass)) {
135 $result_array = &$testObject->getTestResult($active_id, $pass);
136 }
137
138 $passed = $this->language->txt('certificate_failed');
139 if ($result_array['test']['passed']) {
140 $passed = $this->language->txt('certificate_passed');
141 }
142
143 $percentage = 0;
144 if ($result_array['test']['total_max_points']) {
145 $percentage = ($result_array['test']['total_reached_points'] / $result_array['test']['total_max_points']) * 100;
146 }
147
148 $mark_obj = $testObject->getMarkSchema()->getMatchingMark($percentage);
149 $user_data = $this->userObjectHelper->lookupFields($userId);
150
151 $completionDate = false;
152 if ($user_data['usr_id'] > 0) {
153 $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
154 }
155
156 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
157
158 $placeholders['RESULT_PASSED'] = $this->utilHelper->prepareFormOutput($passed);
159 $placeholders['RESULT_POINTS'] = $this->utilHelper->prepareFormOutput($result_array['test']['total_reached_points']);
160 $placeholders['RESULT_PERCENT'] = sprintf('%2.2f', $percentage) . '%';
161 $placeholders['MAX_POINTS'] = $this->utilHelper->prepareFormOutput($result_array['test']['total_max_points']);
162 $placeholders['RESULT_MARK_SHORT'] = $this->utilHelper->prepareFormOutput($mark_obj->getShortName());
163 $placeholders['RESULT_MARK_LONG'] = $this->utilHelper->prepareFormOutput($mark_obj->getOfficialName());
164 $placeholders['TEST_TITLE'] = $this->utilHelper->prepareFormOutput($testObject->getTitle());
165 $placeholders['DATE_COMPLETED'] = '';
166 $placeholders['DATETIME_COMPLETED'] = '';
167
168 if ($completionDate !== false &&
169 $completionDate !== null &&
170 $completionDate !== ''
171 ) {
172 $placeholders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate);
173 $placeholders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate);
174 }
175
176 return $placeholders;
177 }
178
188 public function getPlaceholderValuesForPreview(int $userId, int $objId) : array
189 {
190 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
191
192 $object = $this->objectHelper->getInstanceByObjId($objId);
193
194 $placeholders['RESULT_PASSED'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_result_passed'));
195 $placeholders['RESULT_POINTS'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_result_points'));
196 $placeholders['RESULT_PERCENT'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_result_percent'));
197 $placeholders['MAX_POINTS'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_max_points'));
198 $placeholders['RESULT_MARK_SHORT'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_result_mark_short'));
199 $placeholders['RESULT_MARK_LONG'] = $this->utilHelper->prepareFormOutput($this->language->txt('certificate_var_result_mark_long'));
200 $placeholders['TEST_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
201
202 return $placeholders;
203 }
204}
An exception for terminatinating execution or to throw for unit testing.
Just a wrapper class to create Unit Test for other classes.
Collection of basic placeholder values that can be used.
language handling
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
__construct(ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ilLanguage $language=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateTestObjectHelper $testObjectHelper=null, ilCertificateUserObjectHelper $userObjectHelper=null, ilCertificateLPStatusHelper $lpStatusHelper=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateDateHelper $dateHelper=null)
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: saml.php:7