ILIAS  release_8 Revision v8.24
class.ilDefaultPlaceholderValues.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once 'Services/Calendar/classes/class.ilDateTime.php';
22
28{
29 private array $placeholder;
32 private int $dateFormat;
37
38 public function __construct(
41 ?int $dateFormat = null,
42 ?ilLanguage $language = null,
46 ) {
47 if (null === $objectHelper) {
49 }
50 $this->objectHelper = $objectHelper;
51
52 if (null === $dateHelper) {
54 }
55 $this->dateHelper = $dateHelper;
56
57 if (null === $dateFormat) {
59 }
60 $this->dateFormat = $dateFormat;
61
62 if (null === $language) {
63 global $DIC;
64 $language = $DIC->language();
65 $language->loadLanguageModule('certificate');
66 }
67 $this->language = $language;
68
69 if (null === $utilHelper) {
71 }
72 $this->utilHelper = $utilHelper;
73
76 }
77 $this->userDefinedFieldsPlaceholderValues = $userDefinedFieldsPlaceholderValues;
78
79 $this->birthdayDateFormat = $birthdayDateFormat;
80
81 $this->placeholder = [
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
113 public function getPlaceholderValues(int $userId, int $objId): array
114 {
116 $user = $this->objectHelper->getInstanceByObjId($userId);
117 if (!$user instanceof ilObjUser) {
118 throw new ilException('The entered id: ' . $userId . ' is not an user object');
119 }
120
122
123 $placeholder['USER_LOGIN'] = $this->utilHelper->prepareFormOutput((trim($user->getLogin())));
124 $placeholder['USER_FULLNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFullname())));
125 $placeholder['USER_FIRSTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFirstname())));
126 $placeholder['USER_LASTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getLastname())));
127 $placeholder['USER_TITLE'] = $this->utilHelper->prepareFormOutput((trim($user->getUTitle())));
128
129 $salutation = '';
130 $gender = $user->getGender();
131 if (trim($gender) !== '' && strtolower($gender) !== 'n') {
132 $salutation = $this->utilHelper->prepareFormOutput($this->language->txt("salutation_" . trim($gender)));
133 }
134
135 $placeholder['USER_SALUTATION'] = $salutation;
136
137 $birthday = '';
138 $dateObject = $user->getBirthday();
139 if (null !== $dateObject) {
140 $birthday = $this->dateHelper->formatDate($dateObject, $this->birthdayDateFormat);
141 }
142
143 $placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
144 $placeholder['USER_INSTITUTION'] = $this->utilHelper->prepareFormOutput((trim($user->getInstitution())));
145 $placeholder['USER_DEPARTMENT'] = $this->utilHelper->prepareFormOutput((trim($user->getDepartment())));
146 $placeholder['USER_STREET'] = $this->utilHelper->prepareFormOutput((trim($user->getStreet())));
147 $placeholder['USER_CITY'] = $this->utilHelper->prepareFormOutput((trim($user->getCity())));
148 $placeholder['USER_ZIPCODE'] = $this->utilHelper->prepareFormOutput((trim($user->getZipcode())));
149 $placeholder['USER_COUNTRY'] = $this->utilHelper->prepareFormOutput((trim($user->getCountry())));
150 $placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
151 $placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
152 time(),
153 $this->dateFormat
154 ))));
155 $placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
156 time(),
157 $this->dateFormat
158 ))));
159
160 return array_merge(
162 $this->userDefinedFieldsPlaceholderValues->getPlaceholderValues($userId, $objId)
163 );
164 }
165
178 public function getPlaceholderValuesForPreview(int $userId, int $objId): array
179 {
180 $previewPlacholderValues = [
181 "USER_LOGIN" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_login")),
182 "USER_FULLNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_fullname")),
183 "USER_FIRSTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_firstname")),
184 "USER_LASTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_lastname")),
185 "USER_TITLE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_title")),
186 "USER_SALUTATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_salutation")),
187 "USER_BIRTHDAY" => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
188 time(),
189 $this->dateFormat
190 )))),
191 "USER_INSTITUTION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_institution")),
192 "USER_DEPARTMENT" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_department")),
193 "USER_STREET" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_street")),
194 "USER_CITY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_city")),
195 "USER_ZIPCODE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_zipcode")),
196 "USER_COUNTRY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_country")),
197 "USER_MATRICULATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_matriculation")),
198 'DATE' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
199 time(),
200 $this->dateFormat
201 )))),
202 'DATETIME' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
203 time(),
204 $this->dateFormat
205 )))),
206 'DATE_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
207 time(),
208 $this->dateFormat
209 )))),
210 'DATETIME_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
211 time(),
212 $this->dateFormat
213 ))))
214 ];
215
216 return array_merge(
217 $previewPlacholderValues,
218 $this->userDefinedFieldsPlaceholderValues->getPlaceholderValuesForPreview($userId, $objId)
219 );
220 }
221}
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.
__construct(?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateDateHelper $dateHelper=null, ?int $dateFormat=null, ?ilLanguage $language=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues=null, int $birthdayDateFormat=IL_CAL_DATE)
ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
loadLanguageModule(string $a_module)
Load language module.
User class.
global $DIC
Definition: feed.php:28
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
$objId
Definition: xapitoken.php:57