ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilOrgUnitPositionGUI.php
Go to the documentation of this file.
1 <?php
2 
20 declare(strict_types=1);
21 
23 
29 {
31 
32  public const SUBTAB_SETTINGS = 'settings';
33  public const SUBTAB_PERMISSIONS = 'obj_orgunit_positions';
34  public const CMD_CONFIRM_DELETION = 'confirmDeletion';
35  public const CMD_ASSIGN = 'assign';
37  protected \ILIAS\UI\Component\Link\Factory $link_factory;
38  private ilCtrl $ctrl;
40  private ilLanguage $lng;
41  protected \ilOrgUnitPositionDBRepository $positionRepo;
42  protected \ilOrgUnitUserAssignmentDBRepository $assignmentRepo;
43 
44  public function __construct()
45  {
47  $this->positionRepo = $dic["repo.Positions"];
48  $this->assignmentRepo = $dic["repo.UserAssignments"];
49  $this->ctrl = $dic['ctrl'];
50  $this->lng = $dic['lng'];
51 
52  $to_int = $dic['refinery']->kindlyTo()->int();
53  $ref_id = $dic['query']->retrieve('ref_id', $to_int);
54  $this->link_factory = $dic['ui.factory']->link();
55 
57 
58  global $DIC;
59  $this->toolbar = $DIC->toolbar();
60  $this->tpl = $DIC->ui()->mainTemplate();
61 
62  $this->initRequest(
63  $DIC->http(),
64  $dic['refinery']
65  );
66 
68  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
69  $this->ctrl->redirectByClass(ilObjOrgUnitGUI::class);
70  }
71  }
72 
73  protected function getPossibleNextClasses(): array
74  {
75  return array(
76  ilOrgUnitDefaultPermissionGUI::class,
77  ilOrgUnitUserAssignmentGUI::class,
78  );
79  }
80 
81  protected function getActiveTabId(): string
82  {
84  }
85 
86  protected function index(): void
87  {
88  $url = $this->ctrl->getLinkTarget($this, self::CMD_ADD);
89  $link = $this->link_factory->standard(
90  $this->lng->txt('add_position'),
91  $url
92  );
93  $this->toolbar->addComponent($link);
94 
95  $table = new ilOrgUnitPositionTableGUI($this, self::CMD_INDEX);
96  $this->setContent($table->getHTML());
97  }
98 
99  protected function add(): void
100  {
101  $form = new ilOrgUnitPositionFormGUI($this, $this->positionRepo->create());
102  $this->tpl->setContent($form->getHTML());
103  }
104 
105  protected function create(): void
106  {
107  $form = new ilOrgUnitPositionFormGUI($this, $this->positionRepo->create());
108  if ($form->saveObject() === true) {
109  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_position_created'), true);
110  $this->ctrl->redirect($this, self::CMD_INDEX);
111  }
112 
113  $this->tpl->setContent($form->getHTML());
114  }
115 
116  protected function edit(): void
117  {
118  $this->addSubTabs();
119  $this->activeSubTab(self::SUBTAB_SETTINGS);
120  $position = $this->getPositionFromRequest();
121  $form = new ilOrgUnitPositionFormGUI($this, $position);
122  $form->fillForm();
123  $this->tpl->setContent($form->getHTML());
124  }
125 
126  protected function update(): void
127  {
128  $position = $this->getPositionFromRequest();
129  $form = new ilOrgUnitPositionFormGUI($this, $position);
130  $form->setValuesByPost();
131  if ($form->saveObject() === true) {
132  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_position_updated'), true);
133  $this->ctrl->redirect($this, self::CMD_INDEX);
134  }
135 
136  $this->tpl->setContent($form->getHTML());
137  }
138 
139  protected function assign(): void
140  {
141  $position = $this->getPositionFromRequest();
142  if ($position->isCorePosition()) {
143  $this->cancel();
144  }
145 
146  $employee_position = $this->positionRepo->getSingle(ilOrgUnitPosition::CORE_POSITION_EMPLOYEE, 'core_identifier');
147  $assignments = $this->assignmentRepo->getByPosition($position->getId());
148  foreach ($assignments as $assignment) {
149  $this->assignmentRepo->store($assignment->withPositionId($employee_position->getId()));
150  }
151 
152  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_assignment_to_employee_done'), true);
153  }
154 
155  protected function confirmDeletion(): void
156  {
157  $position = $this->getPositionFromRequest();
158  if ($position->isCorePosition()) {
159  $this->cancel();
160  }
161  $this->lng->loadLanguageModule('orgu');
162  $position_string = $this->lng->txt("position") . ": ";
163  $authority_string = $this->lng->txt("authorities") . ": ";
164  $user_string = $this->lng->txt("user_assignments") . ": ";
165 
166  $confirmation = new ilConfirmationGUI();
167  $confirmation->setFormAction($this->ctrl->getFormAction($this));
168  $confirmation->setCancel($this->lng->txt(self::CMD_CANCEL), self::CMD_CANCEL);
169  $confirmation->setConfirm($this->lng->txt(self::CMD_DELETE), self::CMD_DELETE);
170  $confirmation->setHeaderText($this->lng->txt('msg_confirm_deletion'));
171  $confirmation->addItem(self::AR_ID, (string) $position->getId(), $position_string
172  . $position->getTitle());
173  // Authorities
174  $authority_string .= implode(", ", $this->getAuthorityDescription($position->getAuthorities()));
175  $confirmation->addItem('authorities', '', $authority_string);
176 
177  // Amount uf user-assignments
178  $userIdsOfPosition = $this->assignmentRepo->getUsersByPosition($position->getId());
179  $ilOrgUnitUserQueries = new ilOrgUnitUserQueries();
180  $usersOfPosition = $ilOrgUnitUserQueries->findAllUsersByUserIds($userIdsOfPosition);
181  $userNames = $ilOrgUnitUserQueries->getAllUserNames($usersOfPosition);
182 
183  $confirmation->addItem('users', '', $user_string . implode(', ', $userNames));
184 
185  $checkbox_assign_users = new ilCheckboxInputGUI('', 'assign_users');
186  $checkbox_assign_users->setChecked(true);
187  $checkbox_assign_users->setValue('1');
188  $checkbox_assign_users->setOptionTitle('Assign affected users to employee role');
189  $confirmation->addItem('assign_users', '', $checkbox_assign_users->render());
190 
191  $this->tpl->setContent($confirmation->getHTML());
192  }
193 
194  protected function delete(): void
195  {
196  if ($_POST['assign_users']) {
197  $this->assign();
198  }
199  $position = $this->getPositionFromRequest();
200  $this->positionRepo->delete($position->getId());
201  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_deleted'), true);
202  $this->ctrl->redirect($this, self::CMD_INDEX);
203  }
204 
205  protected function cancel(): void
206  {
207  $this->ctrl->redirect($this, self::CMD_INDEX);
208  }
209 
211  {
212  return $this->positionRepo->getSingle($this->int(self::AR_ID), 'id');
213  }
214 
215 
216  public function addSubTabs(): void
217  {
218  $this->ctrl->saveParameter($this, 'arid');
219  $this->ctrl->saveParameterByClass(ilOrgUnitDefaultPermissionGUI::class, 'arid');
220  $this->pushSubTab(self::SUBTAB_SETTINGS, $this->ctrl
221  ->getLinkTarget($this, self::CMD_EDIT));
222  $this->pushSubTab(self::SUBTAB_PERMISSIONS, $this->ctrl
223  ->getLinkTargetByClass(
224  ilOrgUnitDefaultPermissionGUI::class,
225  self::CMD_INDEX
226  ));
227  }
228 
234  private function getAuthorityDescription(array $authorities): array
235  {
236  $lang = $this->lng;
237  $lang->loadLanguageModule('orgu');
238  $lang_keys = array(
239  'in',
240  'over',
244  );
245  $t = [];
246  foreach ($lang_keys as $key) {
247  $t[$key] = $lang->txt($key);
248  }
249 
250  $authority_description = [];
251  foreach ($authorities as $authority) {
252  switch ($authority->getOver()) {
254  $over_txt = $t["over_" . $authority->getOver()];
255  break;
256  default:
257  $over_txt = $this->positionRepo
258  ->getSingle($authority->getOver(), 'id')
259  ->getTitle();
260  break;
261  }
262 
263  $authority_description[] = " " . $t["over"] . " " . $over_txt . " " . $t["in"] . " " . $t["scope_" . $authority->getScope()];
264  }
265 
266  return $authority_description;
267  }
268 }
Class ilOrgUnitPositionGUI.
ilOrgUnitPositionDBRepository $positionRepo
Class ilOrgUnitPositionFormGUI.
global $DIC
Definition: feed.php:28
pushSubTab(string $subtab_id, string $url)
initRequest(HTTP\Services $http, Refinery\Factory $refinery, ?array $passed_query_params=null, ?array $passed_post_data=null)
Query params and post data parameters are used for testing.
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
ILIAS UI Component Link Factory $link_factory
string $key
Consumer key/client ID value.
Definition: System.php:193
$url
Definition: ltiregstart.php:35
trait BaseGUIRequest
Base gui request wrapper.
ilGlobalTemplateInterface $tpl
$lang
Definition: xapiexit.php:26
static _checkAccessPositions(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: result.php:32
Class ilOrgUnitPositionTableGUI.
getAuthorityDescription(array $authorities)
Returns descriptions for authorities as an array of strings.
ilOrgUnitUserAssignmentDBRepository $assignmentRepo