ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPRGActionNoteBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
23
28{
29 protected UIFactory $ui_factory;
31 protected ilLanguage $lng;
32 protected ilCtrl $ctrl;
33 protected ilTemplate $tpl;
36 protected int $usr_id;
37
38 public function __construct(
39 UIFactory $ui_factory,
46 int $usr_id
47 ) {
48 global $DIC;
49 $this->ui_factory = $ui_factory;
50 $this->ui_renderer = $ui_renderer;
51 $this->lng = $DIC->language();
52 $this->ctrl = $ctrl;
53 $this->tpl = $tpl;
54 $this->repo_assignment = $repo_assignment;
55 $this->repo_settings = $repo_settings;
56 $this->usr_id = $usr_id;
57 }
58
59 public function getNoteFor(int $prg_obj_id): string
60 {
61 $ass = $this->repo_assignment->getLatestAssignment($prg_obj_id, $this->usr_id);
62 $instruction = '';
63 $icon = 'page_editor/icon_pean.svg';
64 $dealine_str = '';
65
66 if ($ass) {
67 $progresses[] = $ass->getProgressTree();
68 $now = new DateTimeImmutable();
69 $deadline = null;
70 $in_progress = array_filter($progresses, fn($pgs) => $pgs->isInProgress());
71 $accredited_or_completed = array_filter($progresses, fn($pgs) => $pgs->isSuccessful());
72 if (count($in_progress) === 0) {
73 $failed = array_filter($progresses, fn($pgs) => $pgs->isFailed());
74 $failed = $this->sortByDeadline($failed);
75 if (count($accredited_or_completed) > 0) {
76 $instruction = 'pc_prgactionnote_no_actions_required';
77 }
78 if (count($failed) > 0 && count($accredited_or_completed) === 0) {
79 $instruction = 'pc_prgactionnote_no_actions_required';
80 $deadline = array_shift($failed)->getDeadline();
81 $dealine_str = ' ' . $deadline->format($this->getUserDateFormat());
82 }
83 } elseif($accredited_or_completed) {
84 $instruction = 'pc_prgactionnote_no_actions_required';
85 } else {
86 $instruction = 'pc_prgactionnote_complete_content';
87 $in_progress_with_deadline = $this->sortByDeadline($in_progress);
88 $in_progress_with_deadline = array_filter(
89 $in_progress_with_deadline,
90 fn($pgs) => $pgs->getDeadline()->format('Y-m-d') >= $now->format('Y-m-d')
91 );
92 if (count($in_progress_with_deadline) > 0) {
93 $deadline = array_shift($in_progress_with_deadline)->getDeadline();
94 }
95
96 if (!is_null($deadline)) {
97 $dealine_str = ' ' . $deadline->format($this->getUserDateFormat()) . '.';
98 $instruction = 'pc_prgactionnote_complete_content_with_deadline';
99 }
100 }
101 } else {
102 $instruction = 'pc_prgactionnote_no_actions_required';
103 }
104
105 $icon = $this->ui_renderer->render(
106 $this->ui_factory->symbol()->icon()->custom(
108 $this->lng->txt($instruction)
109 )->withSize('large')
110 );
111
112 $this->tpl->setVariable("HEADLINE", $this->lng->txt('pc_prgactionnote_headline'));
113 $this->tpl->setVariable("ICON", $icon);
114 $this->tpl->setVariable("NOTE_TEXT", $this->lng->txt($instruction) . $dealine_str);
115 return $this->tpl->get();
116 }
117
118 protected function sortByDeadline(array $progresses): array
119 {
120 $progresses = array_filter($progresses, fn($pgs) => $pgs->getDeadline());
121 usort(
122 $progresses,
123 static function (ilPRGProgress $a, ilPRGProgress $b): int {
124 $a_dat = $a->getDeadline();
125 $b_dat = $b->getDeadline();
126 if ($a_dat === $b_dat) {
127 return 0;
128 }
129 return ($a_dat < $b_dat) ? -1 : 1;
130 }
131 );
132 return $progresses;
133 }
134
135 protected function getUserDateFormat(): string
136 {
137 return ilCalendarUtil::getUserDateFormat(0, true);
138 }
139}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static getUserDateFormat(int $a_add_time=0, bool $a_for_parsing=false)
Parse current user setting into date/time format.
Class ilCtrl provides processing control methods.
language handling
Builds PageContent "Note".
__construct(UIFactory $ui_factory, Renderer $ui_renderer, ilLanguage $lng, ilCtrl $ctrl, ilTemplate $tpl, PRGAssignmentRepository $repo_assignment, ilStudyProgrammeSettingsRepository $repo_settings, int $usr_id)
PRGAssignmentRepository $repo_assignment
ilStudyProgrammeSettingsRepository $repo_settings
sortByDeadline(array $progresses)
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
An entity that renders components to a string output.
Definition: Renderer.php:31
Covers the persistence of settings belonging to a study programme (SP).
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26