ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjLearningSequenceContentGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
12{
13 const CMD_MANAGE_CONTENT = "manageContent";
14 const CMD_SAVE = "save";
15 const CMD_DELETE = "delete";
16 const CMD_CONFIRM_DELETE = "confirmDelete";
17 const CMD_CANCEL = "cancel";
18
19 const FIELD_ORDER = 'f_order';
20 const FIELD_ONLINE = 'f_online';
21 const FIELD_POSTCONDITION_TYPE = 'f_pct';
22
23 public function __construct(
24 ilObjLearningSequenceGUI $parent_gui,
25 ilCtrl $ctrl,
28 ilAccess $access,
29 ilConfirmationGUI $confirmation_gui,
30 LSItemOnlineStatus $ls_item_online_status
31 ) {
32 $this->parent_gui = $parent_gui;
33 $this->ctrl = $ctrl;
34 $this->tpl = $tpl;
35 $this->lng = $lng;
36 $this->access = $access;
37 $this->confirmation_gui = $confirmation_gui;
38 $this->ls_item_online_status = $ls_item_online_status;
39 }
40
41 public function executeCommand()
42 {
43 $cmd = $this->ctrl->getCmd();
44
45 switch ($cmd) {
47 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
48 break;
50 case self::CMD_SAVE:
53 $this->$cmd();
54 break;
55 default:
56 throw new ilException("ilObjLearningSequenceContentGUI: Command not supported: $cmd");
57 }
58 }
59
60 protected function manageContent()
61 {
62 // Adds a btn to the gui which allows adding possible objects.
63 $this->parent_gui->showPossibleSubObjects();
64
65 $data = $this->parent_gui->getObject()->getLSItems();
66 $this->renderTable($data);
67 }
68
69 protected function renderTable(array $ls_items)
70 {
72 $this,
73 self::CMD_MANAGE_CONTENT,
74 $this->ctrl,
75 $this->lng,
76 $this->access,
78 $this->ls_item_online_status
79 );
80
81 $table->setData($ls_items);
82 $table->addMultiCommand(self::CMD_CONFIRM_DELETE, $this->lng->txt("delete"));
83
84 $table->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
85
86 $this->tpl->setContent($table->getHtml());
87 }
88
94 protected function confirmDelete()
95 {
96 $ref_ids = $_POST["id"];
97
98 if (!$ref_ids || count($ref_ids) < 1) {
99 ilUtil::sendInfo($this->lng->txt('no_entries_selected_for_delete'), true);
100 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
101 }
102
103 foreach ($ref_ids as $ref_id) {
105 $this->confirmation_gui->addItem("id[]", $ref_id, $obj->getTitle());
106 }
107
108 $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
109 $this->confirmation_gui->setHeaderText($this->lng->txt("delete_confirmation"));
110 $this->confirmation_gui->setConfirm($this->lng->txt("confirm"), self::CMD_DELETE);
111 $this->confirmation_gui->setCancel($this->lng->txt("cancel"), self::CMD_CANCEL);
112
113 $this->tpl->setContent($this->confirmation_gui->getHTML());
114 }
115
116 protected function delete()
117 {
118 $ref_ids = $_POST["id"];
119
120 $ref_ids = array_map(function ($i) {
121 return (int) $i;
122 }, $ref_ids);
123
124 $this->parent_gui->getObject()->deletePostConditionsForSubObjects($ref_ids);
125
126 ilUtil::sendSuccess($this->lng->txt('entries_deleted'), true);
127 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
128 }
129
130
131 public function getPossiblePostConditionsForType(string $type) : array
132 {
133 return $this->parent_gui->getObject()->getPossiblePostConditionsForType($type);
134 }
135
136
137 public function getFieldName(string $field_name, int $ref_id) : string
138 {
139 return implode('_', [$field_name, (string) $ref_id]);
140 }
141
142 protected function save()
143 {
144 $post = $_POST;
145 $data = $this->parent_gui->getObject()->getLSItems();
146
147 $updated = [];
148 foreach ($data as $lsitem) {
149 $ref_id = $lsitem->getRefId();
150 $online = $this->getFieldName(self::FIELD_ONLINE, $ref_id);
151 $order = $this->getFieldName(self::FIELD_ORDER, $ref_id);
152 $condition_type = $this->getFieldName(self::FIELD_POSTCONDITION_TYPE, $ref_id);
153
154 $condition = $lsitem->getPostCondition()
155 ->withConditionOperator($post[$condition_type]);
156 $updated[] = $lsitem
157 ->withOnline((bool) $post[$online])
158 ->withOrderNumber((int) $post[$order])
159 ->withPostCondition($condition);
160 }
161
162 $this->parent_gui->getObject()->storeLSItems($updated);
163
164 ilUtil::sendSuccess($this->lng->txt('entries_updated'), true);
165 $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
166 }
167}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
User interface class for advanced drop-down selection lists.
Confirmation screen class.
This class provides processing control methods.
Base class for ILIAS Exception handling.
language handling
Class ilObjLearningSequenceContentGUI.
__construct(ilObjLearningSequenceGUI $parent_gui, ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilAccess $access, ilConfirmationGUI $confirmation_gui, LSItemOnlineStatus $ls_item_online_status)
confirmDelete()
Handle the confirmDelete command.
Class ilObjLearningSequenceGUI.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$i
Definition: metadata.php:24
$type
$lng
$data
Definition: storeScorm.php:23
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl