ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
153 public function create_lhist(): void
154 {
155 $this->create();
156 }
157
158 public function create(): void
159 {
160 $valid = false;
161
162 $form = $this->initForm(true);
163 if ($form->checkInput()) {
164 //$data = $form->getInput("skill_id");
165 $valid = true;
166 }
167
168 if ($valid) {
169 $this->content_obj = new ilPCLearningHistory($this->getPage());
170 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
171 $this->setAttributesFromInput($form);
172 $this->updated = $this->pg_obj->update();
173 if ($this->updated === true) {
174 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
175 }
176 }
177
178 $form->setValuesByPost();
179 $this->insert($form);
180 }
181
185 public function update(): void
186 {
187 $form = $this->initForm();
188 if ($form->checkInput()) {
189 $this->setAttributesFromInput($form);
190 $this->updated = $this->pg_obj->update();
191 if ($this->updated === true) {
192 $this->tpl->setOnScreenMessage('info', $this->lng->txt("msg_obj_modified"), true);
193 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
194 }
195 }
196
197 $this->pg_obj->addHierIDs();
198 $form->setValuesByPost();
199 $this->edit($form);
200 }
201
202 protected function setAttributesFromInput(ilPropertyFormGUI $form): void
203 {
205 $item = $form->getItemByPostVar("period");
206 $from = (is_null($item->getStart()))
207 ? ""
208 : $item->getStart()->get(IL_CAL_DATE);
209 $to = (is_null($item->getEnd()))
210 ? ""
211 : $item->getEnd()->get(IL_CAL_DATE);
212
213 $this->content_obj->setFrom($from);
214 $this->content_obj->setTo($to);
215 $classes = ($form->getInput("mode") == "1" && is_array($form->getInput("class")))
216 ? $form->getInput("class")
217 : array();
218 $this->content_obj->setClasses($classes);
219 }
220
221 public static function getPlaceholderPresentation(): string
222 {
223 global $DIC;
224
225 $lng = $DIC->language();
226 $lng->loadLanguageModule("lhist");
227
228 // @todo we need a ks element for this
229 $content = '<div style="margin:5px" class="ilBox"><h3>' . $lng->txt("lhist_lhist") . '</h3><div class="il_Description_no_margin">' .
230 $lng->txt("lhist_cont_placeholder_text") . '</div></div>';
231
232 return $content;
233 }
234}
const IL_CAL_DATE
input GUI for a time span (start and end date)
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 class represents a multi selection list property in a property form.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initForm(bool $a_insert=false)
Init learning history edit form.
insert(?ilPropertyFormGUI $a_form=null)
Insert learning history form.
update()
Update learning history component.
edit(?ilPropertyFormGUI $a_form=null)
__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 class represents an option in a radio group.
$valid
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26