ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjStudyProgrammeIndividualPlanGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 {
23  public const POST_VAR_STATUS = "status";
24  public const POST_VAR_REQUIRED_POINTS = "required_points";
25  public const POST_VAR_DEADLINE = "deadline";
26  public const MANUAL_STATUS_NONE = -1;
27 
29  public ilCtrl $ctrl;
30  public ilLanguage $lng;
31  public ilObjUser $user;
36 
41  protected int $ref_id;
42 
43  public function __construct(
45  ilCtrl $ilCtrl,
46  ilLanguage $lng,
48  ilPRGAssignmentDBRepository $assignment_repository,
49  ilPRGMessagePrinter $messages,
50  ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper,
51  ILIAS\Refinery\Factory $refinery
52  ) {
53  $this->tpl = $tpl;
54  $this->ctrl = $ilCtrl;
55  $this->lng = $lng;
56  $this->user = $ilUser;
57  $this->assignment_object = null;
58  $this->assignment_repository = $assignment_repository;
59  $this->messages = $messages;
60  $this->http_wrapper = $http_wrapper;
61  $this->refinery = $refinery;
62  $this->object = null;
63  $this->permissions = null;
64 
65  $lng->loadLanguageModule("prg");
66 
67  $this->tpl->addCss("Modules/StudyProgramme/templates/css/ilStudyProgramme.css");
68  }
69 
70  public function setParentGUI(ilObjStudyProgrammeMembersGUI $parent_gui): void
71  {
72  $this->parent_gui = $parent_gui;
73  }
74 
75  public function setRefId(int $ref_id): void
76  {
77  $this->ref_id = $ref_id;
78  $this->object = ilObjStudyProgramme::getInstanceByRefId($ref_id);
79  $this->permissions = ilStudyProgrammeDIC::specificDicFor($this->object)['permissionhelper'];
80  }
81 
82  public function executeCommand(): void
83  {
84  $cmd = $this->ctrl->getCmd();
85 
86  if ($cmd === "" || $cmd === null) {
87  $cmd = "view";
88  }
89 
90  switch ($cmd) {
91  case "view":
92  case "manage":
93  case "updateFromCurrentPlan":
94  case "updateFromInput":
95  $cont = $this->$cmd();
96  break;
97  default:
98  throw new ilException("ilObjStudyProgrammeMembersGUI: Command not supported: $cmd");
99  }
100 
101  $this->tpl->setContent($cont);
102  }
103 
104  protected function getAssignmentId(): int
105  {
106  return $this->http_wrapper->query()->retrieve("ass_id", $this->refinery->kindlyTo()->int());
107  }
108 
109  protected function getAssignmentObject(): ilPRGAssignment
110  {
111  if ($this->assignment_object === null) {
112  $id = $this->getAssignmentId();
113  $this->assignment_object = $this->assignment_repository->get((int) $id);
114  }
116  }
117 
118  protected function view(): string
119  {
120  $ass = $this->getAssignmentObject();
121 
122  if (!in_array(
123  $ass->getUserId(),
124  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_VIEW_INDIVIDUAL_PLAN)
125  )) {
127  "may not access individual plan of user"
128  );
129  }
130  $progress = $ass->getProgressForNode($ass->getRootId());
131  $gui = new ilStudyProgrammeIndividualPlanProgressListGUI($progress);
132  $gui->setOnlyRelevant(true);
133  // Wrap a frame around the original gui element to correct rendering.
134  $tpl = new ilTemplate("tpl.individual_plan_tree_frame.html", false, false, "Modules/StudyProgramme");
135  $tpl->setVariable("CONTENT", $gui->getHTML());
136  return $this->buildFrame("view", $tpl->get());
137  }
138 
139  protected function manage(): string
140  {
141  $ass = $this->getAssignmentObject();
142 
143  if (!in_array(
144  $ass->getUserId(),
145  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
146  )) {
148  "may not access individual plan of user"
149  );
150  }
151 
152  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
153  $table = new ilStudyProgrammeIndividualPlanTableGUI($this, $ass);
154  $frame = $this->buildFrame("manage", $table->getHTML());
155  $this->ctrl->setParameter($this, "ass_id", null);
156  return $frame;
157  }
158 
159  protected function updateFromCurrentPlan(): void
160  {
161  $ass = $this->getAssignmentObject();
162 
163  if (!in_array(
164  $ass->getUserId(),
165  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
166  )) {
168  "may not access individual plan of user"
169  );
170  }
171  $msgs = $this->messages->getMessageCollection('msg_update_individual_plan');
172  $this->object->updatePlanFromRepository(
173  $ass->getId(),
174  $this->user->getId(),
175  $msgs
176  );
177 
178  $this->ctrl->setParameter($this, "ass_id", $ass->getId());
179  $this->showSuccessMessage("update_from_plan_successful");
180  $this->ctrl->redirect($this, "manage");
181  }
182 
183  protected function updateFromInput(): void
184  {
185  $retrieve = $this->refinery->kindlyTo()->dictOf($this->refinery->kindlyTo()->string());
186 
187  $msgs = $this->messages->getMessageCollection('msg_update_individual_plan');
188  if ($this->http_wrapper->post()->has(self::POST_VAR_DEADLINE)) {
189  $this->updateDeadlines($this->http_wrapper->post()->retrieve(self::POST_VAR_DEADLINE, $retrieve), $msgs);
190  }
191  $this->updateStatus($this->http_wrapper->post()->retrieve(self::POST_VAR_STATUS, $retrieve), $msgs);
192  if ($this->http_wrapper->post()->has(self::POST_VAR_REQUIRED_POINTS)) {
193  $this->updateRequiredPoints($this->http_wrapper->post()->retrieve(self::POST_VAR_REQUIRED_POINTS, $retrieve), $msgs);
194  }
195 
196  if ($msgs->hasAnyMessages()) {
197  $this->messages->showMessages($msgs);
198  }
199 
200  $this->ctrl->setParameter($this, "ass_id", $this->getAssignmentId());
201  $this->ctrl->redirect($this, "manage");
202  }
203 
204  protected function updateStatus(array $progress_updates, ilPRGMessageCollection $msgs): void
205  {
206  $ass = $this->getAssignmentObject();
207  $acting_user_id = (int) $this->user->getId();
208 
209  foreach ($progress_updates as $progress_id => $target_status) {
210  $programme = ilObjStudyProgramme::getInstanceByObjId($progress_id);
211  $progress = $ass->getProgressForNode($progress_id);
212  switch ($target_status) {
214  $cur_status = $progress->getStatus();
215  if ($cur_status == ilPRGProgress::STATUS_ACCREDITED) {
216  $programme->unmarkAccredited($ass->getId(), $acting_user_id, $msgs);
217  }
218  if ($cur_status == ilPRGProgress::STATUS_NOT_RELEVANT) {
219  $programme->markRelevant($ass->getId(), $acting_user_id, $msgs);
220  }
221  break;
222 
224  $programme->markAccredited($ass->getId(), $acting_user_id, $msgs);
225  break;
226 
228  $programme->markNotRelevant($ass->getId(), $acting_user_id, $msgs);
229  break;
230 
231  case self::MANUAL_STATUS_NONE:
232  break;
233 
234  default:
235  $msgs->add(false, 'msg_impossible_target_status', $progress_id);
236  }
237  }
238  }
239 
240  protected function updateDeadlines(array $deadlines, ilPRGMessageCollection $msgs): void
241  {
242  $ass = $this->getAssignmentObject();
243  $acting_user_id = (int) $this->user->getId();
244 
245  foreach ($deadlines as $progress_id => $deadline) {
246  $programme = ilObjStudyProgramme::getInstanceByObjId($progress_id);
247  $progress = $ass->getProgressForNode($progress_id);
248 
249  if (trim($deadline) === '') {
250  $deadline = null;
251  } else {
252  $deadline = DateTimeImmutable::createFromFormat('d.m.Y', $deadline);
253  }
254 
255  $cur_deadline = $progress->getDeadline();
256  if ($deadline != $cur_deadline) {
257  $programme->changeProgressDeadline($ass->getId(), $acting_user_id, $msgs, $deadline);
258  }
259  }
260  }
261 
262  protected function updateRequiredPoints(array $required_points, ilPRGMessageCollection $msgs): void
263  {
264  $ass = $this->getAssignmentObject();
265  $acting_user_id = (int) $this->user->getId();
266 
267  foreach ($required_points as $progress_id => $points) {
268  $points = (int) $points;
269 
270  if ($points < 0) {
271  $msgs->add(false, 'msg_points_must_be_positive', $progress_id);
272  continue;
273  }
274  $programme = ilObjStudyProgramme::getInstanceByObjId($progress_id);
275  $progress = $ass->getProgressForNode($progress_id);
276  $cur_points = $progress->getAmountOfPoints();
277 
278  if ($points != $cur_points) {
279  $programme->changeAmountOfPoints($ass->getId(), $acting_user_id, $msgs, $points);
280  }
281  }
282  }
283 
284  protected function showSuccessMessage(string $lng_var): void
285  {
286  $this->tpl->setOnScreenMessage("success", $this->lng->txt("prg_$lng_var"), true);
287  }
288 
289  protected function buildFrame(string $tab, string $content): string
290  {
291  $tabs = [];
292  if ($this->permissions->may(ilOrgUnitOperation::OP_VIEW_INDIVIDUAL_PLAN)) {
293  $tabs[] = 'view';
294  }
295  if ($this->permissions->may(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)) {
296  $tabs[] = 'manage';
297  }
298 
299  $tpl = new ilTemplate("tpl.indivdual_plan_frame.html", true, true, "Modules/StudyProgramme");
300  $ass = $this->getAssignmentObject();
301  $user_id = $ass->getUserId();
302  $tpl->setVariable("USERNAME", ilObjUser::_lookupFullname($user_id));
303 
304  foreach ($tabs as $_tab) {
305  $tpl->setCurrentBlock("sub_tab");
306  $tpl->setVariable("CLASS", $_tab === $tab ? "active" : "");
307  $tpl->setVariable("LINK", $this->getLinkTargetForSubTab($_tab, $ass->getId()));
308  $tpl->setVariable("TITLE", $this->lng->txt("prg_$_tab"));
309  $tpl->parseCurrentBlock();
310  }
311  $tpl->setVariable("CONTENT", $content);
312 
313  return $tpl->get();
314  }
315 
316  protected function getLinkTargetForSubTab(string $tab, int $ass_id): string
317  {
318  $this->ctrl->setParameter($this, "ass_id", $ass_id);
319  $lnk = $this->ctrl->getLinkTarget($this, $tab);
320  $this->ctrl->setParameter($this, "ass_id", null);
321  return $lnk;
322  }
323 
324  public function appendIndividualPlanActions(ilTable2GUI $table): void
325  {
326  $table->setFormAction($this->ctrl->getFormAction($this));
327  $table->addCommandButton("updateFromCurrentPlan", $this->lng->txt("prg_update_from_current_plan"));
328  $table->addCommandButton("updateFromInput", $this->lng->txt("save"));
329  }
330 
331  public function getLinkTargetView(int $ass_id): string
332  {
333  $cl = "ilObjStudyProgrammeIndividualPlanGUI";
334  $this->ctrl->setParameterByClass($cl, "ass_id", $ass_id);
335  $link = $this->ctrl->getLinkTargetByClass($cl, "view");
336  $this->ctrl->setParameterByClass($cl, "ass_id", null);
337  return $link;
338  }
339 }
__construct(ilGlobalTemplateInterface $tpl, ilCtrl $ilCtrl, ilLanguage $lng, ilObjUser $ilUser, ilPRGAssignmentDBRepository $assignment_repository, ilPRGMessagePrinter $messages, ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper, ILIAS\Refinery\Factory $refinery)
setParentGUI(ilObjStudyProgrammeMembersGUI $parent_gui)
setFormAction(string $a_form_action, bool $a_multipart=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupFullname(int $a_user_id)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
Class ChatMainBarProvider .
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
updateDeadlines(array $deadlines, ilPRGMessageCollection $msgs)
loadLanguageModule(string $a_module)
Load language module.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
add(bool $success, string $message, string $record_identitifer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateStatus(array $progress_updates, ilPRGMessageCollection $msgs)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateRequiredPoints(array $required_points, ilPRGMessageCollection $msgs)
static specificDicFor(ilObjStudyProgramme $prg)
ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI ilObjStudyProgrammeMembersGUI: il...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...