ILIAS  release_8 Revision v8.24
class.ilPCAMDFormGUI.php
Go to the documentation of this file.
1<?php
2
21use Psr\Http\Message\ServerRequestInterface;
22
30{
32 protected \ILIAS\DI\UIServices $ui;
34 protected ServerRequestInterface $http_request;
35
36 public function __construct(
37 ilPageObject $a_pg_obj,
38 ?ilPageContent $a_content_obj,
39 string $a_hier_id,
40 string $a_pc_id = ""
41 ) {
42 global $DIC;
43 $this->ctrl = $DIC->ctrl();
44 $this->ui = $DIC->ui();
45 $this->http_request = $DIC->http()->request();
46 $this->port_request = $DIC->portfolio()
47 ->internal()
48 ->gui()
49 ->standardRequest();
50 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
51
52 $this->lng->loadLanguageModule("prtt");
53 $this->lng->loadLanguageModule("prtf");
54 }
55
56 public function executeCommand(): void
57 {
58 // get next class that processes or forwards current command
59 $next_class = $this->ctrl->getNextClass($this);
60
61 // get current command
62 $cmd = $this->ctrl->getCmd();
63
64 switch ($next_class) {
65
66 case "ilpropertyformgui":
67 $form = $this->getPortfolioForm(true);
68 $this->ctrl->forwardCommand($form);
69 break;
70
71 default:
72 $ret = $this->$cmd();
73 break;
74 }
75 }
76
77 protected function isTemplate(): bool
78 {
79 return ($this->getPage()->getParentType() === "prtt");
80 }
81
82 public function insert(Form\Standard $form = null): void
83 {
85
87
88 if (!$form) {
89 $form = $this->getTemplateForm();
90 }
91 $tpl->setContent($this->ui->renderer()->render($form));
92 }
93
94 public function edit(): void
95 {
96 if ($this->isTemplate()) {
97 $this->editTemplate();
98 return;
99 }
100 $this->editPortfolio();
101 }
102
103 public function editTemplate(Form\Standard $form = null): void
104 {
106
107 $this->displayValidationError();
108
109 if (!$form) {
110 $form = $this->getTemplateForm(true);
111 }
112 $tpl->setContent($this->ui->renderer()->render($form));
113 }
114
115 public function getTemplateForm(bool $edit = false): Form\Standard
116 {
117 $ui = $this->ui;
118 $f = $ui->factory();
120
121 $selected = [];
122 if ($edit) {
123 $selected = $this->content_obj->getRecordIds();
124 }
125 $recs = $this->getAdvRecords();
126 $fields = array();
127 foreach ($recs as $r) {
128 $val = (in_array($r->getRecordId(), $selected));
129 $fields["rec" . $r->getRecordId()] =
130 $f->input()->field()->checkbox($r->getTitle(), $r->getDescription())
131 ->withValue($val);
132 }
133
134 // section
135 $section1 = $f->input()->field()->section($fields, $this->lng->txt("prtt_select_datasets"));
136
137 if ($edit) {
138 $form_action = $ctrl->getLinkTarget($this, "update");
139 } else {
140 $form_action = $ctrl->getLinkTarget($this, "create_amdfrm");
141 }
142 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
143 }
144
145 public function create(): void
146 {
148 $form = $this->getTemplateForm();
151
152 if ($request->getMethod() === "POST") {
153 $form = $form->withRequest($request);
154 $data = $form->getData();
155 if (is_null($data)) {
156 $tpl->setContent($this->ui->renderer()->render($form));
157 return;
158 }
159 if (is_array($data["sec"])) {
160 $this->content_obj = new ilPCAMDForm($this->getPage());
161 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
162 $this->content_obj->setRecordIds($this->getRecordIdsFromForm($form));
163 $this->updated = $this->pg_obj->update();
164 if (!$this->updated) {
165 $tpl->setContent($this->ui->renderer()->render($form));
166 return;
167 }
168 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
169 }
170 }
171 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
172 }
173
174 protected function getRecordIdsFromForm(Form\Standard $form): array
175 {
176 $data = $form->getData();
177 $ids = [];
178 if (!is_null($data) && is_array($data["sec"])) {
179 $recs = $this->getAdvRecords();
180 $ids = [];
181 foreach ($recs as $r) {
182 $rec_id = $data["sec"]["rec" . $r->getRecordId()];
183 if (isset($rec_id) && $rec_id) {
184 $ids[] = $r->getRecordId();
185 }
186 }
187 }
188 return $ids;
189 }
190
191 protected function getAdvRecords(): array
192 {
193 if ($this->isTemplate()) {
195 $is_ref_id = true;
196 } else {
197 $id = $this->getPage()->getPortfolioId();
198 $is_ref_id = false;
199 }
200
201 $recs = \ilAdvancedMDRecord::_getSelectedRecordsByObject($this->getPage()->getParentType(), $id, "pfpg", $is_ref_id);
202 return $recs;
203 }
204
205 public function update(): void
206 {
208 $form = $this->getTemplateForm(true);
211
212 if ($request->getMethod() === "POST") {
213 $form = $form->withRequest($request);
214 $data = $form->getData();
215 if (is_null($data)) {
216 $tpl->setContent($this->ui->renderer()->render($form));
217 return;
218 }
219 if (is_array($data["sec"])) {
220 $this->content_obj->setRecordIds($this->getRecordIdsFromForm($form));
221 $this->updated = $this->pg_obj->update();
222 if (!$this->updated) {
223 $tpl->setContent($this->ui->renderer()->render($form));
224 return;
225 }
226 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
227 }
228 }
229 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
230 }
231
235
236
240 public function editPortfolio(?ilPropertyFormGUI $form = null): void
241 {
243
244 $this->displayValidationError();
245
246 if (!$form) {
247 $form = $this->getPortfolioForm(true);
248 }
249 $tpl->setContent($form->getHTML());
250 }
251
252 public function getPortfolioForm(bool $edit = false): ilPropertyFormGUI
253 {
255 if (is_null($content_obj)) {
256 $page = new ilPortfolioPage($this->port_request->getPortfolioPageId());
257 $page->buildDom();
258 $content_obj = $page->getContentObjectForPcId($this->request->getPCId());
259 }
260
263
264 $selected = [];
265 if ($edit) {
266 $selected = $content_obj->getRecordIds();
267 }
268 $recs = $this->getAdvRecords();
269 foreach ($recs as $r) {
270 $val = (in_array($r->getRecordId(), $selected));
271 }
272
273 $form = new ilPropertyFormGUI();
274 $form->setFormAction($ctrl->getFormAction($this, "updateAdvancedMetaData"));
275
276 $form->setTitle($lng->txt("prtf_edit_data"));
277
278 $this->record_gui = new ilAdvancedMDRecordGUI(
280 'prtf',
281 $this->getPage()->getPortfolioId(),
282 'pfpg',
283 $this->getPage()->getId(),
284 false
285 );
286 $this->record_gui->setRecordFilter($selected);
287 $this->record_gui->setPropertyForm($form);
288 $this->record_gui->parse();
289
290 $form->addCommandButton("updateAdvancedMetaData", $lng->txt("save"));
291 $form->addCommandButton("cancel", $lng->txt("cancel"));
292
293 return $form;
294 }
295
296 public function updateAdvancedMetaData(): void
297 {
299
300 $form = $this->getPortfolioForm(true);
301
302 // needed for proper advanced MD validation
303 $form->checkInput();
304 if (!$this->record_gui->importEditFormPostValues()) {
305 $this->editPortfolio($form); // #16470
306 return;
307 }
308
309 if ($this->record_gui->writeEditForm()) {
310 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
311 }
312 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
313 }
314}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
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...
AMD Form Page UI.
editPortfolio(?ilPropertyFormGUI $form=null)
Edit courses form.
ilAdvancedMDRecordGUI $record_gui
getTemplateForm(bool $edit=false)
ILIAS DI UIServices $ui
editTemplate(Form\Standard $form=null)
ServerRequestInterface $http_request
StandardGUIRequest $port_request
getRecordIdsFromForm(Form\Standard $form)
getPortfolioForm(bool $edit=false)
insert(Form\Standard $form=null)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
global $DIC
Definition: feed.php:28
This describes commonalities between all forms.
Definition: Form.php:33
This describes a standard form.
Definition: Standard.php:27
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59