ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
36 public function __construct(
37 protected ilObjLearningSequenceGUI $parent_gui,
38 protected ilCtrl $ctrl,
39 protected ilGlobalTemplateInterface $tpl,
40 protected ilLanguage $lng,
41 protected ilAccess $access,
42 protected ilConfirmationGUI $confirmation_gui,
43 protected LSItemOnlineStatus $ls_item_online_status,
44 protected ArrayBasedRequestWrapper $post_wrapper,
45 protected Factory $refinery,
46 protected ILIAS\UI\Factory $ui_factory,
47 protected ILIAS\UI\Renderer $ui_renderer
48 ) {
49 }
50
51 public function executeCommand(): void
52 {
53 if (!$this->access->checkAccess("read", '', $this->parent_gui->getRefId())) {
54 $this->tpl->setOnScreenMessage('info', sprintf(
55 $this->lng->txt('msg_no_perm_read_item'),
56 $this->parent_gui->getObjTitle()
57 ), true);
58
59 $this->ctrl->redirect($this->parent_gui, 'view');
60 }
61
62 $cmd = $this->ctrl->getCmd();
63
64 switch ($cmd) {
66 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
67 break;
68 case 'view':
70 // no break
72 case self::CMD_SAVE:
75 $this->$cmd();
76 break;
77 default:
78 throw new ilException("ilObjLearningSequenceContentGUI: Command not supported: $cmd");
79 }
80 }
81
82 protected function manageContent(): void
83 {
84 // Adds a btn to the gui which allows adding possible objects.
85 $this->parent_gui->showPossibleSubObjects();
86
87 $data = $this->parent_gui->getObject()->getLSItems();
88 // Sadly, ilTable2 only wants an array for fillRow, so we need to wrap this...
89 $data = array_map(fn($s) => [$s], $data);
90 $this->renderTable($data);
91 }
92
93 protected function renderTable(array $ls_items): void
94 {
95 $alert_icon = $this->ui_renderer->render(
96 $this->ui_factory->symbol()->icon()
97 ->custom(ilUtil::getImagePath("standard/icon_alert.svg"), $this->lng->txt("warning"))
98 ->withSize('small')
99 );
101 $this,
102 $this->parent_gui,
103 self::CMD_MANAGE_CONTENT,
104 $this->ctrl,
105 $this->lng,
106 $this->access,
107 $this->ui_factory,
108 $this->ui_renderer,
109 $this->ls_item_online_status,
110 $alert_icon
111 );
112
113 $table->setData($ls_items);
114 $table->addMultiCommand(self::CMD_CONFIRM_DELETE, $this->lng->txt("delete"));
115
116 $table->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
117
118 $this->tpl->setContent($table->getHtml());
119 }
120
124 protected function confirmDelete(): void
125 {
126 $this->parent_gui->deleteObject();
127 }
128
129 protected function delete(): void
130 {
131 $ref_ids = $this->post_wrapper->retrieve(
132 "id",
133 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
134 );
135
136 $this->parent_gui->getObject()->deletePostConditionsForSubObjects($ref_ids);
137
138 $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_deleted'), true);
139 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
140 }
141
145 public function getPossiblePostConditionsForType(string $type): array
146 {
147 return $this->parent_gui->getObject()->getPossiblePostConditionsForType($type);
148 }
149
150
151 public function getFieldName(string $field_name, int $ref_id): string
152 {
153 return implode('_', [$field_name, (string) $ref_id]);
154 }
155
156 protected function save(): void
157 {
158 $data = $this->parent_gui->getObject()->getLSItems();
159 $r = $this->refinery;
160
161 $updated = [];
162 foreach ($data as $lsitem) {
163 $ref_id = $lsitem->getRefId();
164 $online = $this->getFieldName(self::FIELD_ONLINE, $ref_id);
165 $order = $this->getFieldName(self::FIELD_ORDER, $ref_id);
166 $condition_type = $this->getFieldName(self::FIELD_POSTCONDITION_TYPE, $ref_id);
167
168 $condition_type = $this->post_wrapper->retrieve($condition_type, $r->kindlyTo()->string());
169 $online = $this->post_wrapper->retrieve($online, $r->byTrying([$r->kindlyTo()->bool(), $r->always(false)]));
170 $order = $this->post_wrapper->retrieve(
171 $order,
172 $r->in()->series([
173 $r->kindlyTo()->string(),
174 $r->custom()->transformation(fn($v) => ltrim($v, '0')),
175 $r->kindlyTo()->int()
176 ])
177 );
178
179 $condition = $lsitem->getPostCondition()
180 ->withConditionOperator($condition_type);
181 $updated[] = $lsitem
182 ->withOnline($online)
183 ->withOrderNumber($order)
184 ->withPostCondition($condition);
185 }
186
187 $this->parent_gui->getObject()->storeLSItems($updated);
188 $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_updated'), true);
189 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
190 }
191}
Builds data types.
Definition: Factory.php:36
Class ilAccessHandler Checks access for ILIAS objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
language handling
__construct(protected ilObjLearningSequenceGUI $parent_gui, protected ilCtrl $ctrl, protected ilGlobalTemplateInterface $tpl, protected ilLanguage $lng, protected ilAccess $access, protected ilConfirmationGUI $confirmation_gui, protected LSItemOnlineStatus $ls_item_online_status, protected ArrayBasedRequestWrapper $post_wrapper, protected Factory $refinery, protected ILIAS\UI\Factory $ui_factory, protected ILIAS\UI\Renderer $ui_renderer)
confirmDelete()
Handle the confirmDelete command.
Class ilObjLearningSequenceGUI @ilCtrl_isCalledBy ilObjLearningSequenceGUI: ilRepositoryGUI @ilCtrl_i...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31