ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserRoleStartingPointTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
24
30{
31 private const TABLE_POSITION_DEFAULT = 9999;
32
33 public function __construct(
34 object $parent_obj,
35 private Repository $starting_point_repository,
36 private ilRbacReview $rbac_review,
37 private UIFactory $ui_factory,
38 private Renderer $ui_renderer,
39 ) {
40 $this->setId('usrrolesp');
41
42 parent::__construct($parent_obj);
43
44 $this->getItems();
45
46 $this->setLimit(9999);
47 $this->setTitle($this->lng->txt('user_role_starting_point'));
48
49 $this->addColumn($this->lng->txt('user_order'));
50 $this->addColumn($this->lng->txt('criteria'));
51 $this->addColumn($this->lng->txt('starting_page'));
52 $this->addColumn($this->lng->txt('actions'));
53 $this->setFormAction($this->ctrl->getFormAction($parent_obj));
54 $this->setRowTemplate('tpl.user_role_starting_point_row.html', 'components/ILIAS/User');
55 $this->addCommandButton('saveOrder', $this->lng->txt('save_order'));
56
57 $this->setExternalSorting(true);
58 }
59
63 public function getItems(): void
64 {
65 $dc = new ilObjectDataCache();
66
67 $valid_points = $this->starting_point_repository->getPossibleStartingPoints();
68
69 $starting_points = [];
70
71 $available_starting_points = $this->starting_point_repository->getStartingPoints();
72
73 foreach ($available_starting_points as $available_starting_point) {
74 $starting_point_type = $available_starting_point->getStartingPointType();
75 $position = $available_starting_point->getPosition();
76 $sp_text = $this->lng->txt($valid_points[$starting_point_type]) ?? '';
77
78 if ($starting_point_type === Repository::START_REPOSITORY_OBJ
79 && $available_starting_point->getStartingObject() !== null) {
80 $starting_object_ref_id = $available_starting_point->getStartingObject();
81 $object_id = ilObject::_lookupObjId($starting_object_ref_id);
82 $type = $dc->lookupType($object_id);
83 $title = $dc->lookupTitle($object_id);
84 $sp_text = $this->lng->txt('obj_' . $type) . ' '
85 . '<i>"' . $title . '" (' . $starting_object_ref_id . ')</i>';
86 }
87
88 if ($available_starting_point->isRoleBasedStartingPoint()) {
89 $options = unserialize($available_starting_point->getRuleOptions(), ['allowed_classes' => false]);
90
91 $role_obj = ilObjectFactory::getInstanceByObjId((int) $options['role_id'], false);
92 if (!($role_obj instanceof \ilObjRole)) {
93 continue;
94 }
95
96 $starting_points[] = [
97 'id' => $available_starting_point->getId(),
98 'criteria' => $role_obj->getTitle(),
99 'starting_page' => $sp_text,
100 'starting_position' => $position,
101 'role_id' => $role_obj->getId()
102 ];
103 }
104 }
105
106 $default_sp = $this->starting_point_repository->getSystemDefaultStartingPointType();
107 $starting_point = $this->lng->txt($valid_points[$default_sp]);
108 if ($default_sp === Repository::START_REPOSITORY_OBJ) {
109 $starting_object_ref_id = $this->starting_point_repository->getSystemDefaultStartingObject();
110
111 $object_id = ilObject::_lookupObjId($starting_object_ref_id);
112 $type = $dc->lookupType($object_id);
113 $title = $dc->lookupTitle($object_id);
114 $starting_point = $this->lng->txt('obj_' . $type) . ' '
115 . '<i>"' . $title . '" (' . $starting_object_ref_id . ')</i>';
116 }
117
118 $starting_points[] = [
119 'id' => $this->starting_point_repository->getDefaultStartingPointID(),
120 'criteria' => $this->lng->txt('default'),
121 'starting_page' => $starting_point,
122 'starting_position' => self::TABLE_POSITION_DEFAULT
123 ];
124
125 $sorted_starting_points = $this->starting_point_repository->reArrangePositions(
126 ilArrayUtil::sortArray($starting_points, 'starting_position', 'asc', true)
127 );
128
129 $this->setData($sorted_starting_points);
130 }
131
136 protected function fillRow(array $row_data): void
137 {
138 $id = $row_data['id'];
139 $role_id = $row_data['role_id'] ?? null;
140 $this->ctrl->setParameter($this->getParentObject(), 'spid', $id);
141
142 if ($this->isSortingHidden($id)) {
143 $this->tpl->setVariable('HIDDEN', 'hidden');
144 } else {
145 $this->tpl->setVariable('VAL_ID', 'position[' . (string) $id . ']');
146 $this->tpl->setVariable('VAL_POS', $row_data['starting_position']);
147 }
148
149 $this->tpl->setVariable(
150 'TXT_TITLE',
152 $id,
153 $role_id,
154 $row_data['criteria']
155 )
156 );
157
158 $actions = $this->getActions($id, $role_id);
159
160 $this->tpl->setVariable('TXT_PAGE', $row_data['starting_page']);
161
162 $list = $this->ui_factory->dropdown()->standard($actions)->withLabel(
163 $this->lng->txt('actions')
164 );
165
166 $this->tpl->setVariable('ACTION', $this->ui_renderer->render($list));
167 }
168
172 private function getActions(int $id, ?int $role_id): array
173 {
174 $actions = [];
175
176 $edit_url = $this->getEditLink($id, $role_id);
177
178 $actions[] = $this->ui_factory->link()->standard(
179 $this->lng->txt('edit'),
180 $edit_url
181 );
182
183 if ($id !== $this->starting_point_repository->getDefaultStartingPointID()
184 && $id !== $this->starting_point_repository->getUserStartingPointID()) {
185 $delete_url = $this->ctrl->getLinkTarget(
186 $this->getParentObject(),
187 'deleteStartingPoint'
188 );
189 $actions[] = $this->ui_factory->link()->standard(
190 $this->lng->txt('delete'),
191 $delete_url
192 );
193 }
194
195 return $actions;
196 }
197
198 private function getEditLink(int $id, ?int $role_id): string
199 {
200 $cmd = 'initRoleStartingPointForm';
201 if ($id === $this->starting_point_repository->getUserStartingPointID()) {
202 $cmd = 'initUserStartingPointForm';
203 }
204
205 $this->ctrl->setParameter($this->getParentObject(), 'rolid', $role_id);
206 return $this->ctrl->getLinkTargetByClass(
207 get_class($this->getParentObject()),
208 $cmd
209 );
210 }
211
212 private function isSortingHidden(int $id): bool
213 {
214 if ($id === $this->starting_point_repository->getDefaultStartingPointID()) {
215 return true;
216 }
217 return false;
218 }
219
220 private function getTitleForCriterium(
221 int $id,
222 ?int $role_id,
223 string $criterium
224 ): string {
225 if ($id === $this->starting_point_repository->getDefaultStartingPointID()
226 || $id === $this->starting_point_repository->getUserStartingPointID()) {
227 return $criterium;
228 }
229
230 $parent_title = '';
231 if ($role_id !== null && ilObject::_lookupType($role_id) === 'role') {
232 $ref_id = $this->rbac_review->getObjectReferenceOfRole($role_id);
233 if ($ref_id !== ROLE_FOLDER_ID) {
234 $parent_title = ' (' . ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)) . ')';
235 }
236 }
237 return $this->lng->txt('has_role') . ': '
238 . ilObjRole::_getTranslation($criterium)
239 . $parent_title;
240 }
241}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
Class ilObjRole.
static _getTranslation(string $a_role_title)
class ilObjectDataCache
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
TableGUI class for LTI consumer listing.
__construct(object $parent_obj, private Repository $starting_point_repository, private ilRbacReview $rbac_review, private UIFactory $ui_factory, private Renderer $ui_renderer,)
getTitleForCriterium(int $id, ?int $role_id, string $criterium)
const ROLE_FOLDER_ID
Definition: constants.php:34
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))