ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
16  public $ctrl;
17 
21  public $tpl;
22 
26  protected $ilAccess;
27 
31  public $object;
32 
36  protected $ilLog;
37 
41  public $ilias;
42 
46  public $lng;
47 
51  public $toolbar;
52 
56  public $user;
57 
58  protected $parent_gui;
59 
60  public function __construct($a_parent_gui, $a_ref_id) {
61  global $DIC;
62  $tpl = $DIC['tpl'];
63  $ilCtrl = $DIC['ilCtrl'];
64  $ilAccess = $DIC['ilAccess'];
65  $ilToolbar = $DIC['ilToolbar'];
66  $ilLocator = $DIC['ilLocator'];
67  $tree = $DIC['tree'];
68  $lng = $DIC['lng'];
69  $ilLog = $DIC['ilLog'];
70  $ilias = $DIC['ilias'];
71  $ilUser = $DIC['ilUser'];
72 
73  $this->ref_id = $a_ref_id;
74  $this->parent_gui = $a_parent_gui;
75  $this->tpl = $tpl;
76  $this->ctrl = $ilCtrl;
77  $this->ilAccess = $ilAccess;
78  $this->ilLocator = $ilLocator;
79  $this->tree = $tree;
80  $this->toolbar = $ilToolbar;
81  $this->ilLog = $ilLog;
82  $this->ilias = $ilias;
83  $this->lng = $lng;
84  $this->user = $ilUser;
85  $this->assignment_object = null;
86 
87  $this->object = null;
88 
89  $lng->loadLanguageModule("prg");
90 
91  $this->tpl->addCss("Modules/StudyProgramme/templates/css/ilStudyProgramme.css");
92  }
93 
94  public function executeCommand() {
95  $cmd = $this->ctrl->getCmd();
96 
97  if ($cmd == "") {
98  $cmd = "view";
99  }
100 
101  switch ($cmd) {
102  case "view":
103  case "manage":
104  case "updateFromCurrentPlan":
105  case "updateFromInput":
106  $cont = $this->$cmd();
107  break;
108  default:
109  throw new ilException("ilObjStudyProgrammeMembersGUI: ".
110  "Command not supported: $cmd");
111  }
112 
113  $this->tpl->setContent($cont);
114  }
115 
116  protected function getAssignmentId() {
117  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserAssignment.php");
118  if (!is_numeric($_GET["ass_id"])) {
119  throw new ilException("Expected integer 'ass_id'");
120  }
121  return (int)$_GET["ass_id"];
122  }
123 
124  protected function getAssignmentObject() {
125  if ($this->assignment_object === null) {
126  $id = $this->getAssignmentId();
127  $this->assignment_object = ilStudyProgrammeUserAssignment::getInstance($id);
128  }
129  return $this->assignment_object;
130  }
131 
132  protected function view() {
133  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeIndividualPlanProgressListGUI.php");
134  $gui = new ilStudyProgrammeIndividualPlanProgressListGUI($this->getAssignmentObject()->getRootProgress());
135  $gui->setOnlyRelevant(true);
136  // Wrap a frame around the original gui element to correct rendering.
137  $tpl = new ilTemplate("tpl.individual_plan_tree_frame.html", false, false, "Modules/StudyProgramme");
138  $tpl->setVariable("CONTENT", $gui->getHTML());
139  return $this->buildFrame("view", $tpl->get());
140  }
141 
142  protected function manage() {
143  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeIndividualPlanTableGUI.php");
144  $ass = $this->getAssignmentObject();
145  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
146  $this->ctrl->setParameter($this, "cmd", "manage");
147  $table = new ilStudyProgrammeIndividualPlanTableGUI($this, $ass);
148  $frame = $this->buildFrame("manage", $table->getHTML());
149  $this->ctrl->setParameter($this, "ass_id", null);
150  return $frame;
151  }
152 
153  protected function updateFromCurrentPlan() {
154  $ass = $this->getAssignmentObject();
155  $ass->updateFromProgram();
156  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
157  $this->showSuccessMessage("update_from_plan_successful");
158  $this->ctrl->redirect($this, "manage");
159  }
160 
161  protected function updateFromInput() {
162  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
163 
164  $changed = false;
165 
166  $changed = $this->updateStatus();
167 
168  $this->ctrl->setParameter($this, "ass_id", $this->getAssignmentId());
169  if ($changed) {
170  $this->showSuccessMessage("update_successful");
171  }
172  $this->ctrl->redirect($this, "manage");
173  }
174 
175  protected function updateStatus() {
176  $status_updates = $this->getManualStatusUpdates();
177  $changed = false;
178  foreach ($status_updates as $prgrs_id => $status) {
180  $cur_status = $prgrs->getStatus();
181  if ($status == self::MANUAL_STATUS_NONE && $cur_status == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
182  $prgrs->unmarkAccredited($this->user->getId());
183  $changed = true;
184  }
185  else if ($status == self::MANUAL_STATUS_NONE && $cur_status == ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
186  $prgrs->markRelevant($this->user->getId());
187  $changed = true;
188  }
189  else if($status == self::MANUAL_STATUS_NOT_RELEVANT && $cur_status != ilStudyProgrammeProgress::STATUS_NOT_RELEVANT) {
190  $prgrs->markNotRelevant($this->user->getId());
191  $changed = true;
192  }
193  else if($status == self::MANUAL_STATUS_ACCREDITED && $cur_status != ilStudyProgrammeProgress::STATUS_ACCREDITED) {
194  $prgrs->markAccredited($this->user->getId());
195  $changed = true;
196  }
197 
199  $changed = $this->updateRequiredPoints($prgrs_id) || $changed;
200  }
201  }
202  return $changed;
203  }
204 
205  protected function updateRequiredPoints($prgrs_id) {
206  $required_points = $this->getRequiredPointsUpdates($prgrs_id);
207  $changed = false;
208 
210  $cur_status = $prgrs->getStatus();
212  return false;
213  }
214 
215  if ($required_points < 0) {
216  $required_points = 0;
217  }
218 
219  if ($required_points == $prgrs->getAmountOfPoints()) {
220  return false;
221  }
222 
223  $prgrs->setRequiredAmountOfPoints($required_points, $this->user->getId());
224  return true;
225 
226  }
227 
228  protected function showSuccessMessage($a_lng_var) {
229  require_once("Services/Utilities/classes/class.ilUtil.php");
230  ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
231  }
232 
233  protected function getManualStatusUpdates() {
234  $post_var = $this->getManualStatusPostVarTitle();
235  if (!array_key_exists($post_var, $_POST)) {
236  throw new ilException("Expected array $post_var in POST");
237  }
238  return $_POST[$post_var];
239  }
240 
241  protected function getRequiredPointsUpdates($prgrs_id) {
242  $post_var = $this->getRequiredPointsPostVarTitle();
243  if (!array_key_exists($post_var, $_POST)) {
244  throw new ilException("Expected array $post_var in POST");
245  }
246 
247  $post_value = $_POST[$post_var];
248  return (int)$post_value[$prgrs_id];
249  }
250 
251 
252  protected function buildFrame($tab, $content) {
253  $tpl = new ilTemplate("tpl.indivdual_plan_frame.html", true, true, "Modules/StudyProgramme");
254  $ass = $this->getAssignmentObject();
255 
256  $tpl->setVariable("USERNAME", ilObjUser::_lookupFullname($ass->getUserId()));
257  foreach (array("view", "manage") as $_tab) {
258  $tpl->setCurrentBlock("sub_tab");
259  $tpl->setVariable("CLASS", $_tab == $tab ? "active" : "");
260  $tpl->setVariable("LINK", $this->getLinkTargetForSubTab($_tab, $ass->getId()));
261  $tpl->setVariable("TITLE", $this->lng->txt("prg_$_tab"));
262  $tpl->parseCurrentBlock();
263  }
264  $tpl->setVariable("CONTENT", $content);
265 
266  return $tpl->get();
267  }
268 
269  protected function getLinkTargetForSubTab($a_tab, $a_ass_id) {
270  $this->ctrl->setParameter($this, "ass_id", $a_ass_id);
271  $lnk = $this->ctrl->getLinkTarget($this, $a_tab);
272  $this->ctrl->setParameter($this, "ass_id", null);
273  return $lnk;
274  }
275 
276  public function appendIndividualPlanActions(ilTable2GUI $a_table) {
277  $a_table->setFormAction($this->ctrl->getFormAction($this));
278  $a_table->addCommandButton("updateFromCurrentPlan", $this->lng->txt("prg_update_from_current_plan"));
279  $a_table->addCommandButton("updateFromInput", $this->lng->txt("save"));
280  }
281 
285 
286  public function getManualStatusPostVarTitle() {
287  return "status";
288  }
289 
290  public function getRequiredPointsPostVarTitle() {
291  return "required_points";
292  }
293 
294  public function getManualStatusNone() {
295  return self::MANUAL_STATUS_NONE;
296  }
297 
298  public function getManualStatusNotRelevant() {
299  return self::MANUAL_STATUS_NOT_RELEVANT;
300  }
301 
302  public function getManualStatusAccredited() {
303  return self::MANUAL_STATUS_ACCREDITED;
304  }
305 
306  static public function getLinkTargetView($ctrl, $a_ass_id) {
307  $cl = "ilObjStudyProgrammeIndividualPlanGUI";
308  $ctrl->setParameterByClass($cl, "ass_id", $a_ass_id);
309  $link = $ctrl->getLinkTargetByClass($cl, "view");
310  $ctrl->setParameterByClass($cl, "ass_id", null);
311  return $link;
312  }
313 }
314 
315 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
Base class for ILIAS Exception handling.
$_GET["client_id"]
static _lookupFullname($a_user_id)
Lookup Full Name.
$cmd
Definition: sahs_server.php:35
logging
Definition: class.ilLog.php:18
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
Class ilTable2GUI.
special template class to simplify handling of ITX/PEAR
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
Create styles array
The data for the language used.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $DIC
$_POST["username"]
static getInstanceById($a_prgrs_id)
Get an instance by progress id.