ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitPositionGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
11 {
12  const SUBTAB_SETTINGS = 'settings';
13  const SUBTAB_PERMISSIONS = 'obj_orgunit_positions';
14  const CMD_CONFIRM_DELETION = 'confirmDeletion';
15  const CMD_ASSIGN = 'assign';
16 
17  public function __construct() {
18  global $DIC;
19 
20  if (!ilObjOrgUnitAccess::_checkAccessPositions((int) $_GET['ref_id'])) {
21  ilUtil::sendFailure($DIC->language()->txt("permission_denied"), true);
22  $DIC->ctrl()->redirectByClass(ilObjOrgUnitGUI::class);
23  }
24  }
25 
26 
30  protected function getPossibleNextClasses()
31  {
32  return array(
33  ilOrgUnitDefaultPermissionGUI::class,
34  ilOrgUnitUserAssignmentGUI::class,
35  );
36  }
37 
38 
42  protected function getActiveTabId()
43  {
45  }
46 
47 
48  protected function index()
49  {
50  self::initAuthoritiesRenderer();
52  $b->setUrl($this->ctrl()->getLinkTarget($this, self::CMD_ADD));
53  $b->setCaption('add_position');
54  $this->dic()->toolbar()->addButtonInstance($b);
55 
56  $table = new ilOrgUnitPositionTableGUI($this, self::CMD_INDEX);
57  $this->setContent($table->getHTML());
58  }
59 
60 
61  protected function add()
62  {
63  $form = new ilOrgUnitPositionFormGUI($this, new ilOrgUnitPosition());
64  $this->tpl()->setContent($form->getHTML());
65  }
66 
67 
68  protected function create()
69  {
70  $form = new ilOrgUnitPositionFormGUI($this, new ilOrgUnitPosition());
71  if ($form->saveObject()) {
72  ilUtil::sendSuccess($this->txt('msg_position_created'), true);
73  $this->ctrl()->redirect($this, self::CMD_INDEX);
74  }
75 
76  $this->tpl()->setContent($form->getHTML());
77  }
78 
79 
80  protected function edit()
81  {
82  $this->addSubTabs();
83  $this->activeSubTab(self::SUBTAB_SETTINGS);
84  $position = $this->getPositionFromRequest();
85  $form = new ilOrgUnitPositionFormGUI($this, $position);
86  $form->fillForm();
87  $this->tpl()->setContent($form->getHTML());
88  }
89 
90 
91  protected function update()
92  {
93  $position = $this->getPositionFromRequest();
94  $form = new ilOrgUnitPositionFormGUI($this, $position);
95  $form->setValuesByPost();
96  if ($form->saveObject()) {
97  ilUtil::sendSuccess($this->txt('msg_position_updated'), true);
98  $this->ctrl()->redirect($this, self::CMD_INDEX);
99  }
100 
101  $this->tpl()->setContent($form->getHTML());
102  }
103 
104 
105  protected function assign()
106  {
107  $position = $this->getPositionFromRequest();
108  if ($position->isCorePosition()) {
109  $this->cancel();
110  }
111  $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
112  $assignments = $ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($position->getId());
113 
115 
116  foreach ($assignments as $assignment) {
117  ilOrgUnitUserAssignment::findOrCreateAssignment($assignment->getUserId(), $employee_position->getId(), $assignment->getOrguId());
118  $assignment->delete();
119  }
120 
121  ilUtil::sendSuccess($this->txt('msg_assignment_to_employee_done'), true);
122  }
123 
124 
125  protected function confirmDeletion()
126  {
127  $position = $this->getPositionFromRequest();
128  if ($position->isCorePosition()) {
129  $this->cancel();
130  }
131  self::initAuthoritiesRenderer();
132  $this->dic()->language()->loadLanguageModule('orgu');
133  $position_string = $this->dic()->language()->txt("position") . ": ";
134  $authority_string = $this->dic()->language()->txt("authorities") . ": ";
135  $user_string = $this->dic()->language()->txt("user_assignments") . ": ";
136  $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
137 
138  $confirmation = new ilConfirmationGUI();
139  $confirmation->setFormAction($this->ctrl()->getFormAction($this));
140  $confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
141  $confirmation->setConfirm($this->txt(self::CMD_DELETE), self::CMD_DELETE);
142  $confirmation->setHeaderText($this->txt('msg_confirm_deletion'));
143  $confirmation->addItem(self::AR_ID, $position->getId(), $position_string
144  . $position->getTitle());
145  // Authorities
146  $authority_string .= implode(", ", $position->getAuthorities());
147  $confirmation->addItem('authorities', true, $authority_string);
148 
149  // Amount uf user-assignments
150  $userIdsOfPosition = $ilOrgUnitUserAssignmentQueries->getUserIdsOfPosition($position->getId());
151  $ilOrgUnitUserQueries = new ilOrgUnitUserQueries();
152  $usersOfPosition = $ilOrgUnitUserQueries->findAllUsersByUserIds($userIdsOfPosition);
153  $userNames = $ilOrgUnitUserQueries->getAllUserNames($usersOfPosition);
154 
155  $confirmation->addItem('users', true, $user_string . implode(', ', $userNames));
156 
157  $checkbox_assign_users = new ilCheckboxInputGUI('', 'assign_users');
158  $checkbox_assign_users->setChecked(true);
159  $checkbox_assign_users->setValue(1);
160  $checkbox_assign_users->setOptionTitle('Assign affected users to employee role');
161  $confirmation->addItem('assign_users', '', $checkbox_assign_users->render());
162 
163  $this->tpl()->setContent($confirmation->getHTML());
164  }
165 
166 
167  protected function delete()
168  {
169  if ($_POST['assign_users']) {
170  $this->assign();
171  }
172  $position = $this->getPositionFromRequest();
173  $position->deleteWithAllDependencies();
174  ilUtil::sendSuccess($this->txt('msg_deleted'), true);
175  $this->ctrl()->redirect($this, self::CMD_INDEX);
176  }
177 
178 
179  protected function cancel()
180  {
181  $this->ctrl()->redirect($this, self::CMD_INDEX);
182  }
183 
184 
188  protected function getARIdFromRequest()
189  {
190  $get = $this->dic()->http()->request()->getQueryParams()[self::AR_ID];
191  $post = $this->dic()->http()->request()->getParsedBody()[self::AR_ID];
192 
193  return $post ? $post : $get;
194  }
195 
196 
200  protected function getPositionFromRequest()
201  {
202  return ilOrgUnitPosition::find($this->getARIdFromRequest());
203  }
204 
205 
206  public static function initAuthoritiesRenderer()
207  {
208  $lang = $GLOBALS['DIC']->language();
209  $lang->loadLanguageModule('orgu');
210  $lang_keys = array(
211  'in',
215  );
216  $t = array();
217  foreach ($lang_keys as $key) {
218  $t[$key] = $lang->txt($key);
219  }
220 
221  ilOrgUnitAuthority::replaceNameRenderer(function ($id) use ($t) {
225  $ilOrgUnitAuthority = ilOrgUnitAuthority::find($id);
226 
227  switch ($ilOrgUnitAuthority->getScope()) {
231  default:
232  $in_txt = $t["scope_" . $ilOrgUnitAuthority->getScope()];
233  break;
234  }
235 
236  switch ($ilOrgUnitAuthority->getOver()) {
238  $over_txt = $t["over_" . $ilOrgUnitAuthority->getOver()];
239  break;
240  default:
241  $over_txt = ilOrgUnitPosition::findOrGetInstance($ilOrgUnitAuthority->getOver())
242  ->getTitle();
243  break;
244  }
245 
246  return " " . $t["over"] . " " . $over_txt . " " . $t["in"] . " " . $in_txt;
247  });
248  }
249 
250 
251  public function addSubTabs()
252  {
253  $this->ctrl()->saveParameter($this, 'arid');
254  $this->ctrl()->saveParameterByClass(ilOrgUnitDefaultPermissionGUI::class, 'arid');
255  $this->pushSubTab(self::SUBTAB_SETTINGS, $this->ctrl()
256  ->getLinkTarget($this, self::CMD_EDIT));
257  $this->pushSubTab(self::SUBTAB_PERMISSIONS, $this->ctrl()
258  ->getLinkTargetByClass(ilOrgUnitDefaultPermissionGUI::class, self::CMD_INDEX));
259  }
260 }
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
$_GET["client_id"]
static getCorePosition($core_identifier)
This class represents a checkbox property in a property form.
Class ilOrgUnitPositionGUI.
Class ilOrgUnitPositionFormGUI.
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static replaceNameRenderer(Closure $closure)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$lang
Definition: xapiexit.php:8
static _checkAccessPositions(int $ref_id)
Class ilOrgUnitUserQueries.
static findOrGetInstance($primary_key, array $add_constructor_args=array())
Class ilOrgUnitPositionTableGUI.
$_POST["username"]
Confirmation screen class.