ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilRemoteObjectBaseGUI.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
23 abstract class ilRemoteObjectBaseGUI extends ilObject2GUI
24 {
25  private ilLogger $logger;
26 
27  public const TAB_ID_PERMISSIONS = "id_permissions";
28 
29  public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
30  {
31  global $DIC;
32 
33  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
34 
35  $this->logger = $DIC->logger()->wsrv();
36 
37  $this->lng->loadLanguageModule('ecs');
38  }
39 
40  public function executeCommand(): void
41  {
42  $next_class = $this->ctrl->getNextClass($this);
43  $cmd = $this->ctrl->getCmd();
44 
45  $this->prepareOutput();
46  $this->logger->info("Can write:" . print_r($this->checkPermissionBool('write'), true));
47 
48  switch ($next_class) {
49  case 'ilinfoscreengui':
50  // forwards command
51  $this->infoScreen();
52  break;
53 
54  case 'ilpermissiongui':
55  $this->tabs_gui->activateTab('id_permissions');
56  $this->ctrl->forwardCommand(new ilPermissionGUI($this));
57  break;
58 
59  case "ilcommonactiondispatchergui":
61  $this->ctrl->forwardCommand($gui);
62  break;
63 
64  case strtolower(ilECSUserConsentModalGUI::class):
65  $consent_gui = new ilECSUserConsentModalGUI(
66  $this->user->getId(),
68  $this
69  );
70  $this->ctrl->setReturn($this, 'call');
71  $this->ctrl->forwardCommand($consent_gui);
72  break;
73 
74  default:
75  if (!$cmd || $cmd === 'view') {
76  $cmd = "infoScreen";
77  }
78  $cmd .= "Object";
79  $this->logger->info("cmd before call:" . print_r($cmd, true));
80  $this->$cmd();
81  break;
82  }
83  $this->logger->info("cmd:" . print_r($cmd, true));
84  }
85 
89  public function showObject(): void
90  {
91  if ($this->user->getId() === ANONYMOUS_USER_ID ||
92  $this->object->isLocalObject()) {
93  $this->ctrl->redirectToURL($this->object->getRemoteLink());
94  } else {
95  $link = $this->object->getFullRemoteLink();
96  $this->ctrl->redirectToURL($link);
97  }
98  }
99 
103  protected function setTabs(): void
104  {
105  if ($this->checkPermissionBool('visible')) {
106  $this->tabs_gui->addTab(
107  "info",
108  $this->lng->txt("info_short"),
109  $this->ctrl->getLinkTarget($this, "infoScreen")
110  );
111  }
112 
113  if ($this->checkPermissionBool('write')) {
114  $this->tabs_gui->addTab(
115  "edit",
116  $this->lng->txt("edit"),
117  $this->ctrl->getLinkTarget($this, "edit")
118  );
119  }
120  if ($this->checkPermissionBool("edit_permission")) {
121  $this->tabs_gui->addTab(
122  self::TAB_ID_PERMISSIONS,
123  $this->lng->txt("perm_settings"),
124  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm")
125  );
126  }
127  }
128 
134  public function callObject(): bool
135  {
137  $this->getType(),
138  $this->object->getRefId(),
139  $this->object->getId(),
140  $this->user->getId()
141  );
142 
143 
144  // check if the assigned object is hosted on the same installation
145  $link = $this->object->getFullRemoteLink();
146  if ($link) {
147  $this->ctrl->redirectToURL($link);
148  return true;
149  }
150 
151  $this->tpl->setOnScreenMessage('failure', 'Cannot call remote object.');
152  $this->infoScreenObject();
153  return false;
154  }
155 
159  public function infoScreenObject(): void
160  {
161  $this->ctrl->redirectByClass(ilInfoScreenGUI::class, "showSummary");
162  }
163 
167  public function infoScreen(): void
168  {
169  if (!$this->access->checkAccess("visible", "", $this->object->getRefId())) {
170  $this->error->raiseError(
171  $this->lng->txt('msg_no_perm_read'),
172  $this->error->MESSAGE
173  );
174  }
175 
176  $this->ctrl->setReturn($this, 'call');
177  $consent_gui = new ilECSUserConsentModalGUI(
178  $this->user->getId(),
180  $this
181  );
182  $consent_gui->addLinkToToolbar($this->toolbar);
183 
184  $this->tabs_gui->activateTab('info');
185 
186  $info = new ilInfoScreenGUI($this);
187 
188  $info->addSection($this->lng->txt('ecs_general_info'));
189  $info->addProperty($this->lng->txt('title'), $this->object->getTitle());
190  if ($this->object->getOrganization()) {
191  $info->addProperty($this->lng->txt('organization'), $this->object->getOrganization());
192  }
193  if ($this->object->getDescription()) {
194  $info->addProperty($this->lng->txt('description'), $this->object->getDescription());
195  }
196  if ($this->object->getLocalInformation()) {
197  $info->addProperty($this->lng->txt('ecs_local_information'), $this->object->getLocalInformation());
198  }
199 
200  $this->addCustomInfoFields($info);
201 
202  $record_gui = new ilAdvancedMDRecordGUI(
204  $this->getType(),
205  $this->object->getId()
206  );
207  $record_gui->setInfoObject($info);
208  $record_gui->parse();
209 
210  $this->ctrl->forwardCommand($info);
211  }
212 
218  protected function addCustomInfoFields(ilInfoScreenGUI $a_info): void
219  {
220  // can be overwritten by subclasses
221  }
222 
226  public function editObject(ilPropertyFormGUI $form = null): void
227  {
228  if (!$this->access->checkAccess("write", "", $this->object->getRefId())) {
229  $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
230  }
231  $this->logger->info("Can write:" . print_r($this->checkPermissionBool('write'), true));
232  $this->tabs_gui->activateTab('edit');
233 
234  if (!$form) {
235  $form = $this->initEditForm();
236  }
237  $this->tpl->setContent($form->getHTML());
238  }
239 
243  protected function initEditForm(): ilPropertyFormGUI
244  {
245  $form = new ilPropertyFormGUI();
246  $form->setFormAction($this->ctrl->getFormAction($this));
247  $form->setTitle($this->lng->txt('ecs_general_info'));
248  $form->addCommandButton('update', $this->lng->txt('save'));
249  $form->addCommandButton('edit', $this->lng->txt('cancel'));
250 
251  $text = new ilTextInputGUI($this->lng->txt('title'), 'title');
252  $text->setValue($this->object->getTitle());
253  $text->setSize(min(40, ilObject::TITLE_LENGTH));
254  $text->setMaxLength(ilObject::TITLE_LENGTH);
255  $text->setDisabled(true);
256  $form->addItem($text);
257 
258  $area = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
259  $area->setValue($this->object->getDescription());
260  $area->setRows(3);
261  $area->setCols(80);
262  $area->setDisabled(true);
263  $form->addItem($area);
264 
265  $area = new ilTextAreaInputGUI($this->lng->txt('ecs_local_information'), 'local_info');
266  $area->setValue($this->object->getLocalInformation());
267  $area->setRows(3);
268  $area->setCols(80);
269  $form->addItem($area);
270 
271  $this->addCustomEditForm($form);
272 
273  $record_gui = new ilAdvancedMDRecordGUI(
275  $this->getType(),
276  $this->object->getId()
277  );
278  $record_gui->setPropertyForm($form);
279  $record_gui->parse();
280 
281  return $form;
282  }
283 
289  protected function addCustomEditForm(ilPropertyFormGUI $a_form): void
290  {
291  }
292 
293  public function updateObject(): void
294  {
295  if (!$this->checkPermissionBool('write')) {
296  $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->MESSAGE);
297  }
298 
299  $form = $this->initEditForm();
300  if ($form->checkInput()) {
301  $this->object->setLocalInformation($form->getInput('local_info'));
302 
303  $this->updateCustomValues($form);
304 
305  $this->object->update();
306 
307  // Save advanced meta data
308  $record_gui = new ilAdvancedMDRecordGUI(
310  $this->getType(),
311  $this->object->getId()
312  );
313  $record_gui->importEditFormPostValues();
314  $record_gui->writeEditForm();
315 
316  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"));
317  $this->editObject();
318  }
319 
320  $form->setValuesByPost();
321  $this->editObject($form);
322  }
323 
329  protected function updateCustomValues(ilPropertyFormGUI $a_form): void
330  {
331  }
332 
333  public static function _goto(string $a_target): void
334  {
335  global $DIC;
336 
337  $ilAccess = $DIC->access();
338  $ilErr = $DIC["ilErr"];
339  $lng = $DIC->language();
340  if ($ilAccess->checkAccess("read", "", (int) $a_target)) {
341  ilObjectGUI::_gotoRepositoryNode((int) $a_target);
342  }
343 
344  if ($ilAccess->checkAccess("visible", "", (int) $a_target)) {
345  ilObjectGUI::_gotoRepositoryNode((int) $a_target, "infoScreen");
346  }
347  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
348  }
349 }
setPropertyForm(ilPropertyFormGUI $form)
const ANONYMOUS_USER_ID
Definition: constants.php:27
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
editObject(ilPropertyFormGUI $form=null)
Edit settings.
New implementation of ilObjectGUI.
const TITLE_LENGTH
importEditFormPostValues()
Load edit form values from post.
static _gotoRepositoryNode(int $ref_id, string $cmd="")
addCustomInfoFields(ilInfoScreenGUI $a_info)
Add custom fields to info screen.
prepareOutput(bool $show_sub_objects=true)
$ilErr
Definition: raiseError.php:17
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
infoScreenObject()
this one is called from the info button in the repository
getType()
Functions that must be overwritten.
$text
Definition: xapiexit.php:21
static _recordReadEvent(string $a_type, int $a_ref_id, int $obj_id, int $usr_id, bool $isCatchupWriteEvents=true, $a_ext_rc=null, $a_ext_time=null)
global $DIC
Definition: shib_login.php:25
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
setInfoObject(ilInfoScreenGUI $info)
get info sections
updateCustomValues(ilPropertyFormGUI $a_form)
Update object custom values.
initEditForm()
Init edit settings form.
static _goto(string $a_target)
addCustomEditForm(ilPropertyFormGUI $a_form)
Add custom fields to edit form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call