ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjStudyProgrammeMembersGUI.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
20 public $ctrl;
21
25 public $tpl;
26
30 protected $ilAccess;
31
35 public $object;
36
40 protected $ilLog;
41
45 public $ilias;
46
50 public $lng;
51
55 public $toolbar;
56
60 public $user;
61
62 protected $parent_gui;
63
64 public function __construct($a_parent_gui, $a_ref_id) {
65 global $DIC;
66 $tpl = $DIC['tpl'];
67 $ilCtrl = $DIC['ilCtrl'];
68 $ilAccess = $DIC['ilAccess'];
69 $ilToolbar = $DIC['ilToolbar'];
70 $ilLocator = $DIC['ilLocator'];
71 $tree = $DIC['tree'];
72 $lng = $DIC['lng'];
73 $ilLog = $DIC['ilLog'];
74 $ilias = $DIC['ilias'];
75 $ilUser = $DIC['ilUser'];
76
77 $this->ref_id = $a_ref_id;
78 $this->parent_gui = $a_parent_gui;
79 $this->tpl = $tpl;
80 $this->ctrl = $ilCtrl;
81 $this->ilAccess = $ilAccess;
82 $this->ilLocator = $ilLocator;
83 $this->tree = $tree;
84 $this->toolbar = $ilToolbar;
85 $this->ilLog = $ilLog;
86 $this->ilias = $ilias;
87 $this->lng = $lng;
88 $this->user = $ilUser;
89 $this->progress_object = null;
90
91 $this->object = null;
92
93 $lng->loadLanguageModule("prg");
94 }
95
96 public function executeCommand() {
97 $cmd = $this->ctrl->getCmd();
98 $next_class = $this->ctrl->getNextClass($this);
99
100
101 if ($cmd == "") {
102 $cmd = "view";
103 }
104
105 # TODO: Check permission of user!!
106
107 switch ($next_class) {
108 case "ilstudyprogrammerepositorysearchgui":
109 require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
110 $rep_search = new ilStudyProgrammeRepositorySearchGUI();
111 $rep_search->setCallback($this, "addUsers");
112
113 $this->ctrl->setReturn($this, "view");
114 $this->ctrl->forwardCommand($rep_search);
115 return;
116 case "ilobjstudyprogrammeindividualplangui":
117 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
118 $individual_plan_gui = new ilObjStudyProgrammeIndividualPlanGUI( $this, $this->ref_id);
119 $this->ctrl->forwardCommand($individual_plan_gui);
120 return;
121 case false:
122 switch ($cmd) {
123 case "view":
124 case "markAccredited":
125 case "unmarkAccredited":
126 case "removeUser":
127 case "addUsersWithAcknowledgedCourses":
128 $cont = $this->$cmd();
129 break;
130 default:
131 throw new ilException("ilObjStudyProgrammeMembersGUI: ".
132 "Command not supported: $cmd");
133 }
134 break;
135 default:
136 throw new ilException("ilObjStudyProgrammeMembersGUI: Can't forward to next class $next_class");
137 }
138
139 $this->tpl->setContent($cont);
140 }
141
142 protected function view() {
143 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeMembersTableGUI.php");
144
145 if ($this->getStudyProgramme()->isActive()) {
146 $this->initSearchGUI();
147 }
148
149 if (!$this->getStudyProgramme()->isActive()) {
150 ilUtil::sendInfo($this->lng->txt("prg_no_members_not_active"));
151 }
152
153 $prg_id = ilObject::_lookupObjId($this->ref_id);
154 $table = new ilStudyProgrammeMembersTableGUI($prg_id, $this->ref_id, $this, "view");
155 return $table->getHTML();
156 }
157
158 public function addUsers($a_users) {
159 $prg = $this->getStudyProgramme();
160
161 $completed_courses = array();
162
163 foreach ($a_users as $user_id) {
164 $completed_crss = $prg->getCompletedCourses($user_id);
165 if ($completed_crss) {
166 $completed_courses[$user_id] = $completed_crss;
167 }
168 }
169
170 if (count($completed_courses) > 0) {
171 $this->viewCompletedCourses($completed_courses, $a_users);
172 return true;
173 }
174
175 $this->_addUsers($a_users);
176
177 $this->ctrl->redirect($this, "view");
178 }
179
180 public function viewCompletedCourses($a_completed_courses, $a_users) {
181 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI.php");
182
183 $tpl = new ilTemplate("tpl.acknowledge_completed_courses.html", true, true, "Modules/StudyProgramme");
184 $tpl->setVariable("TITLE", $this->lng->txt("prg_acknowledge_completed_courses"));
185 $tpl->setVariable("CAPTION_ADD", $this->lng->txt("btn_next"));
186 $tpl->setVariable("CAPTION_CANCEL", $this->lng->txt("cancel"));
187 $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
188 $tpl->setVariable("ADD_CMD", "addUsersWithAcknowledgedCourses");
189 $tpl->setVariable("CANCEL_CMD", "view");
190
191 foreach ($a_completed_courses as $user_id => $completed_courses) {
192 $names = ilObjUser::_lookupName($user_id);
193 $tpl->setCurrentBlock("usr_section");
194 $tpl->setVariable("FIRSTNAME", $names["firstname"]);
195 $tpl->setVariable("LASTNAME", $names["lastname"]);
196 $table = new ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI($this, $user_id, $completed_courses);
197 $tpl->setVariable("TABLE", $table->getHTML());
198 $tpl->parseCurrentBlock();
199 }
200
201 foreach ($a_users as $usr_id) {
202 $tpl->setCurrentBlock("usr_ids_section");
203 $tpl->setVariable("USR_ID", $usr_id);
204 $tpl->parseCurrentBlock();
205 }
206
207 $this->tpl->setContent($tpl->get());
208 }
209
211 $users = $_POST["users"];
212 $assignments = $this->_addUsers($users);
213
214 $completed_programmes = $_POST["courses"];
215 foreach ($completed_programmes as $user_id => $prg_ref_ids) {
216 $ass_id = $assignments[$user_id]->getId();
217 foreach ($prg_ref_ids as $ids) {
218 list($prg_ref_id, $crs_id, $crsr_id) = explode(";", $ids);
219 $prg = $this->getStudyProgramme($prg_ref_id);
220 $progress = $prg->getProgressForAssignment($ass_id);
221 $progress->setLPCompleted($crsr_id, $user_id);
222 }
223 }
224
225 $this->ctrl->redirect($this, "view");
226 }
227
228 protected function _addUsers($a_users) {
229 $prg = $this->getStudyProgramme();
230
231 $assignments = array();
232
233 foreach ($a_users as $user_id) {
234 $assignments[$user_id] = $prg->assignUser($user_id);
235 }
236
237 if (count($a_users) == 1) {
238 ilUtil::sendSuccess($this->lng->txt("prg_added_member"), true);
239 }
240 if (count($a_users) > 1) {
241 ilUtil::sendSuccess($this->lng->txt("prg_added_members"), true);
242 }
243
244 return $assignments;
245 }
246
247 public function markAccredited() {
248 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
249 $prgrs = $this->getProgressObject();
250 $prgrs->markAccredited($this->user->getId());
251 $this->showSuccessMessage("mark_accredited_success");
252 $this->ctrl->redirect($this, "view");
253 }
254
255 public function unmarkAccredited() {
256 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
257 $prgrs = $this->getProgressObject();
258 $prgrs->unmarkAccredited();
259 $this->showSuccessMessage("unmark_accredited_success");
260 $this->ctrl->redirect($this, "view");
261 }
262
263 public function removeUser() {
264 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
265 $prgrs = $this->getProgressObject();
266 $ass = $prgrs->getAssignment();
267 $prg = $ass->getStudyProgramme();
268 if ($prg->getRefId() != $this->ref_id) {
269 throw new ilException("Can only remove users from the node they where assigned to.");
270 }
271 $ass->deassign();
272 $this->showSuccessMessage("remove_user_success");
273 $this->ctrl->redirect($this, "view");
274 }
275
276 protected function getProgressObject() {
277 if ($this->progress_object === null) {
278 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
279 if (!is_numeric($_GET["prgrs_id"])) {
280 throw new ilException("Expected integer 'prgrs_id'");
281 }
282 $id = (int)$_GET["prgrs_id"];
283 $this->progress_object = ilStudyProgrammeUserProgress::getInstanceById($id);
284 }
285 return $this->progress_object;
286 }
287
288 protected function showSuccessMessage($a_lng_var) {
289 require_once("Services/Utilities/classes/class.ilUtil.php");
290 ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
291 }
292
293 protected function initSearchGUI() {
294 require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
296 $this,
297 $this->toolbar,
298 array(
299 "auto_complete_name" => $this->lng->txt("user"),
300 "submit_name" => $this->lng->txt("add"),
301 "add_search" => true
302 )
303 );
304 }
305
306 public function getStudyProgramme($a_ref_id = null) {
307 if ($a_ref_id === null) {
308 $a_ref_id = $this->ref_id;
309 }
310 require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
312 }
313
322 public function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id) {
323 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
324
325 switch ($a_action) {
327 $target_name = "markAccredited";
328 break;
330 $target_name = "unmarkAccredited";
331 break;
333 require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
334 return ilObjStudyProgrammeIndividualPlanGUI::getLinkTargetView($this->ctrl, $a_ass_id);
336 $target_name = "removeUser";
337 break;
338 default:
339 throw new ilException("Unknown action: $action");
340 }
341
342 $this->ctrl->setParameter($this, "prgrs_id", $a_prgrs_id);
343 $link = $this->ctrl->getLinkTarget($this, $target_name);
344 $this->ctrl->setParameter($this, "prgrs_id", null);
345 return $link;
346 }
347}
348
349?>
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
logging
Definition: class.ilLog.php:19
Class ilObjStudyProgrammeMembersGUI.
getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
Get the link target for an action on user progress.
viewCompletedCourses($a_completed_courses, $a_users)
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static _lookupName($a_user_id)
lookup user name
static _lookupObjId($a_id)
TableGUI class for acknowledgement of completed courses for new members of a study programme.
Class ilObjStudyProgrammeMembersTableGUI.
Custom repository search gui class for study programme to make it possible to get a handle on users s...
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
This is just the same as in the parent class, except for the hardcoded class name.
static getInstanceById($a_prgrs_id)
Get an instance by progress id.
special template class to simplify handling of ITX/PEAR
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
global $DIC
$ilUser
Definition: imgupload.php:18