ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
14  const POST_VAR_STATUS = "status";
15  const POST_VAR_REQUIRED_POINTS = "required_points";
16  const POST_VAR_DEADLINE = "deadline";
17  const MANUAL_STATUS_NONE = -1;
18 
22  public $ctrl;
23 
27  public $tpl;
28 
32  public $object;
33 
37  public $lng;
38 
42  public $user;
43 
44  protected $parent_gui;
45 
50 
55 
59  protected $messages;
60 
64  protected $permissions;
65 
66  public function __construct(
68  \ilCtrl $ilCtrl,
74  ) {
75  $this->tpl = $tpl;
76  $this->ctrl = $ilCtrl;
77  $this->lng = $lng;
78  $this->user = $ilUser;
79 
80  $this->assignment_object = null;
81 
82  $this->progress_repository = $progress_repository;
83  $this->assignment_repository = $assignment_repository;
84  $this->messages = $messages;
85 
86  $this->object = null;
87  $this->permissions = null;
88 
89  $lng->loadLanguageModule("prg");
90 
91  $this->tpl->addCss("Modules/StudyProgramme/templates/css/ilStudyProgramme.css");
92  }
93 
94  public function setParentGUI($a_parent_gui)
95  {
96  $this->parent_gui = $a_parent_gui;
97  }
98 
99  public function setRefId(int $ref_id) : void
100  {
101  $this->ref_id = $a_ref_id;
102  $this->object = \ilObjStudyProgramme::getInstanceByRefId($ref_id);
103  $this->permissions = ilStudyProgrammeDIC::specificDicFor($this->object)['permissionhelper'];
104  }
105 
106  public function executeCommand()
107  {
108  $cmd = $this->ctrl->getCmd();
109 
110  if ($cmd == "") {
111  $cmd = "view";
112  }
113 
114  switch ($cmd) {
115  case "view":
116  case "manage":
117  case "updateFromCurrentPlan":
118  case "updateFromInput":
119  $cont = $this->$cmd();
120  break;
121  default:
122  throw new ilException("ilObjStudyProgrammeMembersGUI: " .
123  "Command not supported: $cmd");
124  }
125 
126  $this->tpl->setContent($cont);
127  }
128 
129  protected function getAssignmentId()
130  {
131  if (!is_numeric($_GET["ass_id"])) {
132  throw new ilException("Expected integer 'ass_id'");
133  }
134  return (int) $_GET["ass_id"];
135  }
136 
137  protected function getAssignmentObject()
138  {
139  if ($this->assignment_object === null) {
140  $id = $this->getAssignmentId();
141  $this->assignment_object = $this->assignment_repository->getInstanceById((int) $id);
142  }
143  return $this->assignment_object;
144  }
145 
146  protected function view()
147  {
148  $ass = $this->getAssignmentObject();
149 
150  if (!in_array(
151  $ass->getUserId(),
152  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_VIEW_INDIVIDUAL_PLAN)
153  )) {
155  "may not access individual plan of user"
156  );
157  }
158  $prg = ilObjStudyProgramme::getInstanceByObjId($ass->getRootId());
159  $progress = $prg->getProgressForAssignment($ass->getId());
160 
161  $gui = new ilStudyProgrammeIndividualPlanProgressListGUI($progress);
162  $gui->setOnlyRelevant(true);
163  // Wrap a frame around the original gui element to correct rendering.
164  $tpl = new ilTemplate("tpl.individual_plan_tree_frame.html", false, false, "Modules/StudyProgramme");
165  $tpl->setVariable("CONTENT", $gui->getHTML());
166  return $this->buildFrame("view", $tpl->get());
167  }
168 
169 
170  protected function manage()
171  {
172  $ass = $this->getAssignmentObject();
173 
174  if (!in_array(
175  $ass->getUserId(),
176  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
177  )) {
179  "may not access individual plan of user"
180  );
181  }
182 
183 
184  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
185  $this->ctrl->setParameter($this, "cmd", "manage");
186  $table = new ilStudyProgrammeIndividualPlanTableGUI($this, $ass, $this->progress_repository);
187  $frame = $this->buildFrame("manage", $table->getHTML());
188  $this->ctrl->setParameter($this, "ass_id", null);
189  return $frame;
190  }
191 
192  protected function updateFromCurrentPlan()
193  {
194  $ass = $this->getAssignmentObject();
195 
196  if (!in_array(
197  $ass->getUserId(),
198  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
199  )) {
201  "may not access individual plan of user"
202  );
203  }
204 
205  $prg = $this->parent_gui->getStudyProgramme();
206  $progress = $prg->getProgressForAssignment($ass->getId());
207  $msgs = $this->messages->getMessageCollection('msg_update_individual_plan');
208  $this->object->updatePlanFromRepository(
209  $progress->getId(),
210  $this->user->getId(),
211  $msgs
212  );
213 
214  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
215  $this->showSuccessMessage("update_from_plan_successful");
216  $this->ctrl->redirect($this, "manage");
217  }
218 
219  protected function digestInput(array $post) : array
220  {
221  $params = [
222  self::POST_VAR_STATUS,
223  self::POST_VAR_DEADLINE,
224  self::POST_VAR_REQUIRED_POINTS
225  ];
226 
227  $ret = [];
228  foreach ($params as $postvar) {
229  $ret[$postvar] = [];
230  if (array_key_exists($postvar, $post)) {
231  $ret[$postvar] = $post[$postvar];
232  krsort($ret[$postvar], SORT_NUMERIC);
233  }
234  }
235  return $ret;
236  }
237 
238  protected function updateFromInput()
239  {
240  $values = $this->digestInput($_POST);
241  $msgs = $this->messages->getMessageCollection('msg_update_individual_plan');
242  $this->updateStatus($values[self::POST_VAR_STATUS], $msgs);
243  $this->updateDeadlines($values[self::POST_VAR_DEADLINE], $msgs);
244  $this->updateRequiredPoints($values[self::POST_VAR_REQUIRED_POINTS], $msgs);
245 
246  if ($msgs->hasAnyMessages()) {
247  $this->messages->showMessages($msgs);
248  }
249 
250  $this->ctrl->setParameter($this, "ass_id", $this->getAssignmentId());
251  $this->ctrl->redirect($this, "manage");
252  }
253 
254  protected function updateStatus(array $progress_updates, ilPRGMessageCollection $msgs)
255  {
256  $programme = $this->parent_gui->getStudyProgramme();
257  $acting_user_id = (int) $this->user->getId();
258 
259  foreach ($progress_updates as $progress_id => $target_status) {
260  switch ($target_status) {
262 
263  $progress = $this->progress_repository->get($progress_id);
264  $cur_status = $progress->getStatus();
265 
266  if ($cur_status == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
267  $programme->unmarkAccredited($progress_id, $acting_user_id, $msgs);
268  }
270  $programme->markRelevant($progress_id, $acting_user_id, $msgs);
271  }
272  break;
273 
275  $programme->markAccredited($progress_id, $acting_user_id, $msgs);
276  break;
277 
279  $programme->markNotRelevant($progress_id, $acting_user_id, $msgs);
280  break;
281 
282  case self::MANUAL_STATUS_NONE:
283  break;
284 
285  default:
286  $msgs->add(false, 'msg_impossible_target_status', $progress_id);
287  }
288  }
289  }
290 
291  protected function updateDeadlines(array $deadlines, ilPRGMessageCollection $msgs)
292  {
293  $programme = $this->parent_gui->getStudyProgramme();
294  $acting_user_id = (int) $this->user->getId();
295 
296  foreach ($deadlines as $progress_id => $deadline) {
297  if (trim($deadline) === '') {
298  $deadline = null;
299  } else {
300  $deadline = DateTimeImmutable::createFromFormat('d.m.Y', $deadline);
301  }
302 
303  $progress = $this->progress_repository->get($progress_id);
304  $cur_deadline = $progress->getDeadline();
305 
306  if ($deadline != $cur_deadline) {
307  $programme->changeProgressDeadline($progress_id, $acting_user_id, $msgs, $deadline);
308  }
309  }
310  }
311 
312  protected function updateRequiredPoints(array $required_points, ilPRGMessageCollection $msgs)
313  {
314  $programme = $this->parent_gui->getStudyProgramme();
315  $acting_user_id = (int) $this->user->getId();
316 
317  foreach ($required_points as $progress_id => $points) {
318  $points = (int) $points;
319 
320  if ($points < 0) {
321  $msgs->add(false, 'msg_points_must_be_positive', $progress_id);
322  continue;
323  }
324 
325  $progress = $this->progress_repository->get($progress_id);
326  $cur_points = $progress->getAmountOfPoints();
327 
328  if ($points != $cur_points) {
329  $programme->changeAmountOfPoints($progress_id, $acting_user_id, $msgs, $points);
330  }
331  }
332  }
333 
334  protected function showSuccessMessage($a_lng_var)
335  {
336  ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
337  }
338 
339  protected function buildFrame($tab, $content)
340  {
341  $tabs = [];
342  if ($this->permissions->may(ilOrgUnitOperation::OP_VIEW_INDIVIDUAL_PLAN)) {
343  $tabs[] = 'view';
344  }
345  if ($this->permissions->may(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)) {
346  $tabs[] = 'manage';
347  }
348 
349  $tpl = new ilTemplate("tpl.indivdual_plan_frame.html", true, true, "Modules/StudyProgramme");
350  $ass = $this->getAssignmentObject();
351  $user_id = $ass->getUserId();
352  $tpl->setVariable("USERNAME", ilObjUser::_lookupFullname($user_id));
353 
354  foreach ($tabs as $_tab) {
355  $tpl->setCurrentBlock("sub_tab");
356  $tpl->setVariable("CLASS", $_tab == $tab ? "active" : "");
357  $tpl->setVariable("LINK", $this->getLinkTargetForSubTab($_tab, $ass->getId()));
358  $tpl->setVariable("TITLE", $this->lng->txt("prg_$_tab"));
359  $tpl->parseCurrentBlock();
360  }
361  $tpl->setVariable("CONTENT", $content);
362 
363  return $tpl->get();
364  }
365 
366  protected function getLinkTargetForSubTab($a_tab, $a_ass_id)
367  {
368  $this->ctrl->setParameter($this, "ass_id", $a_ass_id);
369  $lnk = $this->ctrl->getLinkTarget($this, $a_tab);
370  $this->ctrl->setParameter($this, "ass_id", null);
371  return $lnk;
372  }
373 
374  public function appendIndividualPlanActions(ilTable2GUI $a_table)
375  {
376  $a_table->setFormAction($this->ctrl->getFormAction($this));
377  $a_table->addCommandButton("updateFromCurrentPlan", $this->lng->txt("prg_update_from_current_plan"));
378  $a_table->addCommandButton("updateFromInput", $this->lng->txt("save"));
379  }
380 
381  public function getLinkTargetView($a_ass_id)
382  {
383  $cl = "ilObjStudyProgrammeIndividualPlanGUI";
384  $this->ctrl->setParameterByClass($cl, "ass_id", $a_ass_id);
385  $link = $this->ctrl->getLinkTargetByClass($cl, "view");
386  $this->ctrl->setParameterByClass($cl, "ass_id", null);
387  return $link;
388  }
389 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
This class provides processing control methods.
__construct(\ilGlobalTemplateInterface $tpl, \ilCtrl $ilCtrl, \ilLanguage $lng, \ilObjUser $ilUser, ilStudyProgrammeProgressRepository $progress_repository, ilStudyProgrammeAssignmentRepository $assignment_repository, ilPRGMessagePrinter $messages)
$_GET["client_id"]
Util around ilPRGMessageCollection factors and output collections.
static _lookupFullname($a_user_id)
Lookup Full Name.
updateDeadlines(array $deadlines, ilPRGMessageCollection $msgs)
add(bool $success, string $message, string $record_identitifer)
user()
Definition: user.php:4
static getInstanceByRefId($a_ref_id)
updateStatus(array $progress_updates, ilPRGMessageCollection $msgs)
updateRequiredPoints(array $required_points, ilPRGMessageCollection $msgs)
static specificDicFor(\ilObjStudyProgramme $prg)
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
loadLanguageModule($a_module)
$ret
Definition: parser.php:6
Covers the persistence of settings belonging to a study programme (SP).
$ilUser
Definition: imgupload.php:18
$_POST["username"]
Holds information about multi-actions, mainly in context of member-assignemnts and status changes...