ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilOrgUnitUserAssignmentGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
14 {
15  const CMD_ASSIGNMENTS_RECURSIVE = 'assignmentsRecursive';
16 
17  const SUBTAB_ASSIGNMENTS = 'user_assignments';
18  const SUBTAB_ASSIGNMENTS_RECURSIVE = 'user_assignments_recursive';
19 
20  public function executeCommand()
21  {
22  if (!ilObjOrgUnitAccess::_checkAccessPositions((int) filter_input(INPUT_GET, "ref_id", FILTER_SANITIZE_NUMBER_INT))) {
23  ilUtil::sendFailure($this->lng()->txt("permission_denied"), true);
24  $this->ctrl()->redirectByClass(ilObjOrgUnitGUI::class);
25  }
26 
27  $r = $this->http()->request();
28  switch ($this->ctrl()->getNextClass()) {
29  case strtolower(ilRepositorySearchGUI::class):
30  switch ($this->ctrl()->getCmd()) {
31  case 'addUserFromAutoComplete':
32  if ($r->getQueryParams()['addusertype'] == "staff") {
33  $this->addStaff();
34  }
35  break;
36  default:
37  $repo = new ilRepositorySearchGUI();
38  $this->ctrl()->forwardCommand($repo);
39  break;
40  }
41  break;
42 
43  default:
44  parent::executeCommand();
45  break;
46  }
47  }
48 
49 
50  protected function index()
51  {
52  $this->addSubTabs();
53  $this->activeSubTab(self::SUBTAB_ASSIGNMENTS);
54 
55  // Header
56  $types = ilOrgUnitPosition::getArray('id', 'title');
57  //$types = array();
58  $this->ctrl()->setParameterByClass(ilRepositorySearchGUI::class, 'addusertype', 'staff');
59  ilRepositorySearchGUI::fillAutoCompleteToolbar($this, $this->dic()->toolbar(), array(
60  'auto_complete_name' => $this->txt('user'),
61  'user_type' => $types,
62  'submit_name' => $this->txt('add'),
63  ));
64 
65  // Tables
66  $html = '';
67  foreach (ilOrgUnitPosition::getActiveForPosition($this->getParentRefId()) as $ilOrgUnitPosition) {
68  $ilOrgUnitUserAssignmentTableGUI = new ilOrgUnitUserAssignmentTableGUI($this, self::CMD_INDEX, $ilOrgUnitPosition);
69  $html .= $ilOrgUnitUserAssignmentTableGUI->getHTML();
70  }
71  $this->setContent($html);
72  }
73 
74  protected function assignmentsRecursive()
75  {
76  $this->addSubTabs();
77  $this->activeSubTab(self::SUBTAB_ASSIGNMENTS_RECURSIVE);
78  // Tables
79  $html = '';
80  foreach (ilOrgUnitPosition::getActiveForPosition($this->getParentRefId()) as $ilOrgUnitPosition) {
81  $ilOrgUnitRecursiveUserAssignmentTableGUI =
83  $this,
84  self::CMD_ASSIGNMENTS_RECURSIVE,
85  $ilOrgUnitPosition
86  );
87  $html .= $ilOrgUnitRecursiveUserAssignmentTableGUI->getHTML();
88  }
89  $this->setContent($html);
90  }
91 
92 
93  protected function confirm()
94  {
95  $confirmation = $this->getConfirmationGUI();
96  $confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE);
97 
98  $this->setContent($confirmation->getHTML());
99  }
100 
101  protected function confirmRecursive()
102  {
103  $confirmation = $this->getConfirmationGUI();
104  $confirmation->setConfirm($this->txt('remove_user'), self::CMD_DELETE_RECURSIVE);
105 
106  $this->setContent($confirmation->getHTML());
107  }
108 
109  protected function getConfirmationGUI() : ilConfirmationGUI
110  {
111  $this->ctrl()->saveParameter($this, 'position_id');
112  $r = $this->http()->request();
113  $ilOrgUnitPosition = ilOrgUnitPosition::findOrFail($r->getQueryParams()['position_id']);
117  $confirmation = new ilConfirmationGUI();
118  $confirmation->setFormAction($this->ctrl()->getFormAction($this));
119  $confirmation->setHeaderText(sprintf($this->txt('msg_confirm_remove_user'), $ilOrgUnitPosition->getTitle()));
120  $confirmation->addItem('usr_id', $r->getQueryParams()['usr_id'], ilObjUser::_lookupLogin($r->getQueryParams()['usr_id']));
121  $confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
122 
123  return $confirmation;
124  }
125 
126  protected function delete()
127  {
128  $r = $this->http()->request();
130  ->getAssignmentOrFail($_POST['usr_id'], $r->getQueryParams()['position_id'], $this->getParentRefId());
131  $ua->delete();
132  ilUtil::sendSuccess($this->txt('remove_successful'), true);
133  $this->cancel();
134  }
135 
136  protected function deleteRecursive()
137  {
138  $r = $this->http()->request();
140  ->getAssignmentsOfUserIdAndPosition((int) $_POST['usr_id'], (int) $r->getQueryParams()['position_id'])
141  ;
142 
143  foreach ($assignments as $assignment) {
144  $assignment->delete();
145  }
146  ilUtil::sendSuccess($this->txt('remove_successful'), true);
147  $this->cancel();
148  }
149 
150  protected function cancel()
151  {
152  $this->ctrl()->redirect($this, self::CMD_INDEX);
153  }
154 
155 
156  public function addStaff()
157  {
158  if (!$this->dic()->access()->checkAccess("write", "", $this->getParentRefId())) {
159  ilUtil::sendFailure($this->txt("permission_denied"), true);
160  $this->ctrl()->redirect($this, self::CMD_INDEX);
161  }
162 
163  $users = explode(',', $_POST['user_login']);
164  $user_ids = array();
165  foreach ($users as $user) {
166  $user_id = ilObjUser::_lookupId($user);
167  if ($user_id) {
168  $user_ids[] = $user_id;
169  }
170  }
171 
172  if (!count($user_ids)) {
173  ilUtil::sendFailure($this->txt("user_not_found"), true);
174  $this->ctrl()->redirect($this, self::CMD_INDEX);
175  }
176 
177  $position_id = isset($_POST['user_type']) ? $_POST['user_type'] : 0;
178 
179  if (!$position_id && !$position = ilOrgUnitPosition::find($position_id)) {
180  ilUtil::sendFailure($this->txt("user_not_found"), true);
181  $this->ctrl()->redirect($this, self::CMD_INDEX);
182  }
183  foreach ($user_ids as $user_id) {
184  ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getParentRefId());
185  }
186 
187  ilUtil::sendSuccess($this->txt("users_successfuly_added"), true);
188  $this->ctrl()->redirect($this, self::CMD_INDEX);
189  }
190 
191  public function addSubTabs()
192  {
193  $this->pushSubTab(self::SUBTAB_ASSIGNMENTS, $this->ctrl()
194  ->getLinkTarget($this, self::CMD_INDEX));
195  $this->pushSubTab(self::SUBTAB_ASSIGNMENTS_RECURSIVE, $this->ctrl()
196  ->getLinkTarget($this, self::CMD_ASSIGNMENTS_RECURSIVE));
197  }
198 }
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.
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)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static _checkAccessPositions(int $ref_id)
static getArray($key=null, $values=null)
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
$_POST["username"]
Class ilOrgUnitUserAssignmentTableGUI.
Confirmation screen class.