ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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/classes/class.ilPDSelectedItemsBlockGUI.php';
8 
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  global $DIC;
56  $lng = $DIC['lng'];
57  $ilUser = $DIC['ilUser'];
58  $ilAccess = $DIC['ilAccess'];
59  $ilSetting = $DIC['ilSetting'];
60  $this->il_lng = $lng;
61  $this->il_user = $ilUser;
62  $this->il_access = $ilAccess;
63  $this->il_setting = $ilSetting;
64  $this->il_logger = ilLoggerFactory::getLogger('prg');
65 
66  // No need to load data, as we won't display this.
67  if (!$this->shouldShowThisList()) {
68  return;
69  }
70 
71  $this->readUsersAssignments();
72  //check which kind of option is selected in settings
73  $this->readVisibleOnPDMode();
74  //check to display info message if option "read" is selected
75  $this->readToShowInfoMessage();
76 
77  // As this won't be visible we don't have to initialize this.
78  if (!$this->userHasReadableStudyProgrammes()) {
79  return;
80  }
81 
82  $this->setTitle($this->il_lng->txt("objs_prg"));
83  }
84 
85  public function getHTML() {
86  // TODO: This should be determined from somewhere up in the hierarchy, as
87  // this will lead to problems, when e.g. a command changes. But i don't see
88  // how atm...
89  if (!$this->shouldShowThisList()) {
90  return "";
91  }
92 
93  if (!$this->userHasReadableStudyProgrammes()) {
94  return "";
95  }
96  return parent::getHTML();
97  }
98 
99  public function getDataSectionContent() {
100  $content = "";
101  foreach ($this->users_assignments as $assignment) {
102  if(!$this->isReadable($assignment)) {
103  continue;
104  }
105 
106  try {
107  $list_item = $this->new_ilStudyProgrammeAssignmentListGUI($assignment);
108  $list_item->setShowInfoMessage($this->show_info_message);
109  $list_item->setVisibleOnPDMode($this->visible_on_pd_mode);
110  $content .= $list_item->getHTML();
111  }
113  $this->il_logger->alert("$e");
114  }
116  $this->il_logger->alert("$e");
117  }
118  }
119  return $content;
120  }
121 
122  static public function getBlockType() {
123  return self::BLOCK_TYPE;
124  }
125 
126  static public function isRepositoryObject() {
127  return false;
128  }
129 
130  public function fillDataSection() {
131  assert($this->userHasReadableStudyProgrammes()); // We should not get here.
132  $this->tpl->setVariable("BLOCK_ROW", $this->getDataSectionContent());
133  }
134 
135 
136  protected function userHasVisibleStudyProgrammes() {
137  if (count($this->users_assignments) == 0) {
138  return false;
139  }
140  foreach ($this->users_assignments as $assignment) {
141  if ($this->isVisible($assignment)) {
142  return true;
143  }
144  }
145  return false;
146  }
147 
148  protected function userHasReadableStudyProgrammes() {
149  if (count($this->users_assignments) == 0) {
150  return false;
151  }
152  foreach ($this->users_assignments as $assignment) {
153  if ($this->isReadable($assignment)) {
154  return true;
155  }
156  }
157  return false;
158  }
159 
160  protected function readVisibleOnPDMode() {
161  $this->visible_on_pd_mode = $this->il_setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
162  }
163 
164  protected function hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission) {
165  $prg = $assignment->getStudyProgramme();
166  return $this->il_access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
167  }
168 
169  protected function readToShowInfoMessage() {
170  $this->show_info_message = ($_GET['view'] == ilPDSelectedItemsBlockGUI::VIEW_MY_STUDYPROGRAMME);
171  }
172 
173  protected function isVisible(ilStudyProgrammeUserAssignment $assignment) {
174  return $this->hasPermission($assignment,"visible");
175  }
176 
177  protected function isReadable(ilStudyProgrammeUserAssignment $assignment) {
178  if($this->visible_on_pd_mode == ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS){
179  return true;
180  }
181 
182  return $this->hasPermission($assignment,"read");
183  }
184 
185  protected function shouldShowThisList() {
186  global $DIC;
187  $ctrl = $DIC->ctrl();
188  return ($_GET["cmd"] == "jumpToSelectedItems" ||
189  ($ctrl->getCmdClass() == "ilpersonaldesktopgui" && $ctrl->getCmd() == "show")
190  ) && !$_GET["expand"];
191  }
192 
193  protected function readUsersAssignments() {
194  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
195  $this->users_assignments = ilStudyProgrammeUserAssignment::getInstancesOfUser($this->il_user->getId());
196  }
197 
199  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeProgressListGUI.php");
200  $progress = $a_assignment->getStudyProgramme()->getProgressForAssignment($a_assignment->getId());
201  $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
202  $progress_gui->setOnlyRelevant(true);
203  return $progress_gui;
204  }
205 }
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.
isVisible(ilStudyProgrammeUserAssignment $assignment)
setTitle($a_title)
Set Title.
$ilUser
Definition: imgupload.php:18
Personal Desktop-Presentation for the Study Programme.
hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
global $ilSetting
Definition: privfeed.php:17
global $lng
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.
global $DIC
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.