ILIAS  release_8 Revision v8.24
class.ilStudyProgrammeMailTemplateContext.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24{
25 public const ID = 'prg_context_manual';
26
27 private const TITLE = "prg_title";
28 private const DESCRIPTION = "prg_description";
29 private const TYPE = "prg_type";
30 private const LINK = "prg_link";
31 private const ORG_UNIT = "prg_orgus";
32 private const STATUS = "prg_status";
33 private const COMPLETION_DATE = "prg_completion_date";
34 private const COMPLETED_BY = "prg_completion_by";
35 private const POINTS_REQUIRED = "prg_points_required";
36 private const POINTS_CURRENT = "prg_points_current";
37 private const DEADLINE = "prg_deadline";
38 private const EXPIRE_DATE = "prg_expiry_date";
39 private const VALIDITY = "prg_validity";
40
41 private const DATE_FORMAT = 'd.m.Y';
42
43 protected ilLanguage $lng;
44
45 public function __construct(
48 ilMailUserHelper $usernameHelper = null,
50 ) {
54 $usernameHelper,
56 );
57
58 global $DIC;
59
60 $this->lng = $DIC['lng'];
61 $this->lng->loadLanguageModule('prg');
62 }
63
64 public function getId(): string
65 {
66 return self::ID;
67 }
68
69 public function getTitle(): string
70 {
71 return $this->lng->txt('prg_mail_context_title');
72 }
73
74 public function getDescription(): string
75 {
76 return $this->lng->txt('prg_mail_context_info');
77 }
78
82 public function getSpecificPlaceholders(): array
83 {
84 $placeholders = [];
85
86 $placeholders[self::TITLE] = [
87 'placeholder' => 'STUDY_PROGRAMME_TITLE',
88 'label' => $this->lng->txt(self::TITLE)
89 ];
90
91 $placeholders[self::DESCRIPTION] = [
92 'placeholder' => 'STUDY_PROGRAMME_DESCRIPTION',
93 'label' => $this->lng->txt(self::DESCRIPTION)
94 ];
95
96 $placeholders[self::TYPE] = [
97 'placeholder' => 'STUDY_PROGRAMME_TYPE',
98 'label' => $this->lng->txt(self::TYPE)
99 ];
100
101 $placeholders[self::LINK] = [
102 'placeholder' => 'STUDY_PROGRAMME_LINK',
103 'label' => $this->lng->txt(self::LINK)
104 ];
105
106 $placeholders[self::ORG_UNIT] = [
107 'placeholder' => 'STUDY_PROGRAMME_ORG_UNITS',
108 'label' => $this->lng->txt(self::ORG_UNIT)
109 ];
110
111 $placeholders[self::STATUS] = [
112 'placeholder' => 'STUDY_PROGRAMME_STATUS',
113 'label' => $this->lng->txt(self::STATUS)
114 ];
115
116 $placeholders[self::COMPLETION_DATE] = [
117 'placeholder' => 'STUDY_PROGRAMME_COMPLETION_DATE',
118 'label' => $this->lng->txt(self::COMPLETION_DATE)
119 ];
120
121 $placeholders[self::COMPLETED_BY] = [
122 'placeholder' => 'STUDY_PROGRAMME_COMPLETED_BY',
123 'label' => $this->lng->txt(self::COMPLETED_BY)
124 ];
125
126 $placeholders[self::POINTS_REQUIRED] = [
127 'placeholder' => 'STUDY_PROGRAMME_POINTS_REQUIRED',
128 'label' => $this->lng->txt(self::POINTS_REQUIRED)
129 ];
130
131 $placeholders[self::POINTS_CURRENT] = [
132 'placeholder' => 'STUDY_PROGRAMME_POINTS_CURRENT',
133 'label' => $this->lng->txt(self::POINTS_CURRENT)
134 ];
135
136 $placeholders[self::DEADLINE] = [
137 'placeholder' => 'STUDY_PROGRAMME_DEADLINE',
138 'label' => $this->lng->txt(self::DEADLINE)
139 ];
140
141 $placeholders[self::EXPIRE_DATE] = [
142 'placeholder' => 'STUDY_PROGRAMME_EXPIRE_DATE',
143 'label' => $this->lng->txt(self::EXPIRE_DATE)
144 ];
145
146 $placeholders[self::VALIDITY] = [
147 'placeholder' => 'STUDY_PROGRAMME_VALIDITY',
148 'label' => $this->lng->txt(self::VALIDITY)
149 ];
150
151 return $placeholders;
152 }
153
157 public function resolveSpecificPlaceholder(
158 string $placeholder_id,
159 array $context_parameters,
160 ilObjUser $recipient = null,
161 bool $html_markup = false
162 ): string {
163 if (is_null($recipient)) {
164 return '';
165 }
166
167 if (!in_array($placeholder_id, [
168 self::TITLE,
169 self::DESCRIPTION,
170 self::TYPE,
171 self::LINK,
172 self::ORG_UNIT,
173 self::STATUS,
174 self::COMPLETION_DATE,
175 self::COMPLETED_BY,
176 self::POINTS_REQUIRED,
177 self::POINTS_CURRENT,
178 self::DEADLINE,
179 self::EXPIRE_DATE,
180 self::VALIDITY
181 ])) {
182 return '';
183 }
184
186 $prg = ilObjectFactory::getInstanceByRefId((int)$context_parameters['ref_id']);
187 $assignments = $prg->getAssignmentsOfSingleProgramForUser($recipient->getId());
188 $latest = $this->getLatestAssignment($assignments);
189 $latest_successful = $this->getLatestSuccessfulAssignment($assignments);
190
191 switch ($placeholder_id) {
192 case self::TITLE:
193 $string = $prg->getTitle();
194 break;
196 $string = $prg->getDescription();
197 break;
198 case self::TYPE:
199 $string = '';
200 if (!is_null($prg->getSubType())) {
201 $string = $prg->getSubType()->getTitle();
202 }
203 break;
204 case self::LINK:
205 $string = ilLink::_getLink((int)$context_parameters['ref_id'], 'prg') . ' ';
206 break;
207 case self::ORG_UNIT:
208 $string = ilObjUser::lookupOrgUnitsRepresentation($recipient->getId());
209 break;
210 case self::STATUS:
211 $string = $this->statusToRepr($latest->getProgressTree()->getStatus(), $recipient->getLanguage());
212 break;
214 $string = $this->date2String($latest->getProgressTree()->getCompletionDate(), $recipient);
215 break;
217 $string = '';
218 $id = $latest->getProgressTree()->getCompletionBy();
219 if (!is_null($id) && ilObject::_exists($id)) {
221 if ($obj->getType() === 'usr') {
222 $string = ilObjUser::_lookupLogin($id);
224 if (
225 ilObject::_exists($ref_id, true) &&
227 ) {
229 }
230 }
231 }
232 break;
234 $string = (string) $latest->getProgressTree()->getAmountOfPoints();
235 break;
237 $string = (string) $latest->getProgressTree()->getCurrentAmountOfPoints();
238 break;
239 case self::DEADLINE:
240 $string = $latest->getProgressTree()->isInProgress() ?
241 $this->date2String($latest->getProgressTree()->getDeadline(), $recipient) : '';
242
243 break;
244 case self::VALIDITY:
245 $string = '-';
246 if ($latest_successful) {
247 $langvar = $latest_successful->getProgressTree()->isInvalidated() ? 'prg_not_valid' : 'prg_still_valid';
248 $string = $this->lng->txtlng('prg', $langvar, $recipient->getLanguage());
249 }
250 break;
251
253 $string = '-';
254 if ($latest_successful) {
255 $string = $this->date2String($latest_successful->getProgressTree()->getValidityOfQualification(), $recipient);
256 }
257 break;
258 default:
259 throw new \Exception("cannot resolve placeholder: " . $placeholder_id);
260 $string = '';
261 }
262
263 return $string;
264 }
265
266 protected function getLatestAssignment(array $assignments): ilPRGAssignment
267 {
268 usort($assignments, static function (ilPRGAssignment $a, ilPRGAssignment $b): int {
269 $a_dat =$a->getProgressTree()->getAssignmentDate();
270 $b_dat =$b->getProgressTree()->getAssignmentDate();
271 if ($a_dat > $b_dat) {
272 return -1;
273 } elseif ($a_dat < $b_dat) {
274 return 1;
275 } else {
276 return 0;
277 }
278 });
279 return array_shift($assignments);
280 }
281
282 protected function getLatestSuccessfulAssignment(array $assignments): ?ilPRGAssignment
283 {
284 $successful = array_filter(
285 $assignments,
286 fn ($ass) => $ass->getProgressTree()->isSuccessful()
287 );
288 if (count($successful) === 0) {
289 return null;
290 }
291
292 usort($successful, static function (ilPRGAssignment $a, ilPRGAssignment $b): int {
293 $a_dat =$a->getProgressTree()->getCompletionDate();
294 $b_dat =$b->getProgressTree()->getCompletionDate();
295 if ($a_dat > $b_dat) {
296 return -1;
297 } elseif ($a_dat < $b_dat) {
298 return 1;
299 } else {
300 return 0;
301 }
302 });
303 return array_shift($successful);
304 }
305
306
307
308 protected function statusToRepr(int $status, string $lang): string
309 {
310 if ($status === ilPRGProgress::STATUS_IN_PROGRESS) {
311 return $this->lng->txtlng('prg', 'prg_status_in_progress', $lang);
312 }
313 if ($status === ilPRGProgress::STATUS_COMPLETED) {
314 return $this->lng->txtlng('prg', 'prg_status_completed', $lang);
315 }
316 if ($status === ilPRGProgress::STATUS_ACCREDITED) {
317 return $this->lng->txtlng('prg', 'prg_status_accredited', $lang);
318 }
319 if ($status === ilPRGProgress::STATUS_NOT_RELEVANT) {
320 return $this->lng->txtlng('prg', 'prg_status_not_relevant', $lang);
321 }
322 if ($status === ilPRGProgress::STATUS_FAILED) {
323 return $this->lng->txtlng('prg', 'prg_status_failed', $lang);
324 }
325
326 throw new ilException("Unknown status: '$status'");
327 }
328
329 protected function date2String(
330 DateTimeImmutable $date_time = null,
331 ilObjUser $user = null
332 ): string {
333 if (is_null($date_time)) {
334 return '';
335 }
336 if (is_null($user)) {
337 return $date_time->format(self::DATE_FORMAT);
338 }
339 return $user->getDateFormat()->applyTo($date_time);
340 }
341}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupTitle(int $obj_id)
static _lookupTargetRefId(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
Class ilMailEnvironmentHelper.
Class ilMailLanguageHelper.
Class ilMailTemplateContext.
ilMailLanguageHelper $languageHelper
OrgUnitUserService $orgUnitUserService
ilMailEnvironmentHelper $envHelper
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
Class ilMailUserHelper.
User class.
static _lookupLogin(int $a_user_id)
static lookupOrgUnitsRepresentation(int $a_usr_id)
lookup org unit representation
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupDeletedDate(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
__construct(OrgUnitUserService $orgUnitUserService=null, ilMailEnvironmentHelper $envHelper=null, ilMailUserHelper $usernameHelper=null, ilMailLanguageHelper $languageHelper=null)
date2String(DateTimeImmutable $date_time=null, ilObjUser $user=null)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$lang
Definition: xapiexit.php:26