ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilObjLearningSequenceContentGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 public const CMD_MANAGE_CONTENT = "manageContent";
27 public const CMD_SAVE = "save";
28 public const CMD_DELETE = "delete";
29 public const CMD_CONFIRM_DELETE = "confirmDelete";
30 public const CMD_CANCEL = "cancel";
31
32 public const FIELD_ORDER = 'f_order';
33 public const FIELD_ONLINE = 'f_online';
34 public const FIELD_POSTCONDITION_TYPE = 'f_pct';
35
37 protected ilCtrl $ctrl;
39 protected ilLanguage $lng;
40 protected ilAccess $access;
47
48 public function __construct(
59 ILIAS\UI\Renderer $ui_renderer
60 ) {
61 $this->parent_gui = $parent_gui;
62 $this->ctrl = $ctrl;
63 $this->tpl = $tpl;
64 $this->lng = $lng;
65 $this->access = $access;
66 $this->confirmation_gui = $confirmation_gui;
67 $this->ls_item_online_status = $ls_item_online_status;
68 $this->post_wrapper = $post_wrapper;
69 $this->refinery = $refinery;
70 $this->ui_factory = $ui_factory;
71 $this->ui_renderer = $ui_renderer;
72 }
73
74 public function executeCommand(): void
75 {
76 $cmd = $this->ctrl->getCmd();
77
78 switch ($cmd) {
80 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
81 break;
83 case self::CMD_SAVE:
86 $this->$cmd();
87 break;
88 default:
89 throw new ilException("ilObjLearningSequenceContentGUI: Command not supported: $cmd");
90 }
91 }
92
93 protected function manageContent(): void
94 {
95 // Adds a btn to the gui which allows adding possible objects.
96 $this->parent_gui->showPossibleSubObjects();
97
98 $data = $this->parent_gui->getObject()->getLSItems();
99 // Sadly, ilTable2 only wants an array for fillRow, so we need to wrap this...
100 $data = array_map(fn ($s) => [$s], $data);
101 $this->renderTable($data);
102 }
103
104 protected function renderTable(array $ls_items): void
105 {
107 $this,
108 $this->parent_gui,
109 self::CMD_MANAGE_CONTENT,
110 $this->ctrl,
111 $this->lng,
112 $this->access,
113 $this->ui_factory,
114 $this->ui_renderer,
116 $this->ls_item_online_status
117 );
118
119 $table->setData($ls_items);
120 $table->addMultiCommand(self::CMD_CONFIRM_DELETE, $this->lng->txt("delete"));
121
122 $table->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
123
124 $this->tpl->setContent($table->getHtml());
125 }
126
130 protected function confirmDelete(): void
131 {
132 $r = $this->refinery;
133 $ref_ids = $this->post_wrapper->retrieve(
134 "id",
135 $r->byTrying([
136 $r->kindlyTo()->listOf($r->kindlyTo()->int()),
137 $r->always([])
138 ])
139 );
140
141 if (!$ref_ids || count($ref_ids) < 1) {
142 $this->tpl->setOnScreenMessage("info", $this->lng->txt('no_entries_selected_for_delete'), true);
143 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
144 }
145
146 foreach ($ref_ids as $ref_id) {
148 $this->confirmation_gui->addItem("id[]", (string) $ref_id, $obj->getTitle());
149 }
150
151 $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
152 $this->confirmation_gui->setHeaderText($this->lng->txt("delete_confirmation"));
153 $this->confirmation_gui->setConfirm($this->lng->txt("confirm"), self::CMD_DELETE);
154 $this->confirmation_gui->setCancel($this->lng->txt("cancel"), self::CMD_CANCEL);
155
156 $this->tpl->setContent($this->confirmation_gui->getHTML());
157 }
158
159 protected function delete(): void
160 {
161 $ref_ids = $this->post_wrapper->retrieve(
162 "id",
163 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
164 );
165
166 $this->parent_gui->getObject()->deletePostConditionsForSubObjects($ref_ids);
167
168 $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_deleted'), true);
169 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
170 }
171
175 public function getPossiblePostConditionsForType(string $type): array
176 {
177 return $this->parent_gui->getObject()->getPossiblePostConditionsForType($type);
178 }
179
180
181 public function getFieldName(string $field_name, int $ref_id): string
182 {
183 return implode('_', [$field_name, (string) $ref_id]);
184 }
185
186 protected function save(): void
187 {
188 $data = $this->parent_gui->getObject()->getLSItems();
189 $r = $this->refinery;
190
191 $updated = [];
192 foreach ($data as $lsitem) {
193 $ref_id = $lsitem->getRefId();
194 $online = $this->getFieldName(self::FIELD_ONLINE, $ref_id);
195 $order = $this->getFieldName(self::FIELD_ORDER, $ref_id);
196 $condition_type = $this->getFieldName(self::FIELD_POSTCONDITION_TYPE, $ref_id);
197
198 $condition_type = $this->post_wrapper->retrieve($condition_type, $r->kindlyTo()->string());
199 $online = $this->post_wrapper->retrieve($online, $r->byTrying([$r->kindlyTo()->bool(), $r->always(false)]));
200 $order = $this->post_wrapper->retrieve($order, $r->kindlyTo()->int());
201
202 $condition = $lsitem->getPostCondition()
203 ->withConditionOperator($condition_type);
204 $updated[] = $lsitem
205 ->withOnline($online)
206 ->withOrderNumber($order)
207 ->withPostCondition($condition);
208 }
209
210 $this->parent_gui->getObject()->storeLSItems($updated);
211 $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_updated'), true);
212 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
213 }
214}
Builds data types.
Definition: Factory.php:21
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...
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...
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
__construct(ilObjLearningSequenceGUI $parent_gui, ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccess $access, ilConfirmationGUI $confirmation_gui, LSItemOnlineStatus $ls_item_online_status, ArrayBasedRequestWrapper $post_wrapper, Factory $refinery, ILIAS\UI\Factory $ui_factory, ILIAS\UI\Renderer $ui_renderer)
confirmDelete()
Handle the confirmDelete command.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjLearningSequenceGUI @ilCtrl_isCalledBy ilObjLearningSequenceGUI: ilRepositoryGUI @ilCtrl_i...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$type