ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDStudyProgrammeSimpleListGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
32 {
33  public const BLOCK_TYPE = "prgsimplelist";
34 
35  protected ilSetting $setting;
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);
116  } catch (ilStudyProgrammeTreeException $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 
139  public function fillDataSection(): void
140  {
141  assert($this->userHasReadableStudyProgrammes()); // We should not get here.
142  $this->tpl->setVariable("BLOCK_ROW", $this->getDataSectionContent());
143  }
144 
145  protected function userHasVisibleStudyProgrammes(): bool
146  {
147  if (count($this->users_assignments) === 0) {
148  return false;
149  }
150  foreach ($this->users_assignments as $assignment) {
151  if ($this->isVisible($assignment)) {
152  return true;
153  }
154  }
155  return false;
156  }
157 
158  protected function userHasReadableStudyProgrammes(): bool
159  {
160  if (count($this->users_assignments) === 0) {
161  return false;
162  }
163  foreach ($this->users_assignments as $assignment) {
164  if ($this->isReadable($assignment)) {
165  return true;
166  }
167  }
168  return false;
169  }
170 
171  protected function getVisibleOnPDMode(): void
172  {
173  $this->visible_on_pd_mode = $this->setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
174  }
175 
176  protected function hasPermission(ilStudyProgrammeAssignment $assignment, string $permission): bool
177  {
178  $prg = ilObjStudyProgramme::getInstanceByObjId($assignment->getRootId());
179  return $this->access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
180  }
181 
182  protected function isVisible(ilStudyProgrammeAssignment $assignment): bool
183  {
184  return $this->hasPermission($assignment, "visible");
185  }
186 
187  protected function isReadable(ilStudyProgrammeAssignment $assignment): bool
188  {
189  if ($this->visible_on_pd_mode === ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
190  return true;
191  }
192 
193  return $this->hasPermission($assignment, "read");
194  }
195 
196  protected function shouldShowThisList(): bool
197  {
198  $cmd = $this->request_wrapper->retrieve("cmd", $this->refinery->kindlyTo()->string());
199  $expand = $this->request_wrapper->retrieve("expand", $this->refinery->kindlyTo()->bool());
200  $jump_to_selected_list = $cmd === "jumpToSelectedItems";
201  $is_ilDashboardGUI = $this->ctrl->getCmdClass() === "ildashboardgui";
202  $is_cmd_show = $this->ctrl->getCmd() === "show";
203 
204  return ($jump_to_selected_list || ($is_ilDashboardGUI && $is_cmd_show)) && !$expand;
205  }
206 
207  protected function getUsersAssignments(): void
208  {
209  $this->users_assignments = $this->sp_user_assignment_db->getInstancesOfUser($this->user->getId());
210  }
211 
213  ilStudyProgrammeAssignment $assignment
215  $progress = $assignment->getProgressTree();
216  $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
217  $progress_gui->setOnlyRelevant(true);
218  return $progress_gui;
219  }
220 }
ilStudyProgrammeAssignmentDBRepository $sp_user_assignment_db
new_ilStudyProgrammeAssignmentListGUI(ilStudyProgrammeAssignment $assignment)
static getLogger(string $a_component_id)
Get component logger.
hasPermission(ilStudyProgrammeAssignment $assignment, string $permission)
isVisible(ilStudyProgrammeAssignment $assignment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface RequestWrapper.
Personal Desktop-Presentation for the Study Programme.
isReadable(ilStudyProgrammeAssignment $assignment)
static getInstanceByObjId(int $obj_id)
__construct(Container $dic, ilPlugin $plugin)
setTitle(string $a_title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a block method of a block.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...