ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
79 public function getHTML() : string
80 {
81 $items = [];
82 foreach ($this->getUsersAssignments() as $assignments) {
83 $properties = [];
84 krsort($assignments);
86 $current = current($assignments);
87 if (!$this->isReadable($current)) {
88 continue;
89 }
90
91 try {
92 $current_prg = $current->getStudyProgramme();
93 } catch(\ilException $e) {
94 continue;
95 }
96
98 $current_prg_settings = $current_prg->getRawSettings();
99
101 $current_progress = $current->getRootProgress();
102
103 list($valid, $validation_date) = $this->findValidationValues($assignments);
104
105 list($minimum_percents, $current_percents) = $this->calculatePercent(
106 $current_prg,
107 $current_progress->getCurrentAmountOfPoints()
108 );
109
110 $current_status = $current_progress->getStatus();
111 $validation_expires = $current_prg_settings->validationExpires();
112 $deadline = $current_prg_settings->getDeadlineSettings()->getDeadlineDate();
113 $restart_date = $current->getRestartDate();
114
115 $properties[] = $this->fillMinimumCompletion($minimum_percents);
116 $properties[] = $this->fillCurrentCompletion($current_percents);
117 $properties[] = $this->fillStatus((string) $current_status);
118
119 if ($this->isCompleted($current_status)) {
120 $properties[] = $this->fillRestartFrom($restart_date);
121 }
122
123 if ($this->isInProgress($current_status)) {
124 $properties[] = $this->fillFinishUntil($deadline);
125 }
126
127 if ($validation_expires && $valid) {
128 $properties[] = $this->fillValidUntil($validation_date);
129 } elseif (!$validation_expires && $valid) {
130 $properties[] = $this->fillValid();
131 } else {
132 $properties[] = $this->fillNotValid();
133 }
134
135 $items[] = $this->buildItem($current->getStudyProgramme(), $properties);
136 }
137
138 if (count($items) == 0) {
139 return "";
140 }
141
142 $group[] = $this->factory->item()->group("", $items);
143 $panel = $this->factory->panel()->listing()->standard($this->lng->txt("dash_studyprogramme"), $group);
144
145 return $this->renderer->render($panel);
146 }
147
148 protected function isCompleted(int $current_status) : bool
149 {
150 $status = [
153 ];
154 return in_array($current_status, $status);
155 }
156
157 protected function isInProgress(int $current_status) : bool
158 {
159 $status = [
161 ];
162 return in_array($current_status, $status);
163 }
164
165 protected function fillValidUntil(DateTime $value = null) : array
166 {
167 $date_string = "";
168 if (!is_null($value)) {
169 $date = new ilDate(
170 $value->format('Y-m-d'),
172 );
173 $date_string = ilDatePresentation::formatDate($date);
174 }
175 return [
176 $this->txt('prg_dash_label_valid') => $date_string
177 ];
178 }
179
180 protected function fillNotValid() : array
181 {
182 return [
183 $this->txt('prg_dash_label_valid') => $this->txt('no')
184 ];
185 }
186
187 protected function fillValid() : array
188 {
189 return [
190 $this->txt('prg_dash_label_valid') => $this->txt('yes')
191 ];
192 }
193
194 protected function fillMinimumCompletion(float $value) : array
195 {
196 $title = $value . " " . $this->txt('percentage');
197 return [
198 $this->txt('prg_dash_label_minimum') => $title
199 ];
200 }
201
202 protected function fillCurrentCompletion(float $value) : array
203 {
204 $title = $value . " " . $this->txt('percentage');
205 return [
206 $this->txt('prg_dash_label_gain') => $title
207 ];
208 }
209
210 protected function fillStatus(string $status) : array
211 {
212 return [
213 $this->txt('prg_dash_label_status') => $this->txt('prg_status_' . $status)
214 ];
215 }
216
217 protected function fillFinishUntil(DateTime $value = null) : array
218 {
219 $ret = [];
220 if (!is_null($value)) {
221 $date = new ilDate(
222 $value->format('Y-m-d'),
224 );
225 $date_string = ilDatePresentation::formatDate($date);
226 $ret[$this->txt('prg_dash_label_finish_until')] = $date_string;
227 }
228 return $ret;
229 }
230
231 protected function fillRestartFrom(DateTime $value = null) : array
232 {
233 $ret = [];
234 if (!is_null($value)) {
235 $date = new ilDate(
236 $value->format('Y-m-d'),
238 );
239 $date_string = ilDatePresentation::formatDate($date);
240 $ret[$this->txt('prg_dash_label_restart_from')] = $date_string;
241 }
242 return $ret;
243 }
244
245 protected function getVisibleOnPDMode() : string
246 {
247 if (is_null($this->visible_on_pd_mode)) {
248 $this->visible_on_pd_mode =
249 $this->setting->get(
252 );
253 }
255 }
256
260 protected function hasPermission(
262 string $permission
263 ) : bool {
264 $prg = $assignment->getStudyProgramme();
265 return $this->access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
266 }
267
271 protected function isReadable(ilStudyProgrammeUserAssignment $assignment) : bool
272 {
273 if ($this->getVisibleOnPDMode() == ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
274 return true;
275 }
276
277 return $this->hasPermission($assignment, "read");
278 }
279
283 protected function getUsersAssignments() : array
284 {
286 $assignments_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
287 return $assignments_db->getDashboardInstancesforUser($this->user->getId());
288 }
289
290 protected function txt(string $code) : string
291 {
292 return $this->lng->txt($code);
293 }
294
295 protected function calculatePercent(ilObjStudyProgramme $prg, int $current_points) : array
296 {
297 $minimum_percents = 0;
298 $current_percents = 0;
299
300 if ($prg->hasLPChildren()) {
301 $minimum_percents = 100;
302 if ($current_points > 0) {
303 $current_percents = 100;
304 }
305 }
306
307 $children = $prg->getAllPrgChildren();
308 if (count($children) > 0) {
309 $max_points = 0;
310 foreach ($children as $child) {
311 $max_points += $child->getPoints();
312 }
313
314 if ($max_points > 0) {
315 $prg_points = $prg->getPoints();
316 $minimum_percents = round((100 * $prg_points / $max_points), 2);
317 }
318 if ($current_points > 0) {
319 $current_percents = round((100 * $current_points / $max_points), 2);
320 }
321 }
322
323 return [
324 $minimum_percents,
325 $current_percents
326 ];
327 }
328
329
333 protected function findValidationValues(array $assignments) : array
334 {
335 $validation_date = $this->findValid($assignments);
336
337 return [
338 !is_null($validation_date) && $validation_date->format("Y-m-d") > date("Y-m-d"),
339 $validation_date
340 ];
341 }
342
348 protected function findValid(array $assignments)
349 {
350 $status = [
353 ];
355 foreach ($assignments as $key => $assignment) {
356 $progress = $assignment->getRootProgress();
357 if (in_array($progress->getStatus(), $status)) {
358 return $progress->getValidityOfQualification();
359 }
360 }
361 return null;
362 }
363
364 protected function buildItem(
366 array $properties
367 ) : ILIAS\UI\Component\Item\Item {
368 $title = $prg->getTitle();
369 $link = $this->getDefaultTargetUrl((int) $prg->getRefId());
370 $title_btn = $this->factory->button()->shy($title, $link);
371 $description = $prg->getLongDescription() ?? "";
372 $max = $this->setting->get("rep_shorten_description_length");
373 if ($this->setting->get("rep_shorten_description") && $max) {
374 $description = ilUtil::shortenText($description, $max, true);
375 }
376
377 $icon = $this->factory->symbol()->icon()->standard('prg', $title, 'medium');
378 return $this->factory->item()->standard($title_btn)
379 ->withProperties(array_merge(...$properties))
380 ->withDescription($description)
381 ->withLeadIcon($icon)
382 ;
383 }
384
385 protected function getDefaultTargetUrl(int $prg_ref_id) : string
386 {
387 $this->ctrl->setParameterByClass(
388 ilObjStudyProgrammeGUI::class,
389 'ref_id',
390 $prg_ref_id
391 );
392 $link = $this->ctrl->getLinkTargetByClass(
393 [
394 ilRepositoryGUI::class,
395 ilObjStudyProgrammeGUI::class,
396 ]
397 );
398 $this->ctrl->setParameterByClass(
399 ilObjStudyProgrammeGUI::class,
400 'ref_id',
401 null
402 );
403 return $link;
404 }
405}
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.
Base class for ILIAS Exception handling.
language handling
Component logger with individual log levels by component id.
hasLPChildren()
Does this StudyProgramme has leafs?
getPoints()
Get the amount of points.
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
ILIAS Setting Class.
__construct(ilLanguage $lng, ilObjUser $user, ilAccess $access, ilSetting $setting, ILIAS\UI\Factory $factory, ILIAS\UI\Renderer $renderer, ilCtrl $ctrl, ilLogger $log)
buildItem(ilObjStudyProgramme $prg, array $properties)
isReadable(ilStudyProgrammeUserAssignment $assignment)
hasPermission(ilStudyProgrammeUserAssignment $assignment, string $permission)
calculatePercent(ilObjStudyProgramme $prg, int $current_points)
Represents one assignment of a user to a study programme.
getRootProgress()
Get the progress on the root node of the programme.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
$valid
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$ret
Definition: parser.php:6