ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
21  protected function getPossibleNextClasses()
22  {
23  return array(
24  ilOrgUnitDefaultPermissionGUI::class,
25  ilOrgUnitUserAssignmentGUI::class,
26  );
27  }
28 
29 
33  protected function getActiveTabId()
34  {
36  }
37 
38 
39  protected function index()
40  {
41  self::initAuthoritiesRenderer();
43  $b->setUrl($this->ctrl()->getLinkTarget($this, self::CMD_ADD));
44  $b->setCaption('add_position');
45  $this->dic()->toolbar()->addButtonInstance($b);
46 
47  $table = new ilOrgUnitPositionTableGUI($this, self::CMD_INDEX);
48  $this->setContent($table->getHTML());
49  }
50 
51 
52  protected function add()
53  {
55  $this->tpl()->setContent($form->getHTML());
56  }
57 
58 
59  protected function create()
60  {
62  if ($form->saveObject()) {
63  ilUtil::sendSuccess($this->txt('msg_position_created'), true);
64  $this->ctrl()->redirect($this, self::CMD_INDEX);
65  }
66 
67  $this->tpl()->setContent($form->getHTML());
68  }
69 
70 
71  protected function edit()
72  {
73  $this->addSubTabs();
74  $this->activeSubTab(self::SUBTAB_SETTINGS);
75  $position = $this->getPositionFromRequest();
76  $form = new ilOrgUnitPositionFormGUI($this, $position);
77  $form->fillForm();
78  $this->tpl()->setContent($form->getHTML());
79  }
80 
81 
82  protected function update()
83  {
84  $position = $this->getPositionFromRequest();
85  $form = new ilOrgUnitPositionFormGUI($this, $position);
86  $form->setValuesByPost();
87  if ($form->saveObject()) {
88  ilUtil::sendSuccess($this->txt('msg_position_updated'), true);
89  $this->ctrl()->redirect($this, self::CMD_INDEX);
90  }
91 
92  $this->tpl()->setContent($form->getHTML());
93  }
94 
95 
96  protected function assign()
97  {
98  $position = $this->getPositionFromRequest();
99  if ($position->isCorePosition()) {
100  $this->cancel();
101  }
102  $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
103  $assignments = $ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($position->getId());
104 
106 
107  foreach ($assignments as $assignment) {
108  ilOrgUnitUserAssignment::findOrCreateAssignment($assignment->getUserId(), $employee_position->getId(), $assignment->getOrguId());
109  $assignment->delete();
110  }
111 
112  ilUtil::sendSuccess($this->txt('msg_assignment_to_employee_done'), true);
113  }
114 
115 
116  protected function confirmDeletion()
117  {
118  $position = $this->getPositionFromRequest();
119  if ($position->isCorePosition()) {
120  $this->cancel();
121  }
122  self::initAuthoritiesRenderer();
123  $this->dic()->language()->loadLanguageModule('orgu');
124  $position_string = $this->dic()->language()->txt("position") . ": ";
125  $authority_string = $this->dic()->language()->txt("authorities") . ": ";
126  $user_string = $this->dic()->language()->txt("user_assignments") . ": ";
127  $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
128 
129  $confirmation = new ilConfirmationGUI();
130  $confirmation->setFormAction($this->ctrl()->getFormAction($this));
131  $confirmation->setCancel($this->txt(self::CMD_CANCEL), self::CMD_CANCEL);
132  $confirmation->setConfirm($this->txt(self::CMD_DELETE), self::CMD_DELETE);
133  $confirmation->setHeaderText($this->txt('msg_confirm_deletion'));
134  $confirmation->addItem(self::AR_ID, $position->getId(), $position_string
135  . $position->getTitle());
136  // Authorities
137  $authority_string .= implode(", ", $position->getAuthorities());
138  $confirmation->addItem('authorities', true, $authority_string);
139 
140  // Amount uf user-assignments
141  $userIdsOfPosition = $ilOrgUnitUserAssignmentQueries->getUserIdsOfPosition($position->getId());
142  $ilOrgUnitUserQueries = new ilOrgUnitUserQueries();
143  $usersOfPosition = $ilOrgUnitUserQueries->findAllUsersByUserIds($userIdsOfPosition);
144  $userNames = $ilOrgUnitUserQueries->getAllUserNames($usersOfPosition);
145 
146  $confirmation->addItem('users', true, $user_string . implode(', ', $userNames));
147 
148  $checkbox_assign_users = new ilCheckboxInputGUI('', 'assign_users');
149  $checkbox_assign_users->setChecked(true);
150  $checkbox_assign_users->setValue(1);
151  $checkbox_assign_users->setOptionTitle('Assign affected users to employee role');
152  $confirmation->addItem('assign_users', '', $checkbox_assign_users->render());
153 
154  $this->tpl()->setContent($confirmation->getHTML());
155  }
156 
157 
158  protected function delete()
159  {
160  if ($_POST['assign_users']) {
161  $this->assign();
162  }
163  $position = $this->getPositionFromRequest();
164  $position->deleteWithAllDependencies();
165  ilUtil::sendSuccess($this->txt('msg_deleted'), true);
166  $this->ctrl()->redirect($this, self::CMD_INDEX);
167  }
168 
169 
170  protected function cancel()
171  {
172  $this->ctrl()->redirect($this, self::CMD_INDEX);
173  }
174 
175 
179  protected function getARIdFromRequest()
180  {
181  $get = $this->dic()->http()->request()->getQueryParams()[self::AR_ID];
182  $post = $this->dic()->http()->request()->getParsedBody()[self::AR_ID];
183 
184  return $post ? $post : $get;
185  }
186 
187 
191  protected function getPositionFromRequest()
192  {
193  return ilOrgUnitPosition::find($this->getARIdFromRequest());
194  }
195 
196 
197  public static function initAuthoritiesRenderer()
198  {
199  $lang = $GLOBALS['DIC']->language();
200  $lang->loadLanguageModule('orgu');
201  $lang_keys = array(
202  'in',
206  );
207  $t = array();
208  foreach ($lang_keys as $key) {
209  $t[$key] = $lang->txt($key);
210  }
211 
216  $ilOrgUnitAuthority = ilOrgUnitAuthority::find($id);
217 
218  switch ($ilOrgUnitAuthority->getScope()) {
222  default:
223  $in_txt = $t["scope_" . $ilOrgUnitAuthority->getScope()];
224  break;
225  }
226 
227  switch ($ilOrgUnitAuthority->getOver()) {
229  $over_txt = $t["over_" . $ilOrgUnitAuthority->getOver()];
230  break;
231  default:
232  $over_txt = ilOrgUnitPosition::findOrGetInstance($ilOrgUnitAuthority->getOver())
233  ->getTitle();
234  break;
235  }
236 
237  return " " . $t["over"] . " " . $over_txt . " " . $t["in"] . " " . $in_txt;
238  });
239  }
240 
241 
242  public function addSubTabs()
243  {
244  $this->ctrl()->saveParameter($this, 'arid');
245  $this->ctrl()->saveParameterByClass(ilOrgUnitDefaultPermissionGUI::class, 'arid');
246  $this->pushSubTab(self::SUBTAB_SETTINGS, $this->ctrl()
247  ->getLinkTarget($this, self::CMD_INDEX));
248  $this->pushSubTab(self::SUBTAB_PERMISSIONS, $this->ctrl()
249  ->getLinkTargetByClass(ilOrgUnitDefaultPermissionGUI::class, self::CMD_INDEX));
250  }
251 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if(!array_key_exists('StateId', $_REQUEST)) $id
static getCorePosition($core_identifier)
This class represents a checkbox property in a property form.
Class ilOrgUnitPositionGUI.
Class ilOrgUnitPositionFormGUI.
if(isset($_POST['submit'])) $form
$post
Definition: post.php:34
static replaceNameRenderer(Closure $closure)
Create styles array
The data for the language used.
Class ilOrgUnitUserQueries.
Class ilOrgUnitPosition.
static findOrGetInstance($primary_key, array $add_constructor_args=array())
if(empty($password)) $table
Definition: pwgen.php:24
Class ilOrgUnitPositionTableGUI.
$key
Definition: croninfo.php:18
$_POST["username"]
Confirmation screen class.