ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
35  default:
36  if (!($cmd = $this->ctrl->getCmd()))
37  {
38  $cmd = "initShareForm";
39  }
40  $this->$cmd();
41  break;
42  }
43  return true;
44  }
45 
46  public function initShareForm(ilPropertyFormGUI $form = null)
47  {
48  if(!($form instanceof ilPropertyFormGUI))
49  {
50  $form = $this->getShareForm();
51  }
52  $this->tpl->setContent($form->getHTML());
53  }
54 
55  public function getShareForm()
56  {
57  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
58  $form = new ilPropertyFormGUI();
59 
60  $form->setTitle($this->lng->txt("share_content"));
61  $form->setId('share_usr');
62 
63  $form->setFormAction($this->ctrl->getFormAction($this, 'saveShare'));
64 
65  $inp = new ilTextInputGUI($this->lng->txt("share_with"), 'name');
66  $inp->setSize(20);
67  $form->addItem($inp);
68 
69  $form->addCommandButton('saveShare', $this->lng->txt("share"));
70  $form->addCommandButton('cancel', $this->lng->txt("cancel"));
71 
72  return $form;
73  }
74 
75  protected function saveShare()
76  {
77  $form = $this->getShareForm();
78 
79  if($form->checkInput())
80  {
81  if($user_id = ilObjUser::_lookupId($form->getInput('name')))
82  {
83  $existing = $this->wsp_access_handler->getPermissions($this->wsp_node_id);
84 
85  if(!in_array($user_id, $existing))
86  {
87  $this->wsp_access_handler->addPermission($this->wsp_node_id, $user_id);
88  ilUtil::sendSuccess($this->lng->txt("element_shared"),true);
89  }
90  else
91  {
92  ilUtil::sendInfo($this->lng->txt("element_already_shared"),true);
93  }
94  $this->ctrl->returnToParent($this);
95  }
96  else
97  {
98  ilUtil::sendFailure($this->lng->txt('search_no_match'),true);
99  }
100  }
101  $this->ctrl->redirect($this);
102  }
103 
104  public function cancel()
105  {
106  $this->ctrl->returnToParent($this);
107  }
108 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a property form user interface.
initShareForm(ilPropertyFormGUI $form=null)
$cmd
Definition: sahs_server.php:35
static _lookupId($a_user_str)
Lookup id by login.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
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)
global $DIC