ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCoursePlaceholderValues.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
33 
34  public function __construct(
35  ?ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValues = null,
36  ?ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
37  ?ilLanguage $language = null,
38  ?ilCertificateObjectHelper $objectHelper = null,
39  ?ilCertificateParticipantsHelper $participantsHelper = null,
40  ?ilCertificateUtilHelper $ilUtilHelper = null,
41  ?ilCertificateDateHelper $dateHelper = null,
42  ?ilCertificateLPStatusHelper $lpStatusHelper = null
43  ) {
44  if (null === $language) {
45  global $DIC;
46  $language = $DIC->language();
47  $language->loadLanguageModule('certificate');
48  }
49 
50  if (null === $defaultPlaceholderValues) {
51  $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
52  }
53 
54  if (null === $customUserFieldsPlaceholderValues) {
55  $customUserFieldsPlaceholderValues = new ilObjectCustomUserFieldsPlaceholderValues();
56  }
57 
58  if (null === $objectHelper) {
59  $objectHelper = new ilCertificateObjectHelper();
60  }
61  $this->objectHelper = $objectHelper;
62 
63  if (null === $participantsHelper) {
64  $participantsHelper = new ilCertificateParticipantsHelper();
65  }
66  $this->participantsHelper = $participantsHelper;
67 
68  if (null === $ilUtilHelper) {
69  $ilUtilHelper = new ilCertificateUtilHelper();
70  }
71  $this->ilUtilHelper = $ilUtilHelper;
72 
73  if (null === $dateHelper) {
74  $dateHelper = new ilCertificateDateHelper();
75  }
76  $this->dateHelper = $dateHelper;
77 
78  if (null === $lpStatusHelper) {
79  $lpStatusHelper = new ilCertificateLPStatusHelper();
80  }
81  $this->lpStatusHelper = $lpStatusHelper;
82 
83  $this->customUserFieldsPlaceholderValuesObject = $customUserFieldsPlaceholderValues;
84  $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
85  }
86 
90  private function hasCompletionDate($possibleDate): bool
91  {
92  return (
93  $possibleDate !== false &&
94  $possibleDate !== null &&
95  $possibleDate !== ''
96  );
97  }
98 
111  public function getPlaceholderValues(int $userId, int $objId): array
112  {
113  $courseObject = $this->objectHelper->getInstanceByObjId($objId);
114 
115  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
116 
117  $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValues(
118  $userId,
119  $objId
120  );
121 
122  $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
123 
124  $completionDate = $this->participantsHelper->getDateTimeOfPassed($objId, $userId);
125  if (!$this->hasCompletionDate($completionDate)) {
126  $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
127  }
128 
129  if ($this->hasCompletionDate($completionDate)) {
130  $placeholders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate);
131  $placeholders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate);
132  }
133 
134  $lng_code = ilObjUser::_lookupLanguage($userId);
135  $course_translation = $courseObject->getObjectTranslation();
136  $title = $courseObject->getTitle();
137  if ($course_translation instanceof ilObjectTranslation) {
138  $languages = $course_translation->getLanguages();
139  foreach ($languages as $trans) {
140  if ($trans->getLanguageCode() === $lng_code) {
141  $title = $trans->getTitle();
142  break;
143  }
144  }
145  }
146 
147  $placeholders['COURSE_TITLE'] = ilLegacyFormElementsUtil::prepareFormOutput($title);
148 
149  return $placeholders;
150  }
151 
161  public function getPlaceholderValuesForPreview(int $userId, int $objId): array
162  {
163  $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
164 
165  $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValuesForPreview(
166  $userId,
167  $objId
168  );
169 
170  $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
171 
172  $object = $this->objectHelper->getInstanceByObjId($objId);
173 
174  $placeholders['COURSE_TITLE'] = ilLegacyFormElementsUtil::prepareFormOutput($object->getTitle());
175 
176  return $placeholders;
177  }
178 }
Collection of basic placeholder values that can be used.
static _lookupLanguage(int $a_usr_id)
readonly ilCertificateLPStatusHelper $lpStatusHelper
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
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the &#39;getPlaceholderValues&#39; method, this method is used to create a plac...
static prepareFormOutput($a_str, bool $a_strip=false)
global $DIC
Definition: feed.php:28
readonly ilCertificateUtilHelper $ilUtilHelper
readonly ilCertificateParticipantsHelper $participantsHelper
__construct(?ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValues=null, ?ilDefaultPlaceholderValues $defaultPlaceholderValues=null, ?ilLanguage $language=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateParticipantsHelper $participantsHelper=null, ?ilCertificateUtilHelper $ilUtilHelper=null, ?ilCertificateDateHelper $dateHelper=null, ?ilCertificateLPStatusHelper $lpStatusHelper=null)
Just a wrapper class to create Unit Test for other classes.
readonly ilCertificateDateHelper $dateHelper
readonly ilDefaultPlaceholderValues $defaultPlaceholderValuesObject
readonly ilCertificateObjectHelper $objectHelper
readonly ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValuesObject
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...