ILIAS  release_8 Revision v8.24
class.ilCoursePlaceholderValues.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
34
35 public function __construct(
36 ?ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValues = null,
37 ?ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
38 ?ilLanguage $language = null,
44 ) {
45 if (null === $language) {
46 global $DIC;
47 $language = $DIC->language();
48 $language->loadLanguageModule('certificate');
49 }
50 $this->language = $language;
51
52 if (null === $defaultPlaceholderValues) {
53 $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
54 }
55
56 if (null === $customUserFieldsPlaceholderValues) {
57 $customUserFieldsPlaceholderValues = new ilObjectCustomUserFieldsPlaceholderValues();
58 }
59
60 if (null === $objectHelper) {
62 }
63 $this->objectHelper = $objectHelper;
64
65 if (null === $participantsHelper) {
67 }
68 $this->participantsHelper = $participantsHelper;
69
70 if (null === $ilUtilHelper) {
72 }
73 $this->ilUtilHelper = $ilUtilHelper;
74
75 if (null === $dateHelper) {
77 }
78 $this->dateHelper = $dateHelper;
79
80 if (null === $lpStatusHelper) {
82 }
83 $this->lpStatusHelper = $lpStatusHelper;
84
85 $this->customUserFieldsPlaceholderValuesObject = $customUserFieldsPlaceholderValues;
86 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
87 }
88
93 private function hasCompletionDate($possibleDate): bool
94 {
95 return (
96 $possibleDate !== false &&
97 $possibleDate !== null &&
98 $possibleDate !== ''
99 );
100 }
101
117 public function getPlaceholderValues(int $userId, int $objId): array
118 {
119 $courseObject = $this->objectHelper->getInstanceByObjId($objId);
120
121 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
122
123 $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValues(
124 $userId,
125 $objId
126 );
127
128 $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
129
130 $completionDate = $this->participantsHelper->getDateTimeOfPassed($objId, $userId);
131 if (!$this->hasCompletionDate($completionDate)) {
132 $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
133 }
134
135 if ($this->hasCompletionDate($completionDate)) {
136 $placeholders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate);
137 $placeholders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate);
138 }
139
140 $placeholders['COURSE_TITLE'] = $this->ilUtilHelper->prepareFormOutput($courseObject->getTitle());
141
142 return $placeholders;
143 }
144
157 public function getPlaceholderValuesForPreview(int $userId, int $objId): array
158 {
159 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
160
161 $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValuesForPreview(
162 $userId,
163 $objId
164 );
165
166 $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
167
168 $object = $this->objectHelper->getInstanceByObjId($objId);
169
170 $placeholders['COURSE_TITLE'] = ilLegacyFormElementsUtil::prepareFormOutput($object->getTitle());
171
172 return $placeholders;
173 }
174}
Just a wrapper class to create Unit Test for other classes.
ilCertificateLPStatusHelper $lpStatusHelper
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
ilDefaultPlaceholderValues $defaultPlaceholderValuesObject
ilCertificateParticipantsHelper $participantsHelper
ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValuesObject
__construct(?ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValues=null, ?ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ?ilLanguage $language=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateParticipantsHelper $participantsHelper=null, ?ilCertificateUtilHelper $ilUtilHelper=null, ?ilCertificateDateHelper $dateHelper=null, ?ilCertificateLPStatusHelper $lpStatusHelper=null)
Collection of basic placeholder values that can be used.
language handling
loadLanguageModule(string $a_module)
Load language module.
static prepareFormOutput($a_str, bool $a_strip=false)
global $DIC
Definition: feed.php:28
$objId
Definition: xapitoken.php:57