ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeDashboardViewGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5declare(strict_types=1);
6
8{
9
13 protected $lng;
14
18 protected $user;
19
23 protected $access;
24
28 protected $setting;
29
34
38 protected $log;
39
43 protected $factory;
44
48 protected $renderer;
49
53 protected $ctrl;
54
55 public function __construct(
60 ILIAS\UI\Factory $factory,
61 ILIAS\UI\Renderer $renderer,
64 ) {
65 $this->lng = $lng;
66 $this->lng->loadLanguageModule('prg');
67 $this->user = $user;
68 $this->access = $access;
69 $this->setting = $setting;
70 $this->log = $log;
71 $this->factory = $factory;
72 $this->renderer = $renderer;
73 $this->ctrl = $ctrl;
74 }
75
76
82 {
83 if (!$this->progress_repository) {
84 $this->progress_repository = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserProgressDB'];
85 }
87 }
88
94 {
95 if (!$this->assignment_repository) {
96 $this->assignment_repository = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
97 }
99 }
100
104 protected function getUsersAssignments() : array
105 {
106 return $this->getAssignmentRepository()->getDashboardInstancesforUser($this->user->getId());
107 }
108
112 public function getHTML() : string
113 {
114 $items = [];
115 $now = new DateTimeImmutable();
116
117 foreach ($this->getUsersAssignments() as $assignments) {
118 $properties = [];
119 krsort($assignments);
120
121 $assignment = current($assignments);
122 if (!$this->isReadable($assignment)) {
123 continue;
124 }
125
126 $progress = $this->getProgressRepository()->getRootProgressOf($assignment);
127
128 $current_prg = ilObjStudyProgramme::getInstanceByObjId($assignment->getRootId());
129 list($minimum_percents, $current_percents) = $this->calculatePercent(
130 $current_prg,
131 $progress->getCurrentAmountOfPoints()
132 );
133
134 $current_status = $progress->getStatus();
135 $deadline = $progress->getDeadline();
136 $restart_date = $assignment->getRestartDate();
137
138 $properties[] = $this->fillMinimumCompletion($minimum_percents);
139 $properties[] = $this->fillCurrentCompletion($current_percents);
140 $properties[] = $this->fillStatus((string) $current_status);
141
142 if ($progress->isSuccessful()) {
143 $properties[] = $this->fillRestartFrom($restart_date);
144
145 $valid = $progress->hasValidQualification($now);
146 $validation_expiry_date = $progress->getValidityOfQualification();
147 $properties[] = $this->fillValidation($valid, $validation_expiry_date);
148 }
149 if ($progress->isInProgress()) {
150 $properties[] = $this->fillFinishUntil($deadline);
151 }
152
153
154
155 $items[] = $this->buildItem($current_prg, $properties);
156 }
157
158 if (count($items) == 0) {
159 return "";
160 }
161
162 $group[] = $this->factory->item()->group("", $items);
163 $panel = $this->factory->panel()->listing()->standard($this->lng->txt("dash_studyprogramme"), $group);
164
165 return $this->renderer->render($panel);
166 }
167
168
169
170 protected function isInProgress(int $current_status) : bool
171 {
172 $status = [
174 ];
175 return in_array($current_status, $status);
176 }
177
178 protected function fillValidation(
179 ?bool $valid,
180 ?DateTimeImmutable $validation_expiry_date
181 ) : array {
182 if (!$valid) {
183 $validation = $this->txt('no');
184 }
185 if ($valid && is_null($validation_expiry_date)) {
186 $validation = $this->txt('yes');
187 }
188 if ($valid && !is_null($validation_expiry_date)) {
189 $date = new ilDate($validation_expiry_date->format('Y-m-d'), IL_CAL_DATE);
190 $validation = ilDatePresentation::formatDate($date);
191 }
192
193 return [
194 $this->txt('prg_dash_label_valid') => $validation
195 ];
196 }
197
198 protected function fillMinimumCompletion(float $value) : array
199 {
200 $title = $value . " " . $this->txt('percentage');
201 return [
202 $this->txt('prg_dash_label_minimum') => $title
203 ];
204 }
205
206 protected function fillCurrentCompletion(float $value) : array
207 {
208 $title = $value . " " . $this->txt('percentage');
209 return [
210 $this->txt('prg_dash_label_gain') => $title
211 ];
212 }
213
214 protected function fillStatus(string $status) : array
215 {
216 return [
217 $this->txt('prg_dash_label_status') => $this->txt('prg_status_' . $status)
218 ];
219 }
220
221 protected function fillFinishUntil(DateTimeImmutable $value = null) : array
222 {
223 $ret = [];
224 if (!is_null($value)) {
225 $date = new ilDate(
226 $value->format('Y-m-d'),
228 );
229 $date_string = ilDatePresentation::formatDate($date);
230 $ret[$this->txt('prg_dash_label_finish_until')] = $date_string;
231 }
232 return $ret;
233 }
234
235 protected function fillRestartFrom(DateTimeImmutable $value = null) : array
236 {
237 $ret = [];
238 if (!is_null($value)) {
239 $date = new ilDate(
240 $value->format('Y-m-d'),
242 );
243 $date_string = ilDatePresentation::formatDate($date);
244 $ret[$this->txt('prg_dash_label_restart_from')] = $date_string;
245 }
246 return $ret;
247 }
248
249 protected function getVisibleOnPDMode() : string
250 {
251 if (is_null($this->visible_on_pd_mode)) {
252 $this->visible_on_pd_mode =
253 $this->setting->get(
256 );
257 }
258 return $this->visible_on_pd_mode;
259 }
260
264 protected function hasPermission(
265 ilStudyProgrammeAssignment $assignment,
266 string $permission
267 ) : bool {
268 try {
269 $prg = ilObjStudyProgramme::getInstanceByObjId($assignment->getRootId());
270 } catch (\ilException $e) {
271 return false;
272 }
273 return $this->access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
274 }
275
279 protected function isReadable(ilStudyProgrammeAssignment $assignment) : bool
280 {
281 if ($this->getVisibleOnPDMode() == ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
282 return true;
283 }
284
285 return $this->hasPermission($assignment, "read");
286 }
287
288 protected function txt(string $code) : string
289 {
290 return $this->lng->txt($code);
291 }
292
293 protected function calculatePercent(ilObjStudyProgramme $prg, int $current_points) : array
294 {
295 $minimum_percents = 0;
296 $current_percents = 0;
297
298 if ($prg->hasLPChildren()) {
299 $minimum_percents = 100;
300 if ($current_points > 0) {
301 $current_percents = 100;
302 }
303 }
304
305 $children = $prg->getAllPrgChildren();
306 if (count($children) > 0) {
307 $max_points = 0;
308 foreach ($children as $child) {
309 $max_points += $child->getPoints();
310 }
311
312 if ($max_points > 0) {
313 $prg_points = $prg->getPoints();
314 $minimum_percents = round((100 * $prg_points / $max_points), 2);
315 }
316 if ($current_points > 0) {
317 $current_percents = round((100 * $current_points / $max_points), 2);
318 }
319 }
320
321 return [
322 $minimum_percents,
323 $current_percents
324 ];
325 }
326
327
331 protected function findValidationValues(array $assignments) : array
332 {
333 $validation_date = $this->findValid($assignments);
334
335 return [
336 !is_null($validation_date) && $validation_date->format("Y-m-d") > date("Y-m-d"),
337 $validation_date
338 ];
339 }
340
341
342 protected function findValid(array $assignments)
343 {
344 $status = [
347 ];
348 foreach ($assignments as $key => $assignment) {
349 $prg = ilObjStudyProgramme::getInstanceByObjId($assignment->getRootId());
350 $progress = $prg->getProgressForAssignment($assignment->getId());
351
352 if (in_array($progress->getStatus(), $status)) {
353 return $progress->getValidityOfQualification();
354 }
355 }
356 return null;
357 }
358
359 protected function buildItem(
361 array $properties
362 ) : ILIAS\UI\Component\Item\Item {
363 $title = $prg->getTitle();
364 $link = $this->getDefaultTargetUrl((int) $prg->getRefId());
365 $title_btn = $this->factory->button()->shy($title, $link);
366 $description = $prg->getLongDescription() ?? "";
367 $max = $this->setting->get("rep_shorten_description_length");
368 if ($this->setting->get("rep_shorten_description") && $max) {
369 $description = ilUtil::shortenText($description, $max, true);
370 }
371
372 $icon = $this->factory->symbol()->icon()->standard('prg', $title, 'medium');
373 return $this->factory->item()->standard($title_btn)
374 ->withProperties(array_merge(...$properties))
375 ->withDescription($description)
376 ->withLeadIcon($icon)
377 ;
378 }
379
380 protected function getDefaultTargetUrl(int $prg_ref_id) : string
381 {
382 $this->ctrl->setParameterByClass(
383 ilObjStudyProgrammeGUI::class,
384 'ref_id',
385 $prg_ref_id
386 );
387 $link = $this->ctrl->getLinkTargetByClass(
388 [
389 ilRepositoryGUI::class,
390 ilObjStudyProgrammeGUI::class,
391 ]
392 );
393 $this->ctrl->setParameterByClass(
394 ilObjStudyProgrammeGUI::class,
395 'ref_id',
396 null
397 );
398 return $link;
399 }
400}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
Class ilAccessHandler.
This class provides processing control methods.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
Component logger with individual log levels by component id.
getPoints()
Get the amount of points.
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
ILIAS Setting Class.
Represents one assignment of the user to a program tree.
isReadable(ilStudyProgrammeAssignment $assignment)
__construct(ilLanguage $lng, ilObjUser $user, ilAccess $access, ilSetting $setting, ILIAS\UI\Factory $factory, ILIAS\UI\Renderer $renderer, ilCtrl $ctrl, ilLogger $log)
hasPermission(ilStudyProgrammeAssignment $assignment, string $permission)
buildItem(ilObjStudyProgramme $prg, array $properties)
fillValidation(?bool $valid, ?DateTimeImmutable $validation_expiry_date)
calculatePercent(ilObjStudyProgramme $prg, int $current_points)
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
try
Definition: cron.php:22
$valid
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:138
Covers the persistence of settings belonging to a study programme (SP).
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$ret
Definition: parser.php:6