ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPDStudyProgrammeSimpleListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
32{
33 public const BLOCK_TYPE = "prgsimplelist";
34
39 protected $logger;
40 protected ilStudyProgrammeAssignmentDBRepository $sp_user_assignment_db;
42 protected Factory $refinery;
43
47 protected array $users_assignments;
48 protected ?string $visible_on_pd_mode;
49 protected bool $show_info_message;
50
51 public function __construct()
52 {
53 global $DIC;
54
56
57 $this->setting = $DIC['ilSetting'];
58 $this->logger = ilLoggerFactory::getLogger('prg');
59 $this->sp_user_assignment_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
60 $this->request_wrapper = $DIC->http()->wrapper()->query();
61 $this->refinery = $DIC->refinery();
62
63 // No need to load data, as we won't display this.
64 if (!$this->shouldShowThisList()) {
65 return;
66 }
67
68 $this->getUsersAssignments();
69 //check which kind of option is selected in settings
70 $this->getVisibleOnPDMode();
71 //check to display info message if option "read" is selected
72 $viewSettings = new ilPDSelectedItemsBlockViewSettings(
73 $DIC->user(),
74 $this->request_wrapper->retrieve("view", $this->refinery->kindlyTo()->int())
75 );
76 $this->show_info_message = $viewSettings->isStudyProgrammeViewActive();
77
78 // As this won't be visible we don't have to initialize this.
79 if (!$this->userHasReadableStudyProgrammes()) {
80 return;
81 }
82
83 $this->setTitle($this->lng->txt("objs_prg"));
84 }
85
86 public function getHTML(): string
87 {
88 // TODO: This should be determined from somewhere up in the hierarchy, as
89 // this will lead to problems, when e.g. a command changes. But i don't see
90 // how atm...
91 if (!$this->shouldShowThisList()) {
92 return "";
93 }
94
95 if (!$this->userHasReadableStudyProgrammes()) {
96 return "";
97 }
98 return parent::getHTML();
99 }
100
101 public function getDataSectionContent(): string
102 {
103 $content = "";
104 foreach ($this->users_assignments as $assignment) {
105 if (!$this->isReadable($assignment)) {
106 continue;
107 }
108
109 try {
110 $list_item = $this->new_ilStudyProgrammeAssignmentListGUI($assignment);
111 $list_item->setShowInfoMessage($this->show_info_message);
112 $list_item->setVisibleOnPDMode($this->visible_on_pd_mode);
113 $content .= $list_item->getHTML();
115 $this->logger->alert((string) $e);
117 $this->logger->alert((string) $e);
118 }
119 }
120 return $content;
121 }
122
126 public function getBlockType(): string
127 {
128 return self::BLOCK_TYPE;
129 }
130
134 protected function isRepositoryObject(): bool
135 {
136 return false;
137 }
138 protected function userHasVisibleStudyProgrammes(): bool
139 {
140 if (count($this->users_assignments) === 0) {
141 return false;
142 }
143 foreach ($this->users_assignments as $assignment) {
144 if ($this->isVisible($assignment)) {
145 return true;
146 }
147 }
148 return false;
149 }
150
151 protected function userHasReadableStudyProgrammes(): bool
152 {
153 if (count($this->users_assignments) === 0) {
154 return false;
155 }
156 foreach ($this->users_assignments as $assignment) {
157 if ($this->isReadable($assignment)) {
158 return true;
159 }
160 }
161 return false;
162 }
163
164 protected function getVisibleOnPDMode(): void
165 {
166 $this->visible_on_pd_mode = $this->setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
167 }
168
169 protected function hasPermission(ilStudyProgrammeAssignment $assignment, string $permission): bool
170 {
171 $prg = ilObjStudyProgramme::getInstanceByObjId($assignment->getRootId());
172 return $this->access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
173 }
174
175 protected function isVisible(ilStudyProgrammeAssignment $assignment): bool
176 {
177 return $this->hasPermission($assignment, "visible");
178 }
179
180 protected function isReadable(ilStudyProgrammeAssignment $assignment): bool
181 {
182 if ($this->visible_on_pd_mode === ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
183 return true;
184 }
185
186 return $this->hasPermission($assignment, "read");
187 }
188
189 protected function shouldShowThisList(): bool
190 {
191 $cmd = $this->request_wrapper->retrieve("cmd", $this->refinery->kindlyTo()->string());
192 $expand = $this->request_wrapper->retrieve("expand", $this->refinery->kindlyTo()->bool());
193 $jump_to_selected_list = $cmd === "jumpToSelectedItems";
194 $is_ilDashboardGUI = $this->ctrl->getCmdClass() === "ildashboardgui";
195 $is_cmd_show = $this->ctrl->getCmd() === "show";
196
197 return ($jump_to_selected_list || ($is_ilDashboardGUI && $is_cmd_show)) && !$expand;
198 }
199
200 protected function getUsersAssignments(): void
201 {
202 $this->users_assignments = $this->sp_user_assignment_db->getInstancesOfUser($this->user->getId());
203 }
204
206 ilStudyProgrammeAssignment $assignment
208 $progress = $assignment->getProgressTree();
209 $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
210 $progress_gui->setOnlyRelevant(true);
211 return $progress_gui;
212 }
213}
Builds data types.
Definition: Factory.php:36
This class represents a block method of a block.
setTitle(string $a_title)
static getLogger(string $a_component_id)
Get component logger.
static getInstanceByObjId(int $obj_id)
Personal Desktop-Presentation for the Study Programme.
hasPermission(ilStudyProgrammeAssignment $assignment, string $permission)
isRepositoryObject()
Returns whether block has a corresponding repository object.
isVisible(ilStudyProgrammeAssignment $assignment)
isReadable(ilStudyProgrammeAssignment $assignment)
ilStudyProgrammeAssignmentDBRepository $sp_user_assignment_db
new_ilStudyProgrammeAssignmentListGUI(ilStudyProgrammeAssignment $assignment)
ILIAS Setting Class.
Exception is thrown when progress for some programme node and assignment is missing.
Class ilStudyProgrammeProgressListGUI.
Exception is thrown when invariants on the program tree would be violated by manipulation of tree.
Interface RequestWrapper.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26