ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
BaseCommands.php
Go to the documentation of this file.
1 <?php
20 
22 
27 abstract class BaseCommands
28 {
29  public const CMD_INDEX = "index";
30  public const CMD_ADD = "add";
31  public const CMD_CREATE = "create";
32  public const CMD_EDIT = "edit";
33  public const CMD_UPDATE = "update";
34  public const CMD_CONFIRM = "confirm";
35  public const CMD_CONFIRM_RECURSIVE = "confirmRecursive";
36  public const CMD_DELETE = "delete";
37  public const CMD_DELETE_RECURSIVE = "deleteRecursive";
38  public const CMD_CANCEL = "cancel";
39  public const AR_ID = "arid";
40 
41  private \ilLanguage $lng;
42  private \ilCtrl $ctrl;
43  private \ilTabsGUI $tabsGUI;
44  private \ilAccess $access;
45  private \ILIAS\HTTP\Services $http;
46  private \ilGlobalTemplateInterface $tpl;
47 
48  protected ?BaseCommands $parent_gui = null;
49 
50  protected function __construct()
51  {
52  global $DIC;
53 
54  $this->lng = $DIC->language();
55  $this->lng->loadLanguageModule("orgu");
56  $this->ctrl = $DIC->ctrl();
57  $this->tabsGUI = $DIC->tabs();
58  $this->access = $DIC->access();
59  $this->http = $DIC->http();
60  $this->tpl = $DIC->ui()->mainTemplate();
61  }
62 
63  public function getParentGui(): ?BaseCommands
64  {
65  return $this->parent_gui;
66  }
67 
68  public function setParentGui(BaseCommands $parent_gui)
69  {
70  $this->parent_gui = $parent_gui;
71  }
72 
73  abstract protected function index(): void;
74 
75  protected function getPossibleNextClasses(): array
76  {
77  return array();
78  }
79 
80  protected function getActiveTabId(): ?string
81  {
82  return null;
83  }
84 
88  protected function cancel(): void
89  {
90  $this->ctrl->redirect($this, self::CMD_INDEX);
91  }
92 
93  protected function setContent(string $html)
94  {
95  $this->tpl->setContent($html);
96  }
97 
101  public function executeCommand()
102  {
103  global $DIC;
104  $this->ctrl = $DIC->ctrl();
105  $this->http = $DIC->http();
106  $this->access = $DIC->access();
107  $this->tabsGUI = $DIC->tabs();
108  $this->lng = $DIC->language();
109  $this->tpl = $DIC->ui()->mainTemplate();
110  $this->lng->loadLanguageModule("orgu");
111 
112  $cmd = $this->ctrl->getCmd(self::CMD_INDEX);
113  $next_class = $this->ctrl->getNextClass();
114  if ($next_class) {
115  foreach ($this->getPossibleNextClasses() as $class) {
116  if (strtolower($class) === $next_class) {
117  $instance = new $class();
118  if ($instance instanceof BaseCommands) {
119  $instance->setParentGui($this);
120  $this->ctrl->forwardCommand($instance);
121  }
122 
123  return;
124  }
125  }
126  }
127 
128  if ($this->getActiveTabId()) {
129  $this->tabsGUI->activateTab($this->getActiveTabId());
130  }
131 
132  switch ($cmd) {
133  default:
134  if ($this->checkRequestReferenceId()) {
135  $this->{$cmd}();
136  }
137  break;
138  }
139  }
140 
141  protected function pushSubTab(string $subtab_id, string $url)
142  {
143  $this->tabsGUI->addSubTab($subtab_id, $this->lng->txt($subtab_id), $url);
144  }
145 
146  protected function activeSubTab(string $subtab_id)
147  {
148  $this->tabsGUI->activateSubTab($subtab_id);
149  }
150 
151  protected function checkRequestReferenceId()
152  {
156  $ref_id = $this->getParentRefId();
157  if ($ref_id) {
158  return $this->access->checkAccess("read", "", $ref_id);
159  }
160 
161  return true;
162  }
163 
164  protected function getParentRefId(): ?int
165  {
166  $ref_id = $this->http->request()->getQueryParams()["ref_id"];
167 
168  return $ref_id;
169  }
170 
171  public function addSubTabs(): void
172  {
173  }
174 }
global $DIC
Definition: feed.php:28
pushSubTab(string $subtab_id, string $url)
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
setParentGui(BaseCommands $parent_gui)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url