ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDefaultPlaceholderValues.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
13 private $placeholder;
14
19
23 private $dateHelper;
24
28 private $dateFormat;
29
33 private $language;
34
38 private $utilHelper;
39
44
49
59 public function __construct(
62 int $dateFormat = null,
63 ilLanguage $language = null,
67 ) {
68 if (null === $objectHelper) {
70 }
71 $this->objectHelper = $objectHelper;
72
73 if (null === $dateHelper) {
75 }
76 $this->dateHelper = $dateHelper;
77
78 if (null === $dateFormat) {
80 }
81 $this->dateFormat = $dateFormat;
82
83 if (null === $language) {
84 global $DIC;
85 $language = $DIC->language();
86 $language->loadLanguageModule('certificate');
87 }
88 $this->language = $language;
89
90 if (null === $utilHelper) {
92 }
93 $this->utilHelper = $utilHelper;
94
97 }
98 $this->userDefinedFieldsPlaceholderValues = $userDefinedFieldsPlaceholderValues;
99
100 $this->birthdayDateFormat = $birthdayDateFormat;
101
102 $this->placeholder = array(
103 'USER_LOGIN' => '',
104 'USER_FULLNAME' => '',
105 'USER_FIRSTNAME' => '',
106 'USER_LASTNAME' => '',
107 'USER_TITLE' => '',
108 'USER_SALUTATION' => '',
109 'USER_BIRTHDAY' => '',
110 'USER_INSTITUTION' => '',
111 'USER_DEPARTMENT' => '',
112 'USER_STREET' => '',
113 'USER_CITY' => '',
114 'USER_ZIPCODE' => '',
115 'USER_COUNTRY' => '',
116 'USER_MATRICULATION' => '',
117 'DATE' => '',
118 'DATETIME' => '',
119 'DATE_COMPLETED' => '',
120 'DATETIME_COMPLETED' => '',
121 );
122 }
123
130 public function getPlaceholderValues(int $userId, int $objId) : array
131 {
133 $user = $this->objectHelper->getInstanceByObjId($userId);
134 if (!$user instanceof ilObjUser) {
135 throw new ilException('The entered id: ' . $userId . ' is not an user object');
136 }
137
139
140 $placeholder['USER_LOGIN'] = $this->utilHelper->prepareFormOutput((trim($user->getLogin())));
141 $placeholder['USER_FULLNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFullname())));
142 $placeholder['USER_FIRSTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFirstname())));
143 $placeholder['USER_LASTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getLastname())));
144 $placeholder['USER_TITLE'] = $this->utilHelper->prepareFormOutput((trim($user->getUTitle())));
145
146 $salutation = '';
147 $gender = $user->getGender();
148 if (is_string($gender) && strlen(trim($gender)) > 0 && strtolower($gender) !== 'n') {
149 $salutation = $this->utilHelper->prepareFormOutput($this->language->txt("salutation_" . trim($gender)));
150 }
151
152 $placeholder['USER_SALUTATION'] = $salutation;
153
154 $birthday = '';
155 $dateObject = $user->getBirthday();
156 if (null !== $dateObject) {
157 $birthday = $this->dateHelper->formatDate($dateObject, $this->birthdayDateFormat);
158 }
159
160 $placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
161 $placeholder['USER_INSTITUTION'] = $this->utilHelper->prepareFormOutput((trim($user->getInstitution())));
162 $placeholder['USER_DEPARTMENT'] = $this->utilHelper->prepareFormOutput((trim($user->getDepartment())));
163 $placeholder['USER_STREET'] = $this->utilHelper->prepareFormOutput((trim($user->getStreet())));
164 $placeholder['USER_CITY'] = $this->utilHelper->prepareFormOutput((trim($user->getCity())));
165 $placeholder['USER_ZIPCODE'] = $this->utilHelper->prepareFormOutput((trim($user->getZipcode())));
166 $placeholder['USER_COUNTRY'] = $this->utilHelper->prepareFormOutput((trim($user->getCountry())));
167 $placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
168 $placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(time(), $this->dateFormat))));
169 $placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDatetime(time(), $this->dateFormat))));
170
171 $placeholder = array_merge($placeholder, $this->userDefinedFieldsPlaceholderValues->getPlaceholderValues($userId, $objId));
172
173 return $placeholder;
174 }
175
189 public function getPlaceholderValuesForPreview(int $userId, int $objId) : array
190 {
191 $previewPlacholderValues = array(
192 "USER_LOGIN" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_login")),
193 "USER_FULLNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_fullname")),
194 "USER_FIRSTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_firstname")),
195 "USER_LASTNAME" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_lastname")),
196 "USER_TITLE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_title")),
197 "USER_SALUTATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_salutation")),
198 "USER_BIRTHDAY" => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(time(), $this->dateFormat)))),
199 "USER_INSTITUTION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_institution")),
200 "USER_DEPARTMENT" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_department")),
201 "USER_STREET" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_street")),
202 "USER_CITY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_city")),
203 "USER_ZIPCODE" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_zipcode")),
204 "USER_COUNTRY" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_country")),
205 "USER_MATRICULATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_matriculation")),
206 'DATE' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(time(), $this->dateFormat)))),
207 'DATETIME' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDatetime(time(), $this->dateFormat)))),
208 'DATE_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(time(), $this->dateFormat)))),
209 'DATETIME_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDatetime(time(), $this->dateFormat))))
210 );
211
212 return array_merge($previewPlacholderValues, $this->userDefinedFieldsPlaceholderValues->getPlaceholderValuesForPreview($userId, $objId));
213 }
214}
An exception for terminatinating execution or to throw for unit testing.
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, $birthdayDateFormat=IL_CAL_DATE)
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
global $DIC
Definition: goto.php:24
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()
Definition: language.php:2
$objId
Definition: xapitoken.php:39