ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjLearningSequenceContentGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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) {
46  case self::CMD_CANCEL:
47  $this->ctrl->redirect($this, self::CMD_MANAGE_CONTENT);
48  break;
49  case self::CMD_MANAGE_CONTENT:
50  case self::CMD_SAVE:
51  case self::CMD_DELETE:
52  case self::CMD_CONFIRM_DELETE:
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 (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) {
104  $obj = ilObjectFactory::getInstanceByRefId($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 }
This class provides processing control methods.
$type
$tpl
Definition: ilias.php:10
Class ilAccessHandler.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
confirmDelete()
Handle the confirmDelete command.
$lng
special template class to simplify handling of ITX/PEAR
Class ilObjLearningSequenceContentGUI.
__construct(ilObjLearningSequenceGUI $parent_gui, ilCtrl $ctrl, ilTemplate $tpl, ilLanguage $lng, ilAccess $access, ilConfirmationGUI $confirmation_gui, LSItemOnlineStatus $ls_item_online_status)
$post
Definition: post.php:34
User interface class for advanced drop-down selection lists.
$i
Definition: disco.tpl.php:19
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
language handling
Class ilObjLearningSequenceGUI.
if(empty($password)) $table
Definition: pwgen.php:24
$_POST["username"]
Confirmation screen class.
$data
Definition: bench.php:6