ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
18  private $objectHelper;
19 
23  private $dateHelper;
24 
28  private $dateFormat;
29 
33  private $language;
34 
38  private $utilHelper;
39 
44 
49 
58  public function __construct(
61  int $dateFormat = null,
62  ilLanguage $language = null,
66  ) {
67  if (null === $objectHelper) {
69  }
70  $this->objectHelper = $objectHelper;
71 
72  if (null === $dateHelper) {
74  }
75  $this->dateHelper = $dateHelper;
76 
77  if (null === $dateFormat) {
79  }
80  $this->dateFormat = $dateFormat;
81 
82  if (null === $language) {
83  global $DIC;
84  $language = $DIC->language();
85  }
86  $this->language = $language;
87 
88  if (null === $utilHelper) {
90  }
91  $this->utilHelper = $utilHelper;
92 
95  }
96  $this->userDefinedFieldsPlaceholderValues = $userDefinedFieldsPlaceholderValues;
97 
98  $this->birthdayDateFormat = $birthdayDateFormat;
99 
100  $this->placeholder = array(
101  'USER_LOGIN' => '',
102  'USER_FULLNAME' => '',
103  'USER_FIRSTNAME' => '',
104  'USER_LASTNAME' => '',
105  'USER_TITLE' => '',
106  'USER_SALUTATION' => '',
107  'USER_BIRTHDAY' => '',
108  'USER_INSTITUTION' => '',
109  'USER_DEPARTMENT' => '',
110  'USER_STREET' => '',
111  'USER_CITY' => '',
112  'USER_ZIPCODE' => '',
113  'USER_COUNTRY' => '',
114  'USER_MATRICULATION' => '',
115  'DATE' => '',
116  'DATETIME' => '',
117  'DATE_COMPLETED' => '',
118  'DATETIME_COMPLETED' => '',
119  );
120  }
121 
128  public function getPlaceholderValues(int $userId, int $objId) : array
129  {
131  $user = $this->objectHelper->getInstanceByObjId($userId);
132  if (!$user instanceof ilObjUser) {
133  throw new ilException('The entered id: ' . $userId . ' is not an user object');
134  }
135 
137 
138  $placeholder['USER_LOGIN'] = $this->utilHelper->prepareFormOutput((trim($user->getLogin())));
139  $placeholder['USER_FULLNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFullname())));
140  $placeholder['USER_FIRSTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getFirstname())));
141  $placeholder['USER_LASTNAME'] = $this->utilHelper->prepareFormOutput((trim($user->getLastname())));
142  $placeholder['USER_TITLE'] = $this->utilHelper->prepareFormOutput((trim($user->getUTitle())));
143 
144  $salutation = '';
145  $gender = $user->getGender();
146  if (is_string($gender) && strlen(trim($gender)) > 0 && strtolower($gender) !== 'n') {
147  $salutation = $this->utilHelper->prepareFormOutput($this->language->txt("salutation_" . trim($gender)));
148  }
149 
150  $placeholder['USER_SALUTATION'] = $salutation;
151 
152  $birthday = '';
153  $dateObject = $user->getBirthday();
154  if (null !== $dateObject) {
155  $birthday = $this->dateHelper->formatDate($dateObject, $this->birthdayDateFormat);
156  }
157 
158  $placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
159  $placeholder['USER_INSTITUTION'] = $this->utilHelper->prepareFormOutput((trim($user->getInstitution())));
160  $placeholder['USER_DEPARTMENT'] = $this->utilHelper->prepareFormOutput((trim($user->getDepartment())));
161  $placeholder['USER_STREET'] = $this->utilHelper->prepareFormOutput((trim($user->getStreet())));
162  $placeholder['USER_CITY'] = $this->utilHelper->prepareFormOutput((trim($user->getCity())));
163  $placeholder['USER_ZIPCODE'] = $this->utilHelper->prepareFormOutput((trim($user->getZipcode())));
164  $placeholder['USER_COUNTRY'] = $this->utilHelper->prepareFormOutput((trim($user->getCountry())));
165  $placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
166  $placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(time(), $this->dateFormat))));
167  $placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDatetime(time(), $this->dateFormat))));
168 
169  $placeholder = array_merge($placeholder, $this->userDefinedFieldsPlaceholderValues->getPlaceholderValues($userId, $objId));
170 
171  return $placeholder;
172  }
173 
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 }
Collection of basic placeholder values that can be used.
global $DIC
Definition: saml.php:7
const IL_CAL_UNIX
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
$user
Definition: migrateto20.php:57
Just a wrapper class to create Unit Test for other classes.
const IL_CAL_DATE
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 handling
__construct(ilCertificateObjectHelper $objectHelper=null, ilCertificateDateHelper $dateHelper=null, int $dateFormat=null, ilLanguage $language=null, ilCertificateUtilHelper $utilHelper=null, ilUserDefinedFieldsPlaceholderValues $userDefinedFieldsPlaceholderValues=null, $birthdayDateFormat=IL_CAL_DATE)