ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCoursePlaceholderValues.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
13
18
22 private $language;
23
28
33
38
42 private $dateHelper;
43
48
59 public function __construct(
60 ilObjectCustomUserFieldsPlaceholderValues $customUserFieldsPlaceholderValues = null,
61 ilDefaultPlaceholderValues $defaultPlaceholderValues = null,
62 ilLanguage $language = null,
68 ) {
69 if (null === $language) {
70 global $DIC;
71 $language = $DIC->language();
72 $language->loadLanguageModule('certificate');
73 }
74 $this->language = $language;
75
76 if (null === $defaultPlaceholderValues) {
77 $defaultPlaceholderValues = new ilDefaultPlaceholderValues();
78 }
79
80 if (null === $customUserFieldsPlaceholderValues) {
81 $customUserFieldsPlaceholderValues = new ilObjectCustomUserFieldsPlaceholderValues();
82 }
83
84 if (null === $objectHelper) {
86 }
87 $this->objectHelper = $objectHelper;
88
89 if (null === $participantsHelper) {
91 }
92 $this->participantsHelper = $participantsHelper;
93
94 if (null === $ilUtilHelper) {
96 }
97 $this->ilUtilHelper = $ilUtilHelper;
98
99 if (null === $dateHelper) {
101 }
102 $this->dateHelper = $dateHelper;
103
104 if (null === $lpStatusHelper) {
106 }
107 $this->lpStatusHelper = $lpStatusHelper;
108
109 $this->customUserFieldsPlaceholderValuesObject = $customUserFieldsPlaceholderValues;
110 $this->defaultPlaceholderValuesObject = $defaultPlaceholderValues;
111 }
112
117 private function hasCompletionDate($possibleDate) : bool
118 {
119 return (
120 $possibleDate !== false &&
121 $possibleDate !== null &&
122 $possibleDate !== ''
123 );
124 }
125
137 public function getPlaceholderValues(int $userId, int $objId) : array
138 {
139 $courseObject = $this->objectHelper->getInstanceByObjId($objId);
140
141 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
142
143 $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValues($userId, $objId);
144
145 $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
146
147 $completionDate = $this->participantsHelper->getDateTimeOfPassed($objId, $userId);
148 if (!$this->hasCompletionDate($completionDate)) {
149 $completionDate = $this->lpStatusHelper->lookupStatusChanged($objId, $userId);
150 }
151
152 if ($this->hasCompletionDate($completionDate)) {
153 $placeholders['DATE_COMPLETED'] = $this->dateHelper->formatDate($completionDate);
154 $placeholders['DATETIME_COMPLETED'] = $this->dateHelper->formatDateTime($completionDate);
155 }
156
157 $placeholders['COURSE_TITLE'] = $this->ilUtilHelper->prepareFormOutput($courseObject->getTitle());
158
159 return $placeholders;
160 }
161
170 public function getPlaceholderValuesForPreview(int $userId, int $objId) : array
171 {
172 $placeholders = $this->defaultPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
173
174 $customUserFieldsPlaceholders = $this->customUserFieldsPlaceholderValuesObject->getPlaceholderValuesForPreview($userId, $objId);
175
176 $placeholders = array_merge($placeholders, $customUserFieldsPlaceholders);
177
178 $object = $this->objectHelper->getInstanceByObjId($objId);
179
180 $placeholders['COURSE_TITLE'] = ilUtil::prepareFormOutput($object->getTitle());
181
182 return $placeholders;
183 }
184}
An exception for terminatinating execution or to throw for unit testing.
Just a wrapper class to create Unit Test for other classes.
getPlaceholderValuesForPreview(int $userId, int $objId)
This method is different then the 'getPlaceholderValues' method, this method is used to create a plac...
getPlaceholderValues(int $userId, int $objId)
This method MUST return an array that contains the actual data for the given user of the given object...
__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)
Collection of basic placeholder values that can be used.
language handling
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
$objId
Definition: xapitoken.php:39