ILIAS  release_8 Revision v8.24
class.ilOrgUnitPositionGUI.php
Go to the documentation of this file.
1<?php
20
26{
28
29 public const SUBTAB_SETTINGS = 'settings';
30 public const SUBTAB_PERMISSIONS = 'obj_orgunit_positions';
31 public const CMD_CONFIRM_DELETION = 'confirmDeletion';
32 public const CMD_ASSIGN = 'assign';
34 private \ilGlobalTemplateInterface $main_tpl;
35 private ilCtrl $ctrl;
38
39 public function __construct()
40 {
41 global $DIC;
42
44
45 $main_tpl = $DIC->ui()->mainTemplate();
46 $this->main_tpl = $DIC->ui()->mainTemplate();
47 $this->ctrl = $DIC->ctrl();
48 $this->toolbar = $DIC->toolbar();
49 $this->tpl = $DIC->ui()->mainTemplate();
50 $this->language = $DIC->language();
51 $this->initRequest(
52 $DIC->http(),
53 $DIC['refinery']
54 );
55
56
58 $main_tpl->setOnScreenMessage('failure', $this->language->txt("permission_denied"), true);
59 $DIC->ctrl->redirectByClass(ilObjOrgUnitGUI::class);
60 }
61 }
62
63 protected function getPossibleNextClasses(): array
64 {
65 return array(
66 ilOrgUnitDefaultPermissionGUI::class,
67 ilOrgUnitUserAssignmentGUI::class,
68 );
69 }
70
71 protected function getActiveTabId(): string
72 {
74 }
75
76 protected function index(): void
77 {
78 self::initAuthoritiesRenderer();
80 $b->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD));
81 $b->setCaption('add_position');
82 $this->toolbar->addButtonInstance($b);
83
84 $table = new ilOrgUnitPositionTableGUI($this, self::CMD_INDEX);
85 $this->setContent($table->getHTML());
86 }
87
88 protected function add(): void
89 {
90 $form = new ilOrgUnitPositionFormGUI($this, new ilOrgUnitPosition());
91 $this->tpl->setContent($form->getHTML());
92 }
93
94 protected function create(): void
95 {
96 $form = new ilOrgUnitPositionFormGUI($this, new ilOrgUnitPosition());
97 if ($form->saveObject() === true) {
98 $this->main_tpl->setOnScreenMessage('success', $this->language->txt('msg_position_created'), true);
99 $this->ctrl->redirect($this, self::CMD_INDEX);
100 }
101
102 $this->tpl->setContent($form->getHTML());
103 }
104
105 protected function edit(): void
106 {
107 $this->addSubTabs();
108 $this->activeSubTab(self::SUBTAB_SETTINGS);
109 $position = $this->getPositionFromRequest();
110 $form = new ilOrgUnitPositionFormGUI($this, $position);
111 $form->fillForm();
112 $this->tpl->setContent($form->getHTML());
113 }
114
115 protected function update(): void
116 {
117 $position = $this->getPositionFromRequest();
118 $form = new ilOrgUnitPositionFormGUI($this, $position);
119 $form->setValuesByPost();
120 if ($form->saveObject() === true) {
121 $this->main_tpl->setOnScreenMessage('success', $this->language->txt('msg_position_updated'), true);
122 $this->ctrl->redirect($this, self::CMD_INDEX);
123 }
124
125 $this->tpl->setContent($form->getHTML());
126 }
127
128 protected function assign(): void
129 {
130 $position = $this->getPositionFromRequest();
131 if ($position->isCorePosition()) {
132 $this->cancel();
133 }
134 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
135 $assignments = $ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($position->getId());
136
138
139 foreach ($assignments as $assignment) {
141 $assignment->getUserId(),
142 $employee_position->getId(),
143 $assignment->getOrguId()
144 );
145 $assignment->delete();
146 }
147
148 $this->main_tpl->setOnScreenMessage('success', $this->language->txt('msg_assignment_to_employee_done'), true);
149 }
150
151 protected function confirmDeletion(): void
152 {
153 $position = $this->getPositionFromRequest();
154 if ($position->isCorePosition()) {
155 $this->cancel();
156 }
157 $position->afterObjectLoad();
158 self::initAuthoritiesRenderer();
159 $this->language->loadLanguageModule('orgu');
160 $position_string = $this->language->txt("position") . ": ";
161 $authority_string = $this->language->txt("authorities") . ": ";
162 $user_string = $this->language->txt("user_assignments") . ": ";
163 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
164
165 $confirmation = new ilConfirmationGUI();
166 $confirmation->setFormAction($this->ctrl->getFormAction($this));
167 $confirmation->setCancel($this->language->txt(self::CMD_CANCEL), self::CMD_CANCEL);
168 $confirmation->setConfirm($this->language->txt(self::CMD_DELETE), self::CMD_DELETE);
169 $confirmation->setHeaderText($this->language->txt('msg_confirm_deletion'));
170 $confirmation->addItem(self::AR_ID, $position->getId(), $position_string
171 . $position->getTitle());
172 // Authorities
173 $authority_string .= implode(", ", $position->getAuthorities());
174 $confirmation->addItem('authorities', true, $authority_string);
175
176 // Amount uf user-assignments
177 $userIdsOfPosition = $ilOrgUnitUserAssignmentQueries->getUserIdsOfPosition($position->getId());
178 $ilOrgUnitUserQueries = new ilOrgUnitUserQueries();
179 $usersOfPosition = $ilOrgUnitUserQueries->findAllUsersByUserIds($userIdsOfPosition);
180 $userNames = $ilOrgUnitUserQueries->getAllUserNames($usersOfPosition);
181
182 $confirmation->addItem('users', true, $user_string . implode(', ', $userNames));
183
184 $checkbox_assign_users = new ilCheckboxInputGUI('', 'assign_users');
185 $checkbox_assign_users->setChecked(true);
186 $checkbox_assign_users->setValue(1);
187 $checkbox_assign_users->setOptionTitle('Assign affected users to employee role');
188 $confirmation->addItem('assign_users', '', $checkbox_assign_users->render());
189
190 $this->tpl->setContent($confirmation->getHTML());
191 }
192
193 protected function delete(): void
194 {
195 if ($_POST['assign_users']) {
196 $this->assign();
197 }
198 $position = $this->getPositionFromRequest();
199 $position->afterObjectLoad();
200 $position->deleteWithAllDependencies();
201 $this->main_tpl->setOnScreenMessage('success', $this->language->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 ilOrgUnitPosition::find($this->str(self::AR_ID));
213 }
214
215 public static function initAuthoritiesRenderer(): string
216 {
217 $lang = $GLOBALS['DIC']->language();
218 $lang->loadLanguageModule('orgu');
219 $lang_keys = array(
220 'in',
221 'over',
225 );
226 $t = array();
227 foreach ($lang_keys as $key) {
228 $t[$key] = $lang->txt($key);
229 }
230
231 ilOrgUnitAuthority::replaceNameRenderer(function ($id) use ($t) {
235 $ilOrgUnitAuthority = ilOrgUnitAuthority::find($id);
236
237 switch ($ilOrgUnitAuthority->getScope()) {
241 default:
242 $in_txt = $t["scope_" . $ilOrgUnitAuthority->getScope()];
243 break;
244 }
245
246 switch ($ilOrgUnitAuthority->getOver()) {
248 $over_txt = $t["over_" . $ilOrgUnitAuthority->getOver()];
249 break;
250 default:
251 $over_txt = ilOrgUnitPosition::findOrGetInstance($ilOrgUnitAuthority->getOver())
252 ->getTitle();
253 break;
254 }
255
256 return " " . $t["over"] . " " . $over_txt . " " . $t["in"] . " " . $in_txt;
257 });
258 return "";
259 }
260
261 public function addSubTabs(): void
262 {
263 $this->ctrl->saveParameter($this, 'arid');
264 $this->ctrl->saveParameterByClass(ilOrgUnitDefaultPermissionGUI::class, 'arid');
265 $this->pushSubTab(self::SUBTAB_SETTINGS, $this->ctrl
266 ->getLinkTarget($this, self::CMD_EDIT));
267 $this->pushSubTab(self::SUBTAB_PERMISSIONS, $this->ctrl
268 ->getLinkTargetByClass(
269 ilOrgUnitDefaultPermissionGUI::class,
270 self::CMD_INDEX
271 ));
272 }
273}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Class ActiveRecord.
static findOrGetInstance($primary_key, array $add_constructor_args=array())
pushSubTab(string $subtab_id, string $url)
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
static _checkAccessPositions(int $ref_id)
static replaceNameRenderer(Closure $closure)
Class ilOrgUnitPositionFormGUI.
Class ilOrgUnitPositionGUI.
ilGlobalTemplateInterface $tpl
ilGlobalTemplateInterface $main_tpl
Class ilOrgUnitPositionTableGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getCorePosition(int $core_identifier)
static findOrCreateAssignment(int $user_id, int $position_id, int $orgu_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
trait BaseGUIRequest
Base gui request wrapper.
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.
$_GET['client_id']
Definition: saml1-acs.php:21
$lang
Definition: xapiexit.php:26