ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilPRGStatusInfoBuilder.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;
37 protected int $usr_id;
38
39 public function __construct(
40 UIFactory $ui_factory,
48 int $usr_id
49 ) {
50 global $DIC;
51 $this->ui_factory = $ui_factory;
52 $this->ui_renderer = $ui_renderer;
53 $this->lng = $DIC->language();
54 $this->ctrl = $ctrl;
55 $this->tpl = $tpl;
56 $this->repo_assignment = $repo_assignment;
57 $this->repo_settings = $repo_settings;
58 $this->cert_validator = $cert_validator;
59 $this->usr_id = $usr_id;
60 }
61
62 public function getStatusInfoFor(int $prg_obj_id): string
63 {
64 $status = 'pc_prgstatus_status_no_qualification';
65 $status_txt = 'pc_prgstatus_text_no_qualification';
66 $validity_txt = '';
67 $icon = 'standard/icon_not_ok.svg';
68 $restart_date = null;
69
70 $ass = $this->repo_assignment->getLongestValidAssignment($prg_obj_id, $this->usr_id)
71 ?? $this->repo_assignment->getLatestAssignment($prg_obj_id, $this->usr_id);
72
73 if ($ass) {
74 $pgs = $ass->getProgressTree();
75 $now = new DateTimeImmutable();
76 if ($pgs->hasValidQualification($now)) {
77 $status = 'pc_prgstatus_status_valid_qualification';
78 $status_txt = 'pc_prgstatus_unlimited_validation';
79 $icon = 'standard/icon_ok.svg';
80 }
81
82 if ($validity = $pgs->getValidityOfQualification()) {
83 $status_txt = 'pc_prgstatus_expiration_date';
84 $validity_txt = ' ' . $validity->format('d.m.Y');
85
86 $restart = $this->getRestartPeriodOfProgrammeNode($prg_obj_id);
87 if (!is_null($restart)) {
88 $restart_date = $validity->sub($restart)->format('d.m.Y');
89 }
90 }
91 }
92
93 $icon = $this->ui_renderer->render(
94 $this->ui_factory->symbol()->icon()->custom(
96 $this->lng->txt($status_txt)
97 )
98 ->withSize('large')
99 );
100 $this->tpl->setVariable("ICON", $icon);
101 $this->tpl->setVariable("HEADLINE", $this->lng->txt("pc_prgstatus_qualification_headline"));
102 $this->tpl->setVariable("STATUS", $this->lng->txt($status));
103 $this->tpl->setVariable("STATUS_TEXT", $this->lng->txt($status_txt) . $validity_txt);
104 if ($certificate_link = $this->maybeGetCertificateLink($prg_obj_id)) {
105 $this->tpl->setVariable("CERTIFICATE", $certificate_link);
106 }
107 if ($restart_date) {
108 $this->tpl->setVariable("EDIT_QUALIFICATION", $this->lng->txt("pc_prgstatus_edit_qualification") . " " . $restart_date);
109 }
110 return $this->tpl->get();
111 }
112
113 protected function getRestartPeriodOfProgrammeNode(int $prg_obj_id): ?DateInterval
114 {
115 $settings = $this->repo_settings->get($prg_obj_id);
116 $offset_days = $settings->getValidityOfQualificationSettings()->getRestartPeriod();
117 if ($offset_days) {
118 return new DateInterval('P' . $offset_days . 'D');
119 }
120 return null;
121 }
122
123 protected function maybeGetCertificateLink(int $prg_obj_id): ?string
124 {
125 if ($this->cert_validator->isCertificateDownloadable($this->usr_id, $prg_obj_id)) {
126 $target = $this->ctrl->getLinkTargetByClass("ilObjStudyProgrammeGUI", "deliverCertificate");
127 return $this->ui_renderer->render($this->ui_factory->link()->standard($this->lng->txt('download_certificate'), $target));
128 }
129 return null;
130 }
131}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Validates if an active certificate is stored in the database and can be downloaded by the user.
Class ilCtrl provides processing control methods.
language handling
Builds PageContent "Status Information".
__construct(UIFactory $ui_factory, Renderer $ui_renderer, ilLanguage $lng, ilCtrl $ctrl, ilTemplate $tpl, PRGAssignmentRepository $repo_assignment, ilStudyProgrammeSettingsRepository $repo_settings, ilCertificateDownloadValidator $cert_validator, int $usr_id)
ilCertificateDownloadValidator $cert_validator
getRestartPeriodOfProgrammeNode(int $prg_obj_id)
PRGAssignmentRepository $repo_assignment
ilStudyProgrammeSettingsRepository $repo_settings
maybeGetCertificateLink(int $prg_obj_id)
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).
global $DIC
Definition: shib_login.php:26