ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5require_once("Services/Block/classes/class.ilBlockGUI.php");
6require_once('./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeAdmin.php');
7require_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
44
49
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
127 public static function getBlockType()
128 {
129 return self::BLOCK_TYPE;
130 }
131
132 public static function isRepositoryObject()
133 {
134 return false;
135 }
136
137 public function fillDataSection()
138 {
139 assert($this->userHasReadableStudyProgrammes()); // We should not get here.
140 $this->tpl->setVariable("BLOCK_ROW", $this->getDataSectionContent());
141 }
142
143
144 protected function userHasVisibleStudyProgrammes()
145 {
146 if (count($this->users_assignments) == 0) {
147 return false;
148 }
149 foreach ($this->users_assignments as $assignment) {
150 if ($this->isVisible($assignment)) {
151 return true;
152 }
153 }
154 return false;
155 }
156
158 {
159 if (count($this->users_assignments) == 0) {
160 return false;
161 }
162 foreach ($this->users_assignments as $assignment) {
163 if ($this->isReadable($assignment)) {
164 return true;
165 }
166 }
167 return false;
168 }
169
170 protected function readVisibleOnPDMode()
171 {
172 $this->visible_on_pd_mode = $this->il_setting->get(ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD);
173 }
174
175 protected function hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
176 {
177 $prg = $assignment->getStudyProgramme();
178 return $this->il_access->checkAccess($permission, "", $prg->getRefId(), "prg", $prg->getId());
179 }
180
181 protected function readToShowInfoMessage()
182 {
183 require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockViewSettings.php';
184 $viewSettings = new ilPDSelectedItemsBlockViewSettings($GLOBALS['DIC']->user(), (int) $_GET['view']);
185 $this->show_info_message = $viewSettings->isStudyProgrammeViewActive();
186 }
187
188 protected function isVisible(ilStudyProgrammeUserAssignment $assignment)
189 {
190 return $this->hasPermission($assignment, "visible");
191 }
192
193 protected function isReadable(ilStudyProgrammeUserAssignment $assignment)
194 {
195 if ($this->visible_on_pd_mode == ilObjStudyProgrammeAdmin::SETTING_VISIBLE_ON_PD_ALLWAYS) {
196 return true;
197 }
198
199 return $this->hasPermission($assignment, "read");
200 }
201
202 protected function shouldShowThisList()
203 {
204 global $DIC;
205 $ctrl = $DIC->ctrl();
206 return ($_GET["cmd"] == "jumpToSelectedItems" ||
207 ($ctrl->getCmdClass() == "ilpersonaldesktopgui" && $ctrl->getCmd() == "show")
208 ) && !$_GET["expand"];
209 }
210
211 protected function readUsersAssignments()
212 {
213 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
214 $this->users_assignments = ilStudyProgrammeUserAssignment::getInstancesOfUser($this->il_user->getId());
215 }
216
218 {
219 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeProgressListGUI.php");
220 $progress = $a_assignment->getStudyProgramme()->getProgressForAssignment($a_assignment->getId());
221 $progress_gui = new ilStudyProgrammeProgressListGUI($progress);
222 $progress_gui->setOnlyRelevant(true);
223 return $progress_gui;
224 }
225}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a block method of a block.
setTitle($a_title)
Set Title.
static getLogger($a_component_id)
Get component logger.
Personal Desktop-Presentation for the Study Programme.
hasPermission(ilStudyProgrammeUserAssignment $assignment, $permission)
fillDataSection()
Standard implementation for row based data.
isReadable(ilStudyProgrammeUserAssignment $assignment)
isVisible(ilStudyProgrammeUserAssignment $assignment)
new_ilStudyProgrammeAssignmentListGUI(ilStudyProgrammeUserAssignment $a_assignment)
Exception is thrown when a progress for some programme node and assignment is missing.
Class ilStudyProgrammeProgressListGUI.
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.
getStudyProgramme()
Get the program node where this assignment was made.
static getInstancesOfUser($a_user_id)
Get all instances for a given user.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18