ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeMailTemplateContext.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
8{
9 const ID = 'prg_context_manual';
10
11 const TITLE = "prg_title";
12 const DESCRIPTION = "prg_description";
13 const TYPE = "prg_type";
14 const LINK = "prg_link";
15 const ORG_UNIT = "prg_orgus";
16 const STATUS = "prg_status";
17 const COMPLETION_DATE = "prg_completion_date";
18 const COMPLETED_BY = "prg_completion_by";
19 const POINTS_REQUIRED = "prg_points_required";
20 const POINTS_CURRENT = "prg_points_current";
21 const DEADLINE = "prg_deadline";
22 const EXPIRE_DATE = "prg_expiry_date";
23 const VALIDITY = "prg_validity";
24
25 const DATE_FORMAT = 'd-m-Y H:i:s';
26
30 protected $lng;
31
32 public function __construct(
35 ilMailUserHelper $usernameHelper = null,
37 ) {
41 $usernameHelper,
43 );
44
45 global $DIC;
46
47 $this->lng = $DIC['lng'];
48 $this->lng->loadLanguageModule('prg');
49 }
50
54 public function getId() : string
55 {
56 return self::ID;
57 }
58
62 public function getTitle() : string
63 {
64 return $this->lng->txt('prg_mail_context_title');
65 }
66
70 public function getDescription() : string
71 {
72 return $this->lng->txt('prg_mail_context_info');
73 }
74
79 public function getSpecificPlaceholders() : array
80 {
81 $placeholders = array();
82
83 $placeholders[self::TITLE] = array(
84 'placeholder' => 'STUDY_PROGRAMME_TITLE',
85 'label' => $this->lng->txt(self::TITLE)
86 );
87
88 $placeholders[self::DESCRIPTION] = array(
89 'placeholder' => 'STUDY_PROGRAMME_DESCRIPTION',
90 'label' => $this->lng->txt(self::DESCRIPTION)
91 );
92
93 $placeholders[self::TYPE] = array(
94 'placeholder' => 'STUDY_PROGRAMME_TYPE',
95 'label' => $this->lng->txt(self::TYPE)
96 );
97
98 $placeholders[self::LINK] = array(
99 'placeholder' => 'STUDY_PROGRAMME_LINK',
100 'label' => $this->lng->txt(self::LINK)
101 );
102
103 $placeholders[self::ORG_UNIT] = array(
104 'placeholder' => 'STUDY_PROGRAMME_ORG_UNITS',
105 'label' => $this->lng->txt(self::ORG_UNIT)
106 );
107
108 $placeholders[self::STATUS] = array(
109 'placeholder' => 'STUDY_PROGRAMME_STATUS',
110 'label' => $this->lng->txt(self::STATUS)
111 );
112
113 $placeholders[self::COMPLETION_DATE] = array(
114 'placeholder' => 'STUDY_PROGRAMME_COMPLETION_DATE',
115 'label' => $this->lng->txt(self::COMPLETION_DATE)
116 );
117
118 $placeholders[self::COMPLETED_BY] = array(
119 'placeholder' => 'STUDY_PROGRAMME_COMPLETED_BY',
120 'label' => $this->lng->txt(self::COMPLETED_BY)
121 );
122
123 $placeholders[self::POINTS_REQUIRED] = array(
124 'placeholder' => 'STUDY_PROGRAMME_POINTS_REQUIRED',
125 'label' => $this->lng->txt(self::POINTS_REQUIRED)
126 );
127
128 $placeholders[self::POINTS_CURRENT] = array(
129 'placeholder' => 'STUDY_PROGRAMME_POINTS_CURRENT',
130 'label' => $this->lng->txt(self::POINTS_CURRENT)
131 );
132
133 $placeholders[self::DEADLINE] = array(
134 'placeholder' => 'STUDY_PROGRAMME_DEADLINE',
135 'label' => $this->lng->txt(self::DEADLINE)
136 );
137
138 $placeholders[self::EXPIRE_DATE] = array(
139 'placeholder' => 'STUDY_PROGRAMME_EXPIRE_DATE',
140 'label' => $this->lng->txt(self::EXPIRE_DATE)
141 );
142
143 $placeholders[self::VALIDITY] = array(
144 'placeholder' => 'STUDY_PROGRAMME_VALIDITY',
145 'label' => $this->lng->txt(self::VALIDITY)
146 );
147
148 return $placeholders;
149 }
150
154 public function resolveSpecificPlaceholder(
155 string $placeholder_id,
156 array $context_parameters,
157 ilObjUser $recipient = null,
158 bool $html_markup = false
159 ) : string {
160 if (is_null($recipient)) {
161 return '';
162 }
163
164 if (!in_array($placeholder_id, [
165 self::TITLE,
166 self::DESCRIPTION,
167 self::TYPE,
168 self::LINK,
169 self::ORG_UNIT,
170 self::STATUS,
171 self::COMPLETION_DATE,
172 self::COMPLETED_BY,
173 self::POINTS_REQUIRED,
174 self::POINTS_CURRENT,
175 self::DEADLINE,
176 self::EXPIRE_DATE,
177 self::VALIDITY
178 ])) {
179 return '';
180 }
181
182 $obj_id = ilObject::_lookupObjectId($context_parameters['ref_id']);
183
185 $obj = ilObjectFactory::getInstanceByRefId($context_parameters['ref_id']);
186
187 $progress = $this->getNewestProgressForUser($obj, $recipient->getId());
188
189 switch ($placeholder_id) {
190 case self::TITLE:
191 $string = ilObject::_lookupTitle($obj_id);
192 break;
194 $string = ilObject::_lookupDescription($obj_id);
195 break;
196 case self::TYPE:
197 $string = '';
198 if (!is_null($obj->getSubType())) {
199 $string = (string) $obj->getSubType()->getTitle();
200 }
201 break;
202 case self::LINK:
203 $string = ilLink::_getLink($context_parameters['ref_id'], 'prg');
204 break;
205 case self::ORG_UNIT:
206 $string = ilObjUser::lookupOrgUnitsRepresentation($recipient->getId());
207 break;
208 case self::STATUS:
209 $string = $this->statusToRepr($progress->getStatus(), $recipient->getLanguage());
210 break;
212 $string = $this->date2String($progress->getCompletionDate());
213 break;
215 $string = '';
216 $id = $progress->getCompletionBy();
217 if (!is_null($id) && ilObject::_exists($id)) {
219 if ($obj->getType() == 'usr') {
220 $string = (string) ilObjUser::_lookupLogin($id);
221 } else {
222 if ($ref_id = ilContainerReference::_lookupTargetRefId($id)) {
223 if (
224 ilObject::_exists($ref_id, true) &&
225 is_null(ilObject::_lookupDeletedDate($ref_id))
226 ) {
228 }
229 }
230 }
231 }
232 break;
234 $string = (string) $progress->getAmountOfPoints();
235 break;
237 $string = (string) $progress->getCurrentAmountOfPoints();
238 break;
239 case self::DEADLINE:
240 $string = $this->date2String($progress->getDeadline());
241 break;
242 case self::VALIDITY:
243 $now = new DateTimeImmutable();
244
245 $string = '-';
246 if (!is_null($progress->hasValidQualification($now))) {
247 $string = $this->lng->txtlng('prg', 'prg_not_valid', $recipient->getLanguage());
248 if ($progress->hasValidQualification($now)) {
249 $string = $this->lng->txtlng('prg', 'prg_still_valid', $recipient->getLanguage());
250 }
251 }
252 break;
254 $string = $this->date2String($progress->getValidityOfQualification());
255 break;
256 default:
257 $string = '';
258 }
259
260 return $string;
261 }
262
264 {
265 $progress = $obj->getProgressesOf($user_id);
266
267 $successfully_progress = array_filter($progress, function (ilStudyProgrammeProgress $a) {
268 return $a->isSuccessful() || $a->isSuccessfulExpired() || $a->isAccredited();
269 });
270
271 if (count($successfully_progress) == 0) {
272 return $progress[0];
273 }
274
275 usort($successfully_progress, function (ilStudyProgrammeProgress $a, ilStudyProgrammeProgress $b) {
276 if ($a->getCompletionDate() > $b->getCompletionDate()) {
277 return -1;
278 } elseif ($a->getCompletionDate() < $b->getCompletionDate()) {
279 return 1;
280 } else {
281 return 0;
282 }
283 });
284
285 return array_shift($successfully_progress);
286 }
287
288 protected function statusToRepr(int $status, string $lang) : string
289 {
291 return $this->lng->txtlng('prg', 'prg_status_in_progress', $lang);
292 }
294 return $this->lng->txtlng('prg', 'prg_status_completed', $lang);
295 }
297 return $this->lng->txtlng('prg', 'prg_status_accredited', $lang);
298 }
300 return $this->lng->txtlng('prg', 'prg_status_not_relevant', $lang);
301 }
303 return $this->lng->txtlng('prg', 'prg_status_failed', $lang);
304 }
305
306 throw new ilException("Unknown status: '$status'");
307 }
308
309 protected function date2String(DateTimeImmutable $date_time = null) : string
310 {
311 if (is_null($date_time)) {
312 return '';
313 }
314 return $date_time->format(self::DATE_FORMAT);
315 }
316}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTargetRefId($a_obj_id)
Lookup target ref_id.
static _lookupTitle($a_obj_id)
Overwitten from base class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMailEnvironmentHelper.
Class ilMailLanguageHelper.
Class ilMailTemplateContext.
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
Class ilMailUserHelper.
getProgressesOf(int $a_user_id)
Get the progresses the user has on this node.
static _lookupLogin($a_user_id)
lookup login
static lookupOrgUnitsRepresentation($a_usr_id)
lokup org unit representation
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static _lookupDescription($a_id)
lookup object description
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
__construct(OrgUnitUserService $orgUnitUserService=null, ilMailEnvironmentHelper $envHelper=null, ilMailUserHelper $usernameHelper=null, ilMailLanguageHelper $languageHelper=null)
ilMailTemplateContext constructor.
getNewestProgressForUser(ilObjStudyProgramme $obj, int $user_id)
Class ilStudyProgrammeProgress.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$lang
Definition: xapiexit.php:8