ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjStudyProgrammeIndividualPlanGUI.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
13{
17 public $ctrl;
18
22 public $tpl;
23
27 protected $ilAccess;
28
32 public $object;
33
37 protected $ilLog;
38
42 public $ilias;
43
47 public $lng;
48
52 public $toolbar;
53
57 public $user;
58
59 protected $parent_gui;
60
65
66 public function __construct($a_parent_gui, $a_ref_id, ilStudyProgrammeUserProgressDB $sp_user_progress_db)
67 {
68 global $DIC;
69 $tpl = $DIC['tpl'];
70 $ilCtrl = $DIC['ilCtrl'];
71 $ilAccess = $DIC['ilAccess'];
72 $ilToolbar = $DIC['ilToolbar'];
73 $ilLocator = $DIC['ilLocator'];
74 $tree = $DIC['tree'];
75 $lng = $DIC['lng'];
76 $ilLog = $DIC['ilLog'];
77 $ilias = $DIC['ilias'];
78 $ilUser = $DIC['ilUser'];
79
80 $this->ref_id = $a_ref_id;
81 $this->parent_gui = $a_parent_gui;
82 $this->tpl = $tpl;
83 $this->ctrl = $ilCtrl;
84 $this->ilAccess = $ilAccess;
85 $this->ilLocator = $ilLocator;
86 $this->tree = $tree;
87 $this->toolbar = $ilToolbar;
88 $this->ilLog = $ilLog;
89 $this->ilias = $ilias;
90 $this->lng = $lng;
91 $this->user = $ilUser;
92 $this->assignment_object = null;
93 $this->sp_user_progress_db = $sp_user_progress_db;
94
95 $this->object = null;
96
97 $lng->loadLanguageModule("prg");
98
99 $this->tpl->addCss("Modules/StudyProgramme/templates/css/ilStudyProgramme.css");
100 }
101
102 public function executeCommand()
103 {
104 $cmd = $this->ctrl->getCmd();
105
106 if ($cmd == "") {
107 $cmd = "view";
108 }
109
110 switch ($cmd) {
111 case "view":
112 case "manage":
113 case "updateFromCurrentPlan":
114 case "updateFromInput":
115 $cont = $this->$cmd();
116 break;
117 default:
118 throw new ilException("ilObjStudyProgrammeMembersGUI: " .
119 "Command not supported: $cmd");
120 }
121
122 $this->tpl->setContent($cont);
123 }
124
125 protected function getAssignmentId()
126 {
127 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
128 if (!is_numeric($_GET["ass_id"])) {
129 throw new ilException("Expected integer 'ass_id'");
130 }
131 return (int) $_GET["ass_id"];
132 }
133
134 protected function getAssignmentObject()
135 {
136 if ($this->assignment_object === null) {
137 $id = $this->getAssignmentId();
138 $this->assignment_object = ilStudyProgrammeUserAssignment::getInstance($id);
139 }
140 return $this->assignment_object;
141 }
142
143 protected function view()
144 {
145 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeIndividualPlanProgressListGUI.php");
146 $gui = new ilStudyProgrammeIndividualPlanProgressListGUI($this->getAssignmentObject()->getRootProgress());
147 $gui->setOnlyRelevant(true);
148 // Wrap a frame around the original gui element to correct rendering.
149 $tpl = new ilTemplate("tpl.individual_plan_tree_frame.html", false, false, "Modules/StudyProgramme");
150 $tpl->setVariable("CONTENT", $gui->getHTML());
151 return $this->buildFrame("view", $tpl->get());
152 }
153
154 protected function manage()
155 {
156 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeIndividualPlanTableGUI.php");
157 $ass = $this->getAssignmentObject();
158 $this->ctrl->setParameter($this, "ass_id", $ass->getId());
159 $this->ctrl->setParameter($this, "cmd", "manage");
160 $table = new ilStudyProgrammeIndividualPlanTableGUI($this, $ass, $this->sp_user_progress_db);
161 $frame = $this->buildFrame("manage", $table->getHTML());
162 $this->ctrl->setParameter($this, "ass_id", null);
163 return $frame;
164 }
165
166 protected function updateFromCurrentPlan()
167 {
168 $ass = $this->getAssignmentObject();
169 $ass->updateFromProgram();
170 $this->ctrl->setParameter($this, "ass_id", $ass->getId());
171 $this->showSuccessMessage("update_from_plan_successful");
172 $this->ctrl->redirect($this, "manage");
173 }
174
175 protected function updateFromInput()
176 {
177 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
178
179 $changed = false;
180
181 $changed = $this->updateStatus();
182
183 $this->ctrl->setParameter($this, "ass_id", $this->getAssignmentId());
184 if ($changed) {
185 $this->showSuccessMessage("update_successful");
186 }
187 $this->ctrl->redirect($this, "manage");
188 }
189
190 protected function updateStatus()
191 {
192 $status_updates = $this->getManualStatusUpdates();
193 $changed = false;
194 foreach ($status_updates as $prgrs_id => $status) {
195 $prgrs = $this->sp_user_progress_db->getInstanceById($prgrs_id);
196 $cur_status = $prgrs->getStatus();
197
198 if ($status == self::MANUAL_STATUS_NONE && $cur_status == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
199 $prgrs->unmarkAccredited($this->user->getId());
200 $changed = true;
201 } elseif ($status == self::MANUAL_STATUS_NONE && $cur_status == ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
202 $prgrs->markRelevant($this->user->getId());
203 $changed = true;
204 } elseif ($status == self::MANUAL_STATUS_NOT_RELEVANT && $cur_status != ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
205 $prgrs->markNotRelevant($this->user->getId());
206 $changed = true;
207 } elseif ($status == self::MANUAL_STATUS_ACCREDITED && $cur_status != ilStudyProgrammeProgress::STATUS_ACCREDITED) {
208 $prgrs->markAccredited($this->user->getId());
209 $changed = true;
210 }
211
212 $deadline = null;
213 if ($this->postContainDeadline()) {
214 $deadline = $this->updateDeadline($prgrs);
215 }
216
218 $changed = $this->updateRequiredPoints($prgrs_id) || $changed;
219
220 if ($deadline !== null && $deadline->get(IL_CAL_DATE) < date("Y-m-d")) {
221 $prgrs->markFailed($this->user->getId());
222 }
223 } elseif ($cur_status == ilStudyProgrammeProgress::STATUS_FAILED) {
224 if ($deadline === null || $deadline->get(IL_CAL_DATE) > date("Y-m-d")) {
225 $prgrs->markNotFailed($this->user->getId());
226 }
227 }
228 }
229 return $changed;
230 }
231
240 {
241 $deadline = $this->getDeadlineFromForm($prgrs->getId());
242 $prgrs->setDeadline($deadline);
243 $prgrs->updateProgress($this->user->getId());
244
245 return $deadline;
246 }
247
248 protected function updateRequiredPoints($prgrs_id)
249 {
250 $required_points = $this->getRequiredPointsUpdates($prgrs_id);
251 $changed = false;
252
253 $prgrs = $this->sp_user_progress_db->getInstanceById($prgrs_id);
254 $cur_status = $prgrs->getStatus();
256 return false;
257 }
258
259 if ($required_points < 0) {
260 $required_points = 0;
261 }
262
263 if ($required_points == $prgrs->getAmountOfPoints()) {
264 return false;
265 }
266
267 $prgrs->setRequiredAmountOfPoints($required_points, $this->user->getId());
268 return true;
269 }
270
278 protected function getDeadlineFromForm($prgrs_id)
279 {
280 $post_var = $this->getDeadlinePostVarTitle();
281 if (!$this->postContainDeadline()) {
282 throw new ilException("Expected array $post_var in POST");
283 }
284
285 $post_value = $_POST[$post_var];
286 $deadline = $post_value[$prgrs_id];
287
288 if ($deadline == "") {
289 return null;
290 }
291
292 return new ilDateTime($deadline, IL_CAL_DATE);
293 }
294
300 protected function postContainDeadline()
301 {
302 $post_var = $this->getDeadlinePostVarTitle();
303 if (array_key_exists($post_var, $_POST)) {
304 return true;
305 }
306 return false;
307 }
308
309 protected function showSuccessMessage($a_lng_var)
310 {
311 require_once("Services/Utilities/classes/class.ilUtil.php");
312 ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
313 }
314
315 protected function getManualStatusUpdates()
316 {
317 $post_var = $this->getManualStatusPostVarTitle();
318 if (!array_key_exists($post_var, $_POST)) {
319 throw new ilException("Expected array $post_var in POST");
320 }
321 return $_POST[$post_var];
322 }
323
324 protected function getRequiredPointsUpdates($prgrs_id)
325 {
326 $post_var = $this->getRequiredPointsPostVarTitle();
327 if (!array_key_exists($post_var, $_POST)) {
328 throw new ilException("Expected array $post_var in POST");
329 }
330
331 $post_value = $_POST[$post_var];
332 return (int) $post_value[$prgrs_id];
333 }
334
335
336 protected function buildFrame($tab, $content)
337 {
338 $tpl = new ilTemplate("tpl.indivdual_plan_frame.html", true, true, "Modules/StudyProgramme");
339 $ass = $this->getAssignmentObject();
340
341 $tpl->setVariable("USERNAME", ilObjUser::_lookupFullname($ass->getUserId()));
342 foreach (array("view", "manage") as $_tab) {
343 $tpl->setCurrentBlock("sub_tab");
344 $tpl->setVariable("CLASS", $_tab == $tab ? "active" : "");
345 $tpl->setVariable("LINK", $this->getLinkTargetForSubTab($_tab, $ass->getId()));
346 $tpl->setVariable("TITLE", $this->lng->txt("prg_$_tab"));
347 $tpl->parseCurrentBlock();
348 }
349 $tpl->setVariable("CONTENT", $content);
350
351 return $tpl->get();
352 }
353
354 protected function getLinkTargetForSubTab($a_tab, $a_ass_id)
355 {
356 $this->ctrl->setParameter($this, "ass_id", $a_ass_id);
357 $lnk = $this->ctrl->getLinkTarget($this, $a_tab);
358 $this->ctrl->setParameter($this, "ass_id", null);
359 return $lnk;
360 }
361
362 public function appendIndividualPlanActions(ilTable2GUI $a_table)
363 {
364 $a_table->setFormAction($this->ctrl->getFormAction($this));
365 $a_table->addCommandButton("updateFromCurrentPlan", $this->lng->txt("prg_update_from_current_plan"));
366 $a_table->addCommandButton("updateFromInput", $this->lng->txt("save"));
367 }
368
369 const POST_VAR_STATUS = "status";
370 const POST_VAR_REQUIRED_POINTS = "required_points";
371 const POST_VAR_DEADLINE = "deadline";
375
377 {
379 }
380
382 {
384 }
385
386 public function getDeadlinePostVarTitle()
387 {
389 }
390
391 public function getManualStatusNone()
392 {
394 }
395
397 {
399 }
400
402 {
404 }
405
406 public static function getLinkTargetView($ctrl, $a_ass_id)
407 {
408 $cl = "ilObjStudyProgrammeIndividualPlanGUI";
409 $ctrl->setParameterByClass($cl, "ass_id", $a_ass_id);
410 $link = $ctrl->getLinkTargetByClass($cl, "view");
411 $ctrl->setParameterByClass($cl, "ass_id", null);
412 return $link;
413 }
414}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
Class ilAccessHandler.
@classDescription Date and time handling
Base class for ILIAS Exception handling.
logging
Definition: class.ilLog.php:19
updateDeadline(ilStudyProgrammeUserProgress $prgrs)
Updates current deadline.
__construct($a_parent_gui, $a_ref_id, ilStudyProgrammeUserProgressDB $sp_user_progress_db)
postContainDeadline()
Checks whether $_POST contains deadline.
static _lookupFullname($a_user_id)
Lookup Full Name.
Storage implementation for ilStudyProgrammeUserProgress.
Represents the progress of a user at one node of a study programme.
updateProgress($user_id)
Updates current progress.
setDeadline($deadline)
Set the deadline of this node.
Class ilTable2GUI.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
special template class to simplify handling of ITX/PEAR
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
if(empty($password)) $table
Definition: pwgen.php:24
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18