ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSingleUserShareGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  protected $tpl;
13  protected $ctrl;
14  protected $lng;
15 
16  public function __construct($wsp_access_handler = null, $wsp_node_id = null)
17  {
18  global $DIC;
19 
20  $this->tpl = $DIC['tpl'];
21  $this->ctrl = $DIC['ilCtrl'];
22  $this->lng = $DIC['lng'];
23 
24  // personal workspace
25  $this->wsp_access_handler = $wsp_access_handler;
26  $this->wsp_node_id = $wsp_node_id;
27  }
28 
29  public function executeCommand()
30  {
31  $forward_class = $this->ctrl->getNextClass($this);
32 
33  switch ($forward_class) {
34  default:
35  if (!($cmd = $this->ctrl->getCmd())) {
36  $cmd = "initShareForm";
37  }
38  $this->$cmd();
39  break;
40  }
41  return true;
42  }
43 
44  public function initShareForm(ilPropertyFormGUI $form = null)
45  {
46  if (!($form instanceof ilPropertyFormGUI)) {
47  $form = $this->getShareForm();
48  }
49  $this->tpl->setContent($form->getHTML());
50  }
51 
52  public function getShareForm()
53  {
54  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
55  $form = new ilPropertyFormGUI();
56 
57  $form->setTitle($this->lng->txt("share_content"));
58  $form->setId('share_usr');
59 
60  $form->setFormAction($this->ctrl->getFormAction($this, 'saveShare'));
61 
62  $inp = new ilTextInputGUI($this->lng->txt("share_with"), 'name');
63  $inp->setSize(20);
64  $form->addItem($inp);
65 
66  $form->addCommandButton('saveShare', $this->lng->txt("share"));
67  $form->addCommandButton('cancel', $this->lng->txt("cancel"));
68 
69  return $form;
70  }
71 
72  protected function saveShare()
73  {
74  $form = $this->getShareForm();
75 
76  if ($form->checkInput()) {
77  if ($user_id = ilObjUser::_lookupId($form->getInput('name'))) {
78  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
79 
80  if (!in_array($user_id, $existing)) {
81  $this->wsp_access_handler->addPermission($this->wsp_node_id, $user_id);
82  ilUtil::sendSuccess($this->lng->txt("element_shared"), true);
83  } else {
84  ilUtil::sendInfo($this->lng->txt("element_already_shared"), true);
85  }
86  $this->ctrl->returnToParent($this);
87  } else {
88  ilUtil::sendFailure($this->lng->txt('search_no_match'), true);
89  }
90  }
91  $this->ctrl->redirect($this);
92  }
93 
94  public function cancel()
95  {
96  $this->ctrl->returnToParent($this);
97  }
98 }
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
initShareForm(ilPropertyFormGUI $form=null)
static _lookupId($a_user_str)
Lookup id by login.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(isset($_POST['submit'])) $form
setSize($a_size)
Set Size.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct($wsp_access_handler=null, $wsp_node_id=null)