ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BaseCommands.php
Go to the documentation of this file.
1 <?php
2 
21 
30 
35 abstract class BaseCommands
36 {
37  public const CMD_INDEX = "index";
38  public const CMD_DEFAULT_PERMISSIONS = "defaultPermissions";
39  public const CMD_ADD = "add";
40  public const CMD_CREATE = "create";
41  public const CMD_EDIT = "edit";
42  public const CMD_UPDATE = "update";
43  public const CMD_CONFIRM = "confirm";
44  public const CMD_DELETE = "delete";
45  public const CMD_CANCEL = "cancel";
46  public const AR_ID = "arid";
47 
48  protected \ilLanguage $lng;
49  protected \ilCtrl $ctrl;
50  private \ilTabsGUI $tabsGUI;
51  protected \ilAccess $access;
52  protected \ILIAS\HTTP\Services $http;
53  protected \ilGlobalTemplateInterface $tpl;
54  protected ?BaseCommands $parent_gui = null;
55 
57  protected ?URLBuilderToken $action_token = null;
60  protected Refinery $refinery;
62  protected \ILIAS\HTTP\Wrapper\ArrayBasedRequestWrapper $query;
63 
66 
67  protected function __construct(
68  protected array $query_namespace = ['orgu', 'posedit']
69  ) {
70  global $DIC;
71 
72  $this->lng = $DIC->language();
73  $this->lng->loadLanguageModule("orgu");
74  $this->ctrl = $DIC->ctrl();
75  $this->tabsGUI = $DIC->tabs();
76  $this->access = $DIC->access();
77  $this->http = $DIC->http();
78  $this->tpl = $DIC->ui()->mainTemplate();
79  $this->refinery = $DIC['refinery'];
80  $this->query = $DIC->http()->wrapper()->query();
81  $this->request = $DIC->http()->request();
82  $this->data_factory = new DataFactory();
83 
84  $here_uri = $this->data_factory->uri(
85  $this->request->getUri()->__toString()
86  );
87  $this->url_builder = new URLBuilder($here_uri);
88  list($url_builder, $action_token, $row_id_token) =
89  $this->url_builder->acquireParameters($this->query_namespace, "action", "rowid");
90  $this->url_builder = $url_builder;
91  $this->action_token = $action_token;
92  $this->row_id_token = $row_id_token;
93 
94  $this->ui_factory = $DIC['ui.factory'];
95  $this->ui_renderer = $DIC['ui.renderer'];
96  }
97 
98  public function getParentGui(): ?BaseCommands
99  {
100  return $this->parent_gui;
101  }
102 
103  public function setParentGui(BaseCommands $parent_gui)
104  {
105  $this->parent_gui = $parent_gui;
106  }
107 
108  abstract protected function index(): void;
109 
110  protected function getPossibleNextClasses(): array
111  {
112  return array();
113  }
114 
115  protected function getActiveTabId(): ?string
116  {
117  return null;
118  }
119 
123  protected function cancel(): void
124  {
125  $this->ctrl->redirect($this, self::CMD_INDEX);
126  }
127 
128  protected function setContent(string $html)
129  {
130  $this->tpl->setContent($html);
131  }
132 
136  public function executeCommand()
137  {
138  global $DIC;
139  $this->ctrl = $DIC->ctrl();
140  $this->http = $DIC->http();
141  $this->access = $DIC->access();
142  $this->tabsGUI = $DIC->tabs();
143  $this->lng = $DIC->language();
144  $this->tpl = $DIC->ui()->mainTemplate();
145  $this->lng->loadLanguageModule("orgu");
146 
147  $cmd = $this->ctrl->getCmd(self::CMD_INDEX);
148 
149  if ($this->action_token &&
150  $this->query->has($this->action_token->getName())
151  ) {
152  $cmd = $this->query->retrieve(
153  $this->action_token->getName(),
154  $this->refinery->to()->string()
155  );
156  }
157 
158  $next_class = $this->ctrl->getNextClass();
159  if ($next_class) {
160  foreach ($this->getPossibleNextClasses() as $class) {
161  if (strtolower($class) === $next_class) {
162  $instance = new $class();
163  if ($instance instanceof BaseCommands) {
164  $instance->setParentGui($this);
165  $this->ctrl->forwardCommand($instance);
166  }
167 
168  return;
169  }
170  }
171  }
172 
173  if ($this->getActiveTabId()) {
174  $this->tabsGUI->activateTab($this->getActiveTabId());
175  }
176 
177  switch ($cmd) {
178  default:
179  if ($this->checkRequestReferenceId()) {
180  $this->{$cmd}();
181  }
182  break;
183  }
184  }
185 
186  protected function pushSubTab(string $subtab_id, string $url)
187  {
188  $this->tabsGUI->addSubTab($subtab_id, $this->lng->txt($subtab_id), $url);
189  }
190 
191  protected function activeSubTab(string $subtab_id)
192  {
193  $this->tabsGUI->activateSubTab($subtab_id);
194  }
195 
196  protected function checkRequestReferenceId()
197  {
201  $ref_id = $this->getParentRefId();
202  if ($ref_id) {
203  return $this->access->checkAccess("read", "", $ref_id);
204  }
205 
206  return true;
207  }
208 
209  protected function getParentRefId(): ?int
210  {
211  $ref_id = $this->http->request()->getQueryParams()["ref_id"];
212 
213  return $ref_id;
214  }
215 
216  public function addSubTabs(): void
217  {
218  }
219 
220  protected function getRowIdFromQuery(): int
221  {
222  if ($this->query->has($this->row_id_token->getName())) {
223  return $this->query->retrieve(
224  $this->row_id_token->getName(),
225  $this->refinery->custom()->transformation(fn($v) => (int) array_shift($v))
226  );
227  }
228  throw new \Exception('no position-id in query');
229  }
230 }
__construct(protected array $query_namespace=['orgu', 'posedit'])
pushSubTab(string $subtab_id, string $url)
$url
Definition: shib_logout.php:63
ILIAS HTTP Wrapper ArrayBasedRequestWrapper $query
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
URLBuilder.
Definition: URLBuilder.php:39