19 declare(strict_types=1);
47 if (
null === $language) {
49 $language = $DIC->language();
50 $language->loadLanguageModule(
'certificate');
54 if (
null === $defaultPlaceholderValues) {
55 $defaultPlaceholderValues = new \ilDefaultPlaceholderValues();
57 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
59 if (
null === $objectHelper) {
60 $objectHelper = new \ilCertificateObjectHelper();
64 if (
null === $testObjectHelper) {
69 if (
null === $userObjectHelper) {
70 $userObjectHelper = new \ilCertificateUserObjectHelper();
74 if (
null === $lpStatusHelper) {
75 $lpStatusHelper = new \ilCertificateLPStatusHelper();
79 if (
null === $utilHelper) {
80 $utilHelper = new \ilCertificateUtilHelper();
84 if (
null === $dateHelper) {
85 $dateHelper = new \ilCertificateDateHelper();
104 $testObject = $this->objectHelper->getInstanceByObjId($obj_id);
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);
110 $pass = $this->testObjectHelper->getResultPass($active_id);
112 $result_array = $testObject->getTestResult($active_id);
113 if ($pass !==
null) {
114 $result_array = $testObject->getTestResult($active_id, $pass);
117 $passed = $this->
language->txt(
'certificate_failed');
118 if ($result_array[
'test'][
'passed']) {
119 $passed = $this->
language->txt(
'certificate_passed');
123 if ($result_array[
'test'][
'total_max_points']) {
124 $percentage = ($result_array[
'test'][
'total_reached_points'] / $result_array[
'test'][
'total_max_points']) * 100;
127 $mark_obj = $testObject->getMarkSchema()->getMatchingMark($percentage);
128 $user_data = $this->userObjectHelper->lookupFields($user_id);
130 $completionDate =
false;
131 if ($user_data[
'usr_id'] > 0) {
132 $completionDate = $this->lpStatusHelper->lookupStatusChanged($obj_id, $user_id);
135 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($user_id, $obj_id);
137 $placeholders[
'RESULT_PASSED'] = $this->utilHelper->prepareFormOutput($passed);
138 $placeholders[
'RESULT_POINTS'] = $this->utilHelper->prepareFormOutput(
139 (
string) $result_array[
'test'][
'total_reached_points']
141 $placeholders[
'RESULT_PERCENT'] = sprintf(
'%2.2f', $percentage) .
'%';
142 $placeholders[
'MAX_POINTS'] = $this->utilHelper->prepareFormOutput(
143 (
string) $result_array[
'test'][
'total_max_points']
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'] =
'';
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);
158 return $placeholders;
168 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
170 $object = $this->objectHelper->getInstanceByObjId($objId);
172 $placeholders[
'RESULT_PASSED'] = $this->utilHelper->prepareFormOutput(
173 $this->
language->txt(
'certificate_var_result_passed')
175 $placeholders[
'RESULT_POINTS'] = $this->utilHelper->prepareFormOutput(
176 $this->
language->txt(
'certificate_var_result_points')
178 $placeholders[
'RESULT_PERCENT'] = $this->utilHelper->prepareFormOutput(
179 $this->
language->txt(
'certificate_var_result_percent')
181 $placeholders[
'MAX_POINTS'] = $this->utilHelper->prepareFormOutput(
182 $this->
language->txt(
'certificate_var_max_points')
184 $placeholders[
'RESULT_MARK_SHORT'] = $this->utilHelper->prepareFormOutput(
185 $this->
language->txt(
'certificate_var_result_mark_short')
187 $placeholders[
'RESULT_MARK_LONG'] = $this->utilHelper->prepareFormOutput(
188 $this->
language->txt(
'certificate_var_result_mark_long')
190 $placeholders[
'TEST_TITLE'] = $this->utilHelper->prepareFormOutput($object->getTitle());
192 return $placeholders;
readonly ilDefaultPlaceholderValues $defaultPlaceholderValuesObject
__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
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different from the 'getPlaceholderValues' method, this method is used to create a plac...
readonly ilCertificateUserObjectHelper $userObjectHelper
readonly ilLanguage $language
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.
readonly CertificateTestObjectHelper $testObjectHelper