ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDefaultPlaceholderValues.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
29{
30 private readonly array $placeholder;
33 private readonly int $unix_ts_format_id;
34 private readonly int $birthdayDateFormat;
35 private readonly ilLanguage $language;
38 private readonly Factory $uuid_factory;
39 private ?ilLanguage $user_language = null;
40
41
42 public function __construct(
45 ?int $unix_ts_format_id = null,
46 ?ilLanguage $language = null,
47 ?Profile $profile = null,
50 ?ILIAS\Data\UUID\Factory $uuid_factory = null,
51 ?int $birthdayDateFormat = null
52 ) {
53 $this->objectHelper = $objectHelper ?? new ilCertificateObjectHelper();
54 $this->dateHelper = $dateHelper ?? new ilCertificateDateHelper();
55
56 require_once __DIR__ . '/../../../../Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
57
58 $this->unix_ts_format_id = $unix_ts_format_id ?? IL_CAL_UNIX;
59 $this->birthdayDateFormat = $birthdayDateFormat ?? IL_CAL_DATE;
60
61 global $DIC;
62 if (null === $language) {
63 $language = $DIC->language();
64 $language->loadLanguageModule('certificate');
65 }
66 $this->language = $language;
67
68 $profile ??= $DIC['user']->getProfile();
69
70 $this->utilHelper = $utilHelper ?? new ilCertificateUtilHelper();
71 $this->userDefinedFieldsPlaceholderValues =
73 $this->language,
74 new ilCertificateObjectHelper(),
75 $profile,
77 );
78 $this->uuid_factory = $uuid_factory ?? new ILIAS\Data\UUID\Factory();
79
80 $this->placeholder = [
81 'CERTIFICATE_ID' => '',
82 'USER_LOGIN' => '',
83 'USER_FULLNAME' => '',
84 'USER_FIRSTNAME' => '',
85 'USER_LASTNAME' => '',
86 'USER_TITLE' => '',
87 'USER_SALUTATION' => '',
88 'USER_BIRTHDAY' => '',
89 'USER_INSTITUTION' => '',
90 'USER_DEPARTMENT' => '',
91 'USER_STREET' => '',
92 'USER_CITY' => '',
93 'USER_ZIPCODE' => '',
94 'USER_COUNTRY' => '',
95 'USER_MATRICULATION' => '',
96 'DATE' => '',
97 'DATETIME' => '',
98 'DATE_COMPLETED' => '',
99 'DATETIME_COMPLETED' => '',
100 ];
101 }
102
110 public function getPlaceholderValues(int $userId, int $objId): array
111 {
113 $user = $this->objectHelper->getInstanceByObjId($userId);
114 if (!$user instanceof ilObjUser) {
115 throw new ilException('The entered id: ' . $userId . ' is not an user object');
116 }
117 $user_lng = $this->getUserLanguage($user);
119
120 $placeholder['USER_LOGIN'] = $this->utilHelper->prepareFormOutput((trim($user->getLogin())));
121 $placeholder['USER_FULLNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFullname())));
122 $placeholder['USER_FIRSTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFirstname())));
123 $placeholder['USER_LASTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getLastname())));
124 $placeholder['USER_TITLE'] = $this->utilHelper->prepareFormOutput((trim($user->getUTitle())));
125
126 $salutation = '';
127 $gender = $user->getGender();
128 if (trim($gender) !== '' && strtolower($gender) !== 'n') {
129 $salutation = $this->utilHelper->prepareFormOutput($user_lng->txt("salutation_" . trim($gender)));
130 }
131
132 $placeholder['USER_SALUTATION'] = $salutation;
133
134 $birthday = '';
135 $dateObject = $user->getBirthday();
136 if (null !== $dateObject) {
137 $birthday = $this->dateHelper->formatDate($dateObject, $user, $this->birthdayDateFormat);
138 }
139
140 $placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
141 $placeholder['USER_INSTITUTION'] = $this->utilHelper->prepareFormOutput((trim($user->getInstitution())));
142 $placeholder['USER_DEPARTMENT'] = $this->utilHelper->prepareFormOutput((trim($user->getDepartment())));
143 $placeholder['USER_STREET'] = $this->utilHelper->prepareFormOutput((trim($user->getStreet())));
144 $placeholder['USER_CITY'] = $this->utilHelper->prepareFormOutput((trim($user->getCity())));
145 $placeholder['USER_ZIPCODE'] = $this->utilHelper->prepareFormOutput((trim($user->getZipcode())));
146 $placeholder['USER_COUNTRY'] = $this->utilHelper->prepareFormOutput((trim($user->getCountry())));
147 $placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
148 $placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
149 time(),
150 $user,
151 $this->unix_ts_format_id
152 ))));
153 $placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
154 time(),
155 $user,
156 $this->unix_ts_format_id
157 ))));
158
159 return array_merge(
161 $this->userDefinedFieldsPlaceholderValues->getPlaceholderValues($userId, $objId)
162 );
163 }
164
174 public function getPlaceholderValuesForPreview(int $userId, int $objId): array
175 {
176 $previewPlacholderValues = [
177 'CERTIFICATE_ID' => $this->utilHelper->prepareFormOutput($this->uuid_factory->uuid4AsString()),
178 "USER_LOGIN" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_login")),
179 "USER_FULLNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_fullname")),
180 "USER_FIRSTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_firstname")),
181 "USER_LASTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_lastname")),
182 "USER_TITLE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_title")),
183 "USER_SALUTATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_salutation")),
184 "USER_BIRTHDAY" => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
185 time(),
186 null,
187 $this->unix_ts_format_id
188 )))),
189 "USER_INSTITUTION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_institution")),
190 "USER_DEPARTMENT" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_department")),
191 "USER_STREET" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_street")),
192 "USER_CITY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_city")),
193 "USER_ZIPCODE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_zipcode")),
194 "USER_COUNTRY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_country")),
195 "USER_MATRICULATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_matriculation")),
196 'DATE' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
197 time(),
198 null,
199 $this->unix_ts_format_id
200 )))),
201 'DATETIME' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
202 time(),
203 null,
204 $this->unix_ts_format_id
205 )))),
206 'DATE_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
207 time(),
208 null,
209 $this->unix_ts_format_id
210 )))),
211 'DATETIME_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
212 time(),
213 null,
214 $this->unix_ts_format_id
215 ))))
216 ];
217
218 return array_merge(
219 $previewPlacholderValues,
220 $this->userDefinedFieldsPlaceholderValues->getPlaceholderValuesForPreview($userId, $objId)
221 );
222 }
223
224 private function getUserLanguage(ilObjUser $user): ilLanguage
225 {
226 if ($this->user_language instanceof ilLanguage) {
228 }
229 $language = new ilLanguage($user->getLanguage());
230 $language->loadLanguageModule('certificate');
231 $this->user_language = $language;
232 return $language;
233 }
234
238 public function setUserLanguage(ilLanguage $language): void
239 {
240 $this->user_language = $language;
241 }
242}
const IL_CAL_DATE
const IL_CAL_UNIX
Just a wrapper class to create Unit Test for other classes.
Collection of basic placeholder values that can be used.
readonly ilCertificateObjectHelper $objectHelper
readonly ilCertificateDateHelper $dateHelper
readonly ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
__construct(?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateDateHelper $dateHelper=null, ?int $unix_ts_format_id=null, ?ilLanguage $language=null, ?Profile $profile=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues=null, ?ILIAS\Data\UUID\Factory $uuid_factory=null, ?int $birthdayDateFormat=null)
readonly ilCertificateUtilHelper $utilHelper
Base class for ILIAS Exception handling.
language handling
loadLanguageModule(string $a_module)
Load language module.
User class.
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57