ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
16 {
17  const BLOCK_TYPE = "prgsimplelist";
18 
22  protected $il_lng;
23 
27  protected $il_user;
28 
32  protected $il_access;
33 
37  protected $il_setting;
38 
42  protected $users_assignments;
43 
48 
52  protected $show_info_message;
53 
54  public function __construct()
55  {
56  global $DIC;
57 
59 
60  $lng = $DIC['lng'];
61  $ilUser = $DIC['ilUser'];
62  $ilAccess = $DIC['ilAccess'];
63  $ilSetting = $DIC['ilSetting'];
64  $this->il_lng = $lng;
65  $this->il_user = $ilUser;
66  $this->il_access = $ilAccess;
67  $this->il_setting = $ilSetting;
68  $this->il_logger = ilLoggerFactory::getLogger('prg');
69 
70  $this->sp_user_assignment_db = ilStudyProgrammeDIC::dic()['ilStudyProgrammeUserAssignmentDB'];
71 
72  // No need to load data, as we won't display this.
73  if (!$this->shouldShowThisList()) {
74  return;
75  }
76 
77  $this->readUsersAssignments();
78  //check which kind of option is selected in settings
79  $this->readVisibleOnPDMode();
80  //check to display info message if option "read" is selected
81  $this->readToShowInfoMessage();
82 
83  // As this won't be visible we don't have to initialize this.
84  if (!$this->userHasReadableStudyProgrammes()) {
85  return;
86  }
87 
88  $this->setTitle($this->il_lng->txt("objs_prg"));
89  }
90 
91  public function getHTML()
92  {
93  // TODO: This should be determined from somewhere up in the hierarchy, as
94  // this will lead to problems, when e.g. a command changes. But i don't see
95  // how atm...
96  if (!$this->shouldShowThisList()) {
97  return "";
98  }
99 
100  if (!$this->userHasReadableStudyProgrammes()) {
101  return "";
102  }
103  return parent::getHTML();
104  }
105 
106  public function getDataSectionContent()
107  {
108  $content = "";
109  foreach ($this->users_assignments as $assignment) {
110  if (!$this->isReadable($assignment)) {
111  continue;
112  }
113 
114  try {
115  $list_item = $this->new_ilStudyProgrammeAssignmentListGUI($assignment);
116  $list_item->setShowInfoMessage($this->show_info_message);
117  $list_item->setVisibleOnPDMode($this->visible_on_pd_mode);
118  $content .= $list_item->getHTML();
120  $this->il_logger->alert("$e");
121  } catch (ilStudyProgrammeTreeException $e) {
122  $this->il_logger->alert("$e");
123  }
124  }
125  return $content;
126  }
127 
131  public function getBlockType() : string
132  {
133  return self::BLOCK_TYPE;
134  }
135 
139  protected function isRepositoryObject() : bool
140  {
141  return false;
142  }
143 
144  public function fillDataSection()
145  {
146  assert($this->userHasReadableStudyProgrammes()); // We should not get here.
147  $this->tpl->setVariable("BLOCK_ROW", $this->getDataSectionContent());
148  }
149 
150 
151  protected function userHasVisibleStudyProgrammes()
152  {
153  if (count($this->users_assignments) == 0) {
154  return false;
155  }
156  foreach ($this->users_assignments as $assignment) {
157  if ($this->isVisible($assignment)) {
158  return true;
159  }
160  }
161  return false;
162  }
163 
164  protected function userHasReadableStudyProgrammes()
165  {
166  if (count($this->users_assignments) == 0) {
167  return false;
168  }
169  foreach ($this->users_assignments as $assignment) {
170  if ($this->isReadable($assignment)) {
171  return true;
172  }
173  }
174  return false;
175  }
176 
177  protected function readVisibleOnPDMode()
178  {
179  $this->visible_on_pd_mode = $this->il_setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
180  }
181 
182  protected function hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
183  {
184  $prg = $assignment->getStudyProgramme();
185  return $this->il_access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
186  }
187 
188  protected function readToShowInfoMessage()
189  {
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() == "ildashboardgui" && $ctrl->getCmd() == "show")
214  ) && !$_GET["expand"];
215  }
216 
217  protected function readUsersAssignments()
218  {
219  $this->users_assignments = $this->sp_user_assignment_db->getInstancesOfUser($this->il_user->getId());
220  }
221 
223  {
224  $progress = $a_assignment->getStudyProgramme()->getProgressForAssignment($a_assignment->getId());
225  $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
226  $progress_gui->setOnlyRelevant(true);
227  return $progress_gui;
228  }
229 }
isReadable(ilStudyProgrammeUserAssignment $assignment)
$_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.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$ilUser
Definition: imgupload.php:18
Personal Desktop-Presentation for the Study Programme.
hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
$DIC
Definition: xapitoken.php:46
Class ilStudyProgrammeProgressListGUI.
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...
Represents one assignment of a user to a study programme.