ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilSingleUserShareGUI.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ?int $wsp_node_id;
27 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
29
30 public function __construct(
32 ?int $wsp_node_id = null
33 ) {
34 global $DIC;
35
36 $this->tpl = $DIC->ui()->mainTemplate();
37 $this->ctrl = $DIC->ctrl();
38 $this->lng = $DIC->language();
39
40 // personal workspace
41 $this->wsp_access_handler = $wsp_access_handler;
42 $this->wsp_node_id = $wsp_node_id;
43 }
44
45 public function executeCommand(): void
46 {
47 $forward_class = $this->ctrl->getNextClass($this);
48
49 switch ($forward_class) {
50 default:
51 if (!($cmd = $this->ctrl->getCmd())) {
52 $cmd = "initShareForm";
53 }
54 $this->$cmd();
55 break;
56 }
57 }
58
59 public function initShareForm(?ilPropertyFormGUI $form = null): void
60 {
61 if (!($form instanceof ilPropertyFormGUI)) {
62 $form = $this->getShareForm();
63 }
64 $this->tpl->setContent($form->getHTML());
65 }
66
68 {
69 $form = new ilPropertyFormGUI();
70
71 $form->setTitle($this->lng->txt("share_content"));
72 $form->setId('share_usr');
73
74 $form->setFormAction($this->ctrl->getFormAction($this, 'saveShare'));
75
76 $inp = new ilTextInputGUI($this->lng->txt("share_with"), 'name');
77 $inp->setSize(20);
78 $form->addItem($inp);
79
80 $form->addCommandButton('saveShare', $this->lng->txt("share"));
81 $form->addCommandButton('cancel', $this->lng->txt("cancel"));
82
83 return $form;
84 }
85
86 protected function saveShare(): void
87 {
88 $form = $this->getShareForm();
89
90 if ($form->checkInput()) {
91 if ($user_id = ilObjUser::_lookupId((string) $form->getInput('name'))) {
92 $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
93
94 if (!in_array($user_id, $existing)) {
95 $this->wsp_access_handler->addPermission($this->wsp_node_id, $user_id);
96 $this->tpl->setOnScreenMessage('success', $this->lng->txt("element_shared"), true);
97 } else {
98 $this->tpl->setOnScreenMessage('info', $this->lng->txt("element_already_shared"), true);
99 }
100 $this->ctrl->returnToParent($this);
101 } else {
102 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('search_no_match'), true);
103 }
104 }
105 $this->ctrl->redirect($this);
106 }
107
108 public function cancel(): void
109 {
110 $this->ctrl->returnToParent($this);
111 }
112}
Class ilCtrl provides processing control methods.
language handling
static _lookupId(string|array $a_user_str)
Access handler for portfolio NOTE: This file needs to stay in the classes directory,...
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPortfolioAccessHandler|ilWorkspaceAccessHandler|null $wsp_access_handler=null, ?int $wsp_node_id=null)
initShareForm(?ilPropertyFormGUI $form=null)
ilPortfolioAccessHandler ilWorkspaceAccessHandler $wsp_access_handler
ilGlobalTemplateInterface $tpl
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26