ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjLearningSequenceContentGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  $cmd = $this->ctrl->getCmd();
54 
55  switch ($cmd) {
56  case self::CMD_CANCEL:
57  $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
58  break;
59  case self::CMD_MANAGE_CONTENT:
60  case self::CMD_SAVE:
61  case self::CMD_DELETE:
62  case self::CMD_CONFIRM_DELETE:
63  $this->$cmd();
64  break;
65  default:
66  throw new ilException("ilObjLearningSequenceContentGUI: Command not supported: $cmd");
67  }
68  }
69 
70  protected function manageContent(): void
71  {
72  // Adds a btn to the gui which allows adding possible objects.
73  $this->parent_gui->showPossibleSubObjects();
74 
75  $data = $this->parent_gui->getObject()->getLSItems();
76  // Sadly, ilTable2 only wants an array for fillRow, so we need to wrap this...
77  $data = array_map(fn($s) => [$s], $data);
78  $this->renderTable($data);
79  }
80 
81  protected function renderTable(array $ls_items): void
82  {
83  $alert_icon = $this->ui_renderer->render(
84  $this->ui_factory->symbol()->icon()
85  ->custom(ilUtil::getImagePath("standard/icon_alert.svg"), $this->lng->txt("warning"))
86  ->withSize('small')
87  );
89  $this,
90  $this->parent_gui,
91  self::CMD_MANAGE_CONTENT,
92  $this->ctrl,
93  $this->lng,
94  $this->access,
95  $this->ui_factory,
96  $this->ui_renderer,
97  $this->ls_item_online_status,
98  $alert_icon
99  );
100 
101  $table->setData($ls_items);
102  $table->addMultiCommand(self::CMD_CONFIRM_DELETE, $this->lng->txt("delete"));
103 
104  $table->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
105 
106  $this->tpl->setContent($table->getHtml());
107  }
108 
112  protected function confirmDelete(): void
113  {
114  $this->parent_gui->deleteObject();
115  }
116 
117  protected function delete(): void
118  {
119  $ref_ids = $this->post_wrapper->retrieve(
120  "id",
121  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
122  );
123 
124  $this->parent_gui->getObject()->deletePostConditionsForSubObjects($ref_ids);
125 
126  $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_deleted'), true);
127  $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
128  }
129 
133  public function getPossiblePostConditionsForType(string $type): array
134  {
135  return $this->parent_gui->getObject()->getPossiblePostConditionsForType($type);
136  }
137 
138 
139  public function getFieldName(string $field_name, int $ref_id): string
140  {
141  return implode('_', [$field_name, (string) $ref_id]);
142  }
143 
144  protected function save(): void
145  {
146  $data = $this->parent_gui->getObject()->getLSItems();
148 
149  $updated = [];
150  foreach ($data as $lsitem) {
151  $ref_id = $lsitem->getRefId();
152  $online = $this->getFieldName(self::FIELD_ONLINE, $ref_id);
153  $order = $this->getFieldName(self::FIELD_ORDER, $ref_id);
154  $condition_type = $this->getFieldName(self::FIELD_POSTCONDITION_TYPE, $ref_id);
155 
156  $condition_type = $this->post_wrapper->retrieve($condition_type, $r->kindlyTo()->string());
157  $online = $this->post_wrapper->retrieve($online, $r->byTrying([$r->kindlyTo()->bool(), $r->always(false)]));
158  $order = $this->post_wrapper->retrieve(
159  $order,
160  $r->in()->series([
161  $r->kindlyTo()->string(),
162  $r->custom()->transformation(fn($v) => ltrim($v, '0')),
163  $r->kindlyTo()->int()
164  ])
165  );
166 
167  $condition = $lsitem->getPostCondition()
168  ->withConditionOperator($condition_type);
169  $updated[] = $lsitem
170  ->withOnline($online)
171  ->withOrderNumber($order)
172  ->withPostCondition($condition);
173  }
174 
175  $this->parent_gui->getObject()->storeLSItems($updated);
176  $this->tpl->setOnScreenMessage("success", $this->lng->txt('entries_updated'), true);
177  $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
178  }
179 }
Class ChatMainBarProvider .
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
int $updated
Timestamp for when the object was last updated.
Definition: System.php:158
$ref_id
Definition: ltiauth.php:67
confirmDelete()
Handle the confirmDelete command.
$lng
Class ilObjLearningSequenceGUI ilObjLearningSequenceGUI: ilRepositoryGUI ilObjLearningSequenceGUI: ...
__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)
$r
Refinery Factory $refinery