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