ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPDStudyProgrammeSimpleListGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("Services/Block/classes/class.ilBlockGUI.php");
6 require_once('./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeAdmin.php');
7 require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockGUI.php';
8 
17 {
18  const BLOCK_TYPE = "prgsimplelist";
19 
23  protected $il_lng;
24 
28  protected $il_user;
29 
33  protected $il_access;
34 
38  protected $il_setting;
39 
43  protected $users_assignments;
44 
49 
53  protected $show_info_message;
54 
55  public function __construct()
56  {
57  global $DIC;
58 
59  parent::__construct();
60 
61  $lng = $DIC['lng'];
62  $ilUser = $DIC['ilUser'];
63  $ilAccess = $DIC['ilAccess'];
64  $ilSetting = $DIC['ilSetting'];
65  $this->il_lng = $lng;
66  $this->il_user = $ilUser;
67  $this->il_access = $ilAccess;
68  $this->il_setting = $ilSetting;
69  $this->il_logger = ilLoggerFactory::getLogger('prg');
70 
71  // No need to load data, as we won't display this.
72  if (!$this->shouldShowThisList()) {
73  return;
74  }
75 
76  $this->readUsersAssignments();
77  //check which kind of option is selected in settings
78  $this->readVisibleOnPDMode();
79  //check to display info message if option "read" is selected
80  $this->readToShowInfoMessage();
81 
82  // As this won't be visible we don't have to initialize this.
83  if (!$this->userHasReadableStudyProgrammes()) {
84  return;
85  }
86 
87  $this->setTitle($this->il_lng->txt("objs_prg"));
88  }
89 
90  public function getHTML()
91  {
92  // TODO: This should be determined from somewhere up in the hierarchy, as
93  // this will lead to problems, when e.g. a command changes. But i don't see
94  // how atm...
95  if (!$this->shouldShowThisList()) {
96  return "";
97  }
98 
99  if (!$this->userHasReadableStudyProgrammes()) {
100  return "";
101  }
102  return parent::getHTML();
103  }
104 
105  public function getDataSectionContent()
106  {
107  $content = "";
108  foreach ($this->users_assignments as $assignment) {
109  if (!$this->isReadable($assignment)) {
110  continue;
111  }
112 
113  try {
114  $list_item = $this->new_ilStudyProgrammeAssignmentListGUI($assignment);
115  $list_item->setShowInfoMessage($this->show_info_message);
116  $list_item->setVisibleOnPDMode($this->visible_on_pd_mode);
117  $content .= $list_item->getHTML();
119  $this->il_logger->alert("$e");
120  } catch (ilStudyProgrammeTreeException $e) {
121  $this->il_logger->alert("$e");
122  }
123  }
124  return $content;
125  }
126 
130  public function getBlockType() : string
131  {
132  return self::BLOCK_TYPE;
133  }
134 
138  protected function isRepositoryObject() : bool
139  {
140  return false;
141  }
142 
143  public function fillDataSection()
144  {
145  assert($this->userHasReadableStudyProgrammes()); // We should not get here.
146  $this->tpl->setVariable("BLOCK_ROW", $this->getDataSectionContent());
147  }
148 
149 
150  protected function userHasVisibleStudyProgrammes()
151  {
152  if (count($this->users_assignments) == 0) {
153  return false;
154  }
155  foreach ($this->users_assignments as $assignment) {
156  if ($this->isVisible($assignment)) {
157  return true;
158  }
159  }
160  return false;
161  }
162 
163  protected function userHasReadableStudyProgrammes()
164  {
165  if (count($this->users_assignments) == 0) {
166  return false;
167  }
168  foreach ($this->users_assignments as $assignment) {
169  if ($this->isReadable($assignment)) {
170  return true;
171  }
172  }
173  return false;
174  }
175 
176  protected function readVisibleOnPDMode()
177  {
178  $this->visible_on_pd_mode = $this->il_setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
179  }
180 
181  protected function hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
182  {
183  $prg = $assignment->getStudyProgramme();
184  return $this->il_access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
185  }
186 
187  protected function readToShowInfoMessage()
188  {
189  require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockViewSettings.php';
190  $viewSettings = new ilPDSelectedItemsBlockViewSettings($GLOBALS['DIC']->user(), (int) $_GET['view']);
191  $this->show_info_message = $viewSettings->isStudyProgrammeViewActive();
192  }
193 
194  protected function isVisible(ilStudyProgrammeUserAssignment $assignment)
195  {
196  return $this->hasPermission($assignment, "visible");
197  }
198 
199  protected function isReadable(ilStudyProgrammeUserAssignment $assignment)
200  {
201  if ($this->visible_on_pd_mode == ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
202  return true;
203  }
204 
205  return $this->hasPermission($assignment, "read");
206  }
207 
208  protected function shouldShowThisList()
209  {
210  global $DIC;
211  $ctrl = $DIC->ctrl();
212  return ($_GET["cmd"] == "jumpToSelectedItems" ||
213  ($ctrl->getCmdClass() == "ilpersonaldesktopgui" && $ctrl->getCmd() == "show")
214  ) && !$_GET["expand"];
215  }
216 
217  protected function readUsersAssignments()
218  {
219  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
220  $this->users_assignments = ilStudyProgrammeUserAssignment::getInstancesOfUser($this->il_user->getId());
221  }
222 
224  {
225  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeProgressListGUI.php");
226  $progress = $a_assignment->getStudyProgramme()->getProgressForAssignment($a_assignment->getId());
227  $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
228  $progress_gui->setOnlyRelevant(true);
229  return $progress_gui;
230  }
231 }
isReadable(ilStudyProgrammeUserAssignment $assignment)
global $DIC
Definition: saml.php:7
$_GET["client_id"]
getStudyProgramme()
Get the program node where this assignment was made.
Exception is thrown when a progress for some programme node and assignment is missing.
user()
Definition: user.php:4
isVisible(ilStudyProgrammeUserAssignment $assignment)
setTitle($a_title)
Set Title.
Class ilPDSelectedItemsBlockViewSettings.
$ilUser
Definition: imgupload.php:18
Personal Desktop-Presentation for the Study Programme.
hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
global $ilSetting
Definition: privfeed.php:17
Class ilStudyProgrammeProgressListGUI.
static getInstancesOfUser($a_user_id)
Get all instances for a given user.
This class represents a block method of a block.
static getLogger($a_component_id)
Get component logger.
new_ilStudyProgrammeAssignmentListGUI(ilStudyProgrammeUserAssignment $a_assignment)
Exception is thrown when invariants on the program tree would be violated by manipulation of tree...
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Represents one assignment of a user to a study programme.