ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDefaultPlaceholderValues.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 {
29  private readonly array $placeholder;
32  private readonly int $dateFormat;
33  private readonly int $birthdayDateFormat;
34  private readonly ilLanguage $language;
37  private readonly Factory $uuid_factory;
39 
40 
41  public function __construct(
42  ?ilCertificateObjectHelper $objectHelper = null,
43  ?ilCertificateDateHelper $dateHelper = null,
44  ?int $dateFormat = null,
45  ?ilLanguage $language = null,
46  ?ilCertificateUtilHelper $utilHelper = null,
47  ?ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues = null,
48  ?ILIAS\Data\UUID\Factory $uuid_factory = null,
49  ?int $birthdayDateFormat = null
50  ) {
51  $this->objectHelper = $objectHelper ?? new ilCertificateObjectHelper();
52  $this->dateHelper = $dateHelper ?? new ilCertificateDateHelper();
53 
54  require_once __DIR__ . '/../../../../Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
55 
56  $this->dateFormat = $dateFormat ?? IL_CAL_UNIX;
57  $this->birthdayDateFormat = $birthdayDateFormat ?? IL_CAL_DATE;
58 
59  if (null === $language) {
60  global $DIC;
61  $language = $DIC->language();
62  $language->loadLanguageModule('certificate');
63  }
64  $this->language = $language;
65 
66  $this->utilHelper = $utilHelper ?? new ilCertificateUtilHelper();
67  $this->userDefinedFieldsPlaceholderValues =
68  $userDefinedFieldsPlaceholderValues ?? new ilUserDefinedFieldsPlaceholderValues();
69  $this->uuid_factory = $uuid_factory ?? new ILIAS\Data\UUID\Factory();
70 
71  $this->placeholder = [
72  'CERTIFICATE_ID' => '',
73  'USER_LOGIN' => '',
74  'USER_FULLNAME' => '',
75  'USER_FIRSTNAME' => '',
76  'USER_LASTNAME' => '',
77  'USER_TITLE' => '',
78  'USER_SALUTATION' => '',
79  'USER_BIRTHDAY' => '',
80  'USER_INSTITUTION' => '',
81  'USER_DEPARTMENT' => '',
82  'USER_STREET' => '',
83  'USER_CITY' => '',
84  'USER_ZIPCODE' => '',
85  'USER_COUNTRY' => '',
86  'USER_MATRICULATION' => '',
87  'DATE' => '',
88  'DATETIME' => '',
89  'DATE_COMPLETED' => '',
90  'DATETIME_COMPLETED' => '',
91  ];
92  }
93 
101  public function getPlaceholderValues(int $userId, int $objId): array
102  {
104  $user = $this->objectHelper->getInstanceByObjId($userId);
105  if (!$user instanceof ilObjUser) {
106  throw new ilException('The entered id: ' . $userId . ' is not an user object');
107  }
108  $user_lng = $this->getUserLanguage($user);
109  $placeholder = $this->placeholder;
110 
111  $placeholder['USER_LOGIN'] = $this->utilHelper->prepareFormOutput((trim($user->getLogin())));
112  $placeholder['USER_FULLNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFullname())));
113  $placeholder['USER_FIRSTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFirstname())));
114  $placeholder['USER_LASTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getLastname())));
115  $placeholder['USER_TITLE'] = $this->utilHelper->prepareFormOutput((trim($user->getUTitle())));
116 
117  $salutation = '';
118  $gender = $user->getGender();
119  if (trim($gender) !== '' && strtolower($gender) !== 'n') {
120  $salutation = $this->utilHelper->prepareFormOutput($user_lng->txt("salutation_" . trim($gender)));
121  }
122 
123  $placeholder['USER_SALUTATION'] = $salutation;
124 
125  $birthday = '';
126  $dateObject = $user->getBirthday();
127  if (null !== $dateObject) {
128  $birthday = $this->dateHelper->formatDate($dateObject, $user, $this->birthdayDateFormat);
129  }
130 
131  $placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
132  $placeholder['USER_INSTITUTION'] = $this->utilHelper->prepareFormOutput((trim($user->getInstitution())));
133  $placeholder['USER_DEPARTMENT'] = $this->utilHelper->prepareFormOutput((trim($user->getDepartment())));
134  $placeholder['USER_STREET'] = $this->utilHelper->prepareFormOutput((trim($user->getStreet())));
135  $placeholder['USER_CITY'] = $this->utilHelper->prepareFormOutput((trim($user->getCity())));
136  $placeholder['USER_ZIPCODE'] = $this->utilHelper->prepareFormOutput((trim($user->getZipcode())));
137  $placeholder['USER_COUNTRY'] = $this->utilHelper->prepareFormOutput((trim($user->getCountry())));
138  $placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
139  $placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
140  time(),
141  $user,
142  $this->dateFormat
143  ))));
144  $placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
145  time(),
146  $user,
147  $this->dateFormat
148  ))));
149 
150  return array_merge(
151  $placeholder,
152  $this->userDefinedFieldsPlaceholderValues->getPlaceholderValues($userId, $objId)
153  );
154  }
155 
165  public function getPlaceholderValuesForPreview(int $userId, int $objId): array
166  {
167  $previewPlacholderValues = [
168  'CERTIFICATE_ID' => $this->utilHelper->prepareFormOutput($this->uuid_factory->uuid4AsString()),
169  "USER_LOGIN" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_login")),
170  "USER_FULLNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_fullname")),
171  "USER_FIRSTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_firstname")),
172  "USER_LASTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_lastname")),
173  "USER_TITLE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_title")),
174  "USER_SALUTATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_salutation")),
175  "USER_BIRTHDAY" => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
176  time(),
177  null,
178  $this->dateFormat
179  )))),
180  "USER_INSTITUTION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_institution")),
181  "USER_DEPARTMENT" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_department")),
182  "USER_STREET" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_street")),
183  "USER_CITY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_city")),
184  "USER_ZIPCODE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_zipcode")),
185  "USER_COUNTRY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_country")),
186  "USER_MATRICULATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_matriculation")),
187  'DATE' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
188  time(),
189  null,
190  $this->dateFormat
191  )))),
192  'DATETIME' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
193  time(),
194  null,
195  $this->dateFormat
196  )))),
197  'DATE_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
198  time(),
199  null,
200  $this->dateFormat
201  )))),
202  'DATETIME_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
203  time(),
204  null,
205  $this->dateFormat
206  ))))
207  ];
208 
209  return array_merge(
210  $previewPlacholderValues,
211  $this->userDefinedFieldsPlaceholderValues->getPlaceholderValuesForPreview($userId, $objId)
212  );
213  }
214 
215  private function getUserLanguage(ilObjUser $user): ilLanguage
216  {
217  if ($this->user_language instanceof ilLanguage) {
218  return $this->user_language;
219  }
220  $language = new ilLanguage($user->getLanguage());
221  $language->loadLanguageModule('certificate');
222  $this->user_language = $language;
223  return $language;
224  }
225 
229  public function setUserLanguage(ilLanguage $language): void
230  {
231  $this->user_language = $language;
232  }
233 }
Interface Observer Contains several chained tasks and infos about them.
readonly ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues
$objId
Definition: xapitoken.php:57
loadLanguageModule(string $a_module)
Load language module.
const IL_CAL_UNIX
readonly ilCertificateUtilHelper $utilHelper
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
__construct(?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateDateHelper $dateHelper=null, ?int $dateFormat=null, ?ilLanguage $language=null, ?ilCertificateUtilHelper $utilHelper=null, ?ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues=null, ?ILIAS\Data\UUID\Factory $uuid_factory=null, ?int $birthdayDateFormat=null)
const IL_CAL_DATE
readonly ilCertificateDateHelper $dateHelper
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.
Definition: language.php:41
readonly ilCertificateObjectHelper $objectHelper