ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOrgUnitUserAssignmentGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
13 {
14  public function executeCommand()
15  {
16  $r = $this->http()->request();
17  switch ($this->ctrl()->getNextClass()) {
18  case strtolower(ilRepositorySearchGUI::class):
19  switch ($this->ctrl()->getCmd()) {
20  case 'addUserFromAutoComplete':
21  if ($r->getQueryParams()['addusertype'] == "staff") {
22  $this->addStaff();
23  }
24  break;
25  default:
26  $repo = new ilRepositorySearchGUI();
27  $this->ctrl()->forwardCommand($repo);
28  break;
29  }
30  break;
31 
32  default:
33  parent::executeCommand();
34  break;
35  }
36  }
37 
38 
39  protected function index()
40  {
41  // Header
42  $types = ilOrgUnitPosition::getArray('id', 'title');
43  //$types = array();
44  $this->ctrl()->setParameterByClass(ilRepositorySearchGUI::class, 'addusertype', 'staff');
45  ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->dic()->toolbar(), array(
46  'auto_complete_name' => $this->txt('user'),
47  'user_type' => $types,
48  'submit_name' => $this->txt('add'),
49  ));
50 
51  // Tables
52  $html = '';
53  foreach (ilOrgUnitPosition::getActiveForPosition($this->getParentRefId()) as $ilOrgUnitPosition) {
54  $ilOrgUnitUserAssignmentTableGUI = new ilOrgUnitUserAssignmentTableGUI($this, self::CMD_INDEX, $ilOrgUnitPosition);
55  $html .= $ilOrgUnitUserAssignmentTableGUI->getHTML();
56  }
57  $this->setContent($html);
58  }
59 
60 
61  protected function confirm()
62  {
63  $this->ctrl()->saveParameter($this, 'position_id');
64  $r = $this->http()->request();
65  $ilOrgUnitPosition = ilOrgUnitPosition::findOrFail($r->getQueryParams()['position_id']);
69  $confirmation = new ilConfirmationGUI();
70  $confirmation->setFormAction($this->ctrl()->getFormAction($this));
71  $confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
72  $confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE);
73  $confirmation->setHeaderText(sprintf($this->txt('msg_confirm_remove_user'), $ilOrgUnitPosition->getTitle()));
74  $confirmation->addItem('usr_id', $r->getQueryParams()['usr_id'], ilObjUser::_lookupLogin($r->getQueryParams()['usr_id']));
75 
76  $this->setContent($confirmation->getHTML());
77  }
78 
79 
80  protected function delete()
81  {
82  $r = $this->http()->request();
84  ->getAssignmentOrFail($_POST['usr_id'], $r->getQueryParams()['position_id'], $this->getParentRefId());
85  $ua->delete();
86  ilUtil::sendSuccess($this->txt('remove_successful'), true);
87  $this->cancel();
88  }
89 
90 
91  protected function cancel()
92  {
93  $this->ctrl()->redirect($this, self::CMD_INDEX);
94  }
95 
96 
97  public function addStaff()
98  {
99  if (!$this->dic()->access()->checkAccess("write", "", $this->getParentRefId())) {
100  ilUtil::sendFailure($this->txt("permission_denied"), true);
101  $this->ctrl()->redirect($this, self::CMD_INDEX);
102  }
103 
104  $users = explode(',', $_POST['user_login']);
105  $user_ids = array();
106  foreach ($users as $user) {
107  $user_id = ilObjUser::_lookupId($user);
108  if ($user_id) {
109  $user_ids[] = $user_id;
110  }
111  }
112 
113  if (!count($user_ids)) {
114  ilUtil::sendFailure($this->txt("user_not_found"), true);
115  $this->ctrl()->redirect($this, self::CMD_INDEX);
116  }
117 
118  $position_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
119 
120  if (!$position_id && !$position = ilOrgUnitPosition::find($position_id)) {
121  ilUtil::sendFailure($this->txt("user_not_found"), true);
122  $this->ctrl()->redirect($this, self::CMD_INDEX);
123  }
124  foreach ($user_ids as $user_id) {
125  ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getParentRefId());
126  }
127 
128  ilUtil::sendSuccess($this->txt("users_successfuly_added"), true);
129  $this->ctrl()->redirect($this, self::CMD_INDEX);
130  }
131 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupLogin($a_user_id)
lookup login
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
Class ilOrgUnitUserAssignmentGUI.
static _lookupId($a_user_str)
Lookup id by login.
$r
Definition: example_031.php:79
static http()
Fetches the global http state from ILIAS.
static findOrFail($primary_key, array $add_constructor_args=array())
Tries to find the object and throws an Exception if object is not found, instead of returning null...
static getActiveForPosition($orgu_ref_id)
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getArray($key=null, $values=null)
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
$_POST["username"]
$html
Definition: example_001.php:87
Class ilOrgUnitUserAssignmentTableGUI.
Confirmation screen class.