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