ILIAS  release_8 Revision v8.24
class.ilPCLearningHistoryGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilObjUser $user;
27 protected \ILIAS\DI\UIServices $ui;
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPCLearningHistory $a_content_obj = null,
33 string $a_hier_id = "",
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->tpl = $DIC["tpl"];
39 $this->ctrl = $DIC->ctrl();
40 $this->user = $DIC->user();
41 $this->lng = $DIC->language();
42 $this->lng->loadLanguageModule("lhist");
43 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
44 $this->service = $DIC->learningHistory();
45 $this->ui = $DIC->ui();
46 }
47
48 public function executeCommand(): void
49 {
50 $next_class = $this->ctrl->getNextClass($this);
51 $cmd = $this->ctrl->getCmd();
52
53 switch ($next_class) {
54 default:
55 $this->$cmd();
56 break;
57 }
58 }
59
63 public function insert(ilPropertyFormGUI $a_form = null): void
64 {
66
68
69 if (!$a_form) {
70 $a_form = $this->initForm(true);
71 }
72 $tpl->setContent($a_form->getHTML());
73 }
74
75 public function edit(ilPropertyFormGUI $a_form = null): void
76 {
78
80
81 if (!$a_form) {
82 $a_form = $this->initForm();
83 }
84 $tpl->setContent($a_form->getHTML());
85 }
86
90 protected function initForm(bool $a_insert = false): ilPropertyFormGUI
91 {
92 $ilCtrl = $this->ctrl;
94
95 $form = new ilPropertyFormGUI();
96 $form->setFormAction($ilCtrl->getFormAction($this));
97 if ($a_insert) {
98 $form->setTitle($this->lng->txt("cont_create_lhist"));
99 } else {
100 $form->setTitle($this->lng->txt("cont_update_lhist"));
101 }
102
103 // duration
104 $du = new ilDateDurationInputGUI($lng->txt("lhist_period"), "period");
105 if (!$a_insert) {
106 if ($this->content_obj->getFrom() != "") {
107 $du->setStart(new ilDate($this->content_obj->getFrom(), IL_CAL_DATE));
108 }
109 if ($this->content_obj->getTo() != "") {
110 $du->setEnd(new ilDate($this->content_obj->getTo(), IL_CAL_DATE));
111 }
112 }
113 $du->setAllowOpenIntervals(true);
114 $form->addItem($du);
115
116 //
117 $radg = new ilRadioGroupInputGUI($lng->txt("lhist_type_of_achievement"), "mode");
118 $radg->setValue("0");
119 $op1 = new ilRadioOption($lng->txt("lhist_all"), "0");
120 $radg->addOption($op1);
121 $op2 = new ilRadioOption($lng->txt("lhist_selected"), "1");
122 $radg->addOption($op2);
123 $form->addItem($radg);
124
125
126 // select type
127 $options = [];
128 foreach ($this->service->provider()->getAllProviders(true) as $p) {
129 $options[get_class($p)] = $p->getName();
130 }
131 $si = new ilMultiSelectInputGUI($lng->txt(""), "class");
132 $si->setHeight(130);
133 if (!$a_insert) {
134 $si->setValue($this->content_obj->getClasses());
135 if (count($this->content_obj->getClasses()) > 0) {
136 $radg->setValue(1);
137 }
138 }
139 $si->setOptions($options);
140 $op2->addSubItem($si);
141
142 if ($a_insert) {
143 $form->addCommandButton("create_lhist", $this->lng->txt("insert"));
144 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
145 } else {
146 $form->addCommandButton("update", $this->lng->txt("save"));
147 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
148 }
149
150 return $form;
151 }
152
156 public function create(): void
157 {
158 $valid = false;
159
160 $form = $this->initForm(true);
161 if ($form->checkInput()) {
162 //$data = $form->getInput("skill_id");
163 $valid = true;
164 }
165
166 if ($valid) {
167 $this->content_obj = new ilPCLearningHistory($this->getPage());
168 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
169 $this->setAttributesFromInput($form);
170 $this->updated = $this->pg_obj->update();
171 if ($this->updated === true) {
172 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
173 }
174 }
175
176 $form->setValuesByPost();
177 $this->insert($form);
178 }
179
183 public function update(): void
184 {
185 $form = $this->initForm();
186 if ($form->checkInput()) {
187 $this->setAttributesFromInput($form);
188 $this->updated = $this->pg_obj->update();
189 if ($this->updated === true) {
190 $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_obj_modified"), true);
191 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
192 }
193 }
194
195 $this->pg_obj->addHierIDs();
196 $form->setValuesByPost();
197 $this->edit($form);
198 }
199
200 protected function setAttributesFromInput(ilPropertyFormGUI $form): void
201 {
203 $item = $form->getItemByPostVar("period");
204 $from = (is_null($item->getStart()))
205 ? ""
206 : $item->getStart()->get(IL_CAL_DATE);
207 $to = (is_null($item->getEnd()))
208 ? ""
209 : $item->getEnd()->get(IL_CAL_DATE);
210
211 $this->content_obj->setFrom($from);
212 $this->content_obj->setTo($to);
213 $classes = ($form->getInput("mode") == "1" && is_array($form->getInput("class")))
214 ? $form->getInput("class")
215 : array();
216 $this->content_obj->setClasses($classes);
217 }
218
219 public static function getPlaceholderPresentation(): string
220 {
221 global $DIC;
222
223 $lng = $DIC->language();
224 $lng->loadLanguageModule("lhist");
225
226 // @todo we need a ks element for this
227 $content = '<div style="margin:5px" class="ilBox"><h3>' . $lng->txt("lhist_lhist") . '</h3><div class="il_Description_no_margin">' .
228 $lng->txt("lhist_cont_placeholder_text") . '</div></div>';
229
230 return $content;
231 }
232}
const IL_CAL_DATE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for single dates.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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...
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
create()
Create new learning history component.
initForm(bool $a_insert=false)
Init learning history edit form.
update()
Update learning history component.
edit(ilPropertyFormGUI $a_form=null)
insert(ilPropertyFormGUI $a_form=null)
Insert learning history form.
__construct(ilPageObject $a_pg_obj, ?ilPCLearningHistory $a_content_obj=null, string $a_hier_id="", string $a_pc_id="")
ilLearningHistoryService $service
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc