ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
28 protected $lng;
29
30 public function __construct(
33 ilMailUserHelper $usernameHelper = null,
35 ) {
39 $usernameHelper,
41 );
42
43 global $DIC;
44
45 $this->lng = $DIC['lng'];
46 $this->lng->loadLanguageModule('prg');
47 }
48
52 public function getId() : string
53 {
54 return self::ID;
55 }
56
60 public function getTitle() : string
61 {
62 return $this->lng->txt('prg_mail_context_title');
63 }
64
68 public function getDescription() : string
69 {
70 return $this->lng->txt('prg_mail_context_info');
71 }
72
77 public function getSpecificPlaceholders() : array
78 {
79 $placeholders = array();
80
81 $placeholders[self::TITLE] = array(
82 'placeholder' => 'STUDY_PROGRAMME_TITLE',
83 'label' => $this->lng->txt(self::TITLE)
84 );
85
86 $placeholders[self::DESCRIPTION] = array(
87 'placeholder' => 'STUDY_PROGRAMME_DESCRIPTION',
88 'label' => $this->lng->txt(self::DESCRIPTION)
89 );
90
91 $placeholders[self::TYPE] = array(
92 'placeholder' => 'STUDY_PROGRAMME_TYPE',
93 'label' => $this->lng->txt(self::TYPE)
94 );
95
96 $placeholders[self::LINK] = array(
97 'placeholder' => 'STUDY_PROGRAMME_LINK',
98 'label' => $this->lng->txt(self::LINK)
99 );
100
101 $placeholders[self::ORG_UNIT] = array(
102 'placeholder' => 'STUDY_PROGRAMME_ORG_UNITS',
103 'label' => $this->lng->txt(self::ORG_UNIT)
104 );
105
106 $placeholders[self::STATUS] = array(
107 'placeholder' => 'STUDY_PROGRAMME_STATUS',
108 'label' => $this->lng->txt(self::STATUS)
109 );
110
111 $placeholders[self::COMPLETION_DATE] = array(
112 'placeholder' => 'STUDY_PROGRAMME_COMPLETION_DATE',
113 'label' => $this->lng->txt(self::COMPLETION_DATE)
114 );
115
116 $placeholders[self::COMPLETED_BY] = array(
117 'placeholder' => 'STUDY_PROGRAMME_COMPLETED_BY',
118 'label' => $this->lng->txt(self::COMPLETED_BY)
119 );
120
121 $placeholders[self::POINTS_REQUIRED] = array(
122 'placeholder' => 'STUDY_PROGRAMME_POINTS_REQUIRED',
123 'label' => $this->lng->txt(self::POINTS_REQUIRED)
124 );
125
126 $placeholders[self::POINTS_CURRENT] = array(
127 'placeholder' => 'STUDY_PROGRAMME_POINTS_CURRENT',
128 'label' => $this->lng->txt(self::POINTS_CURRENT)
129 );
130
131 $placeholders[self::DEADLINE] = array(
132 'placeholder' => 'STUDY_PROGRAMME_DEADLINE',
133 'label' => $this->lng->txt(self::DEADLINE)
134 );
135
136 $placeholders[self::EXPIRE_DATE] = array(
137 'placeholder' => 'STUDY_PROGRAMME_EXPIRE_DATE',
138 'label' => $this->lng->txt(self::EXPIRE_DATE)
139 );
140
141 $placeholders[self::VALIDITY] = array(
142 'placeholder' => 'STUDY_PROGRAMME_VALIDITY',
143 'label' => $this->lng->txt(self::VALIDITY)
144 );
145
146 return $placeholders;
147 }
148
152 public function resolveSpecificPlaceholder(
153 string $placeholder_id,
154 array $context_parameters,
155 ilObjUser $recipient = null,
156 bool $html_markup = false
157 ) : string {
158 if (is_null($recipient)) {
159 return '';
160 }
161
162 if (!in_array($placeholder_id, [
163 self::TITLE,
164 self::DESCRIPTION,
165 self::TYPE,
166 self::LINK,
167 self::ORG_UNIT,
168 self::STATUS,
169 self::COMPLETION_DATE,
170 self::COMPLETED_BY,
171 self::POINTS_REQUIRED,
172 self::POINTS_CURRENT,
173 self::DEADLINE,
174 self::EXPIRE_DATE,
175 self::VALIDITY
176 ])) {
177 return '';
178 }
179
180 $obj_id = ilObject::_lookupObjectId($context_parameters['ref_id']);
181
183 $obj = ilObjectFactory::getInstanceByRefId($context_parameters['ref_id']);
184
185 $progress = $this->getNewestProgressForUser($obj, $recipient->getId());
186
187 switch ($placeholder_id) {
188 case self::TITLE:
189 $string = ilObject::_lookupTitle($obj_id);
190 break;
192 $string = ilObject::_lookupDescription($obj_id);
193 break;
194 case self::TYPE:
195 $string = '';
196 if (!is_null($obj->getSubType())) {
197 $string = (string) $obj->getSubType()->getTitle();
198 }
199 break;
200 case self::LINK:
201 $string = ilLink::_getLink($context_parameters['ref_id'], 'prg');
202 break;
203 case self::ORG_UNIT:
204 $string = ilObjUser::lookupOrgUnitsRepresentation($recipient->getId());
205 break;
206 case self::STATUS:
207 $string = $this->statusToRepr($progress->getStatus());
208 break;
210 $string = $this->date2String($progress->getCompletionDate());
211 break;
213 $string = '';
214 $id = $progress->getCompletionBy();
215 if (!is_null($id) && ilObject::_exists($id)) {
217 if ($obj->getType() == 'usr') {
218 $string = (string) ilObjUser::_lookupLogin($id);
219 } else {
220 if ($ref_id = ilContainerReference::_lookupTargetRefId($id)) {
221 if (
222 ilObject::_exists($ref_id, true) &&
223 is_null(ilObject::_lookupDeletedDate($ref_id))
224 ) {
226 }
227 }
228 }
229 }
230 break;
232 $string = (string) $progress->getAmountOfPoints();
233 break;
235 $string = (string) $progress->getCurrentAmountOfPoints();
236 break;
237 case self::DEADLINE:
238 $string = $this->date2String($progress->getDeadline());
239 break;
240 case self::VALIDITY:
241 $string = $this->lng->txt('prg_quali_not_valid');
242 $now = (new DateTime())->format('Y-m-d H:i:s');
243 $val_of_qual = $progress->getValidityOfQualification();
244
245 if (!is_null($val_of_qual)) {
246 $vq_date = $val_of_qual->format('Y-m-d H:i:s');
247 if ($vq_date > $now) {
248 $string = $this->lng->txt('prg_quali_still_valid');
249 }
250 }
251 break;
253 $string = $this->date2String($progress->getValidityOfQualification());
254 break;
255 default:
256 $string = '';
257 }
258
259 return $string;
260 }
261
263 {
264 $progress = $obj->getProgressesOf($user_id);
265
266 $successfully_progress = array_filter($progress, function (ilStudyProgrammeUserProgress $a) {
267 return $a->isSuccessful() || $a->isSuccessfulExpired() || $a->isAccredited();
268 });
269
270 if (count($successfully_progress) == 0) {
271 return $progress[0];
272 }
273
274 usort($successfully_progress, function (ilStudyProgrammeUserProgress $a, ilStudyProgrammeUserProgress $b) {
275 if ($a->getCompletionDate() > $b->getCompletionDate()) {
276 return -1;
277 } elseif ($a->getCompletionDate() < $b->getCompletionDate()) {
278 return 1;
279 } else {
280 return 0;
281 }
282 });
283
284 return array_shift($successfully_progress);
285 }
286
287 protected function statusToRepr(int $status) : string
288 {
290 return $this->lng->txt("prg_status_in_progress");
291 }
293 return $this->lng->txt("prg_status_completed");
294 }
296 return $this->lng->txt("prg_status_accredited");
297 }
299 return $this->lng->txt("prg_status_not_relevant");
300 }
302 return $this->lng->txt("prg_status_failed");
303 }
304 throw new ilException("Unknown status: '$status'");
305 }
306
307 protected function date2String(DateTime $date_time = null) : string
308 {
309 if (is_null($date_time)) {
310 return '';
311 }
312
313 return $date_time->format('d-m-Y H:i:s');
314 }
315}
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.
Base class for ILIAS Exception handling.
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)
Represents the progress of a user at one node of a study programme.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$DIC
Definition: xapitoken.php:46