ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ProfileUserAssignmentTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Table;
22
23use ILIAS\Data;
28use ILIAS\UI;
29use Psr\Http\Message\ServerRequestInterface;
30
35{
36 protected \ilCtrl $ctrl;
37 protected \ilLanguage $lng;
38 protected UI\Factory $ui_fac;
39 protected UI\Renderer $ui_ren;
40 protected ServerRequestInterface $request;
42 protected Data\Factory $df;
52
54 {
55 global $DIC;
56
57 $this->ctrl = $DIC->ctrl();
58 $this->lng = $DIC->language();
59 $this->ui_fac = $DIC->ui()->factory();
60 $this->ui_ren = $DIC->ui()->renderer();
61 $this->request = $DIC->http()->request();
62 $this->query = $DIC->http()->wrapper()->query();
63 $this->df = new Data\Factory();
64 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
65
66 $this->profile = $profile;
67 $this->tree_access_manager = $tree_access_manager;
68 $this->profile_manager = $DIC->skills()->internal()->manager()->getProfileManager();
69 $this->requested_table_profile_user_ass_action = $this->admin_gui_request->getTableProfileUserAssignmentAction();
70 $this->requested_table_profile_user_ass_ids = $this->admin_gui_request->getTableProfileUserAssignmentIds();
71 }
72
73 public function getComponent(): UI\Component\Table\Data
74 {
75 $columns = $this->getColumns();
76 $actions = $this->getActions();
77 $data_retrieval = $this->getDataRetrieval();
78
79 if ($this->requested_table_profile_user_ass_action === "removeUsers") {
80 $items = [];
81 foreach ($this->requested_table_profile_user_ass_ids as $id) {
82 if ($id === "ALL_OBJECTS") {
83 $all_assignments = $this->profile_manager->getAssignments($this->profile->getId());
84 foreach ($all_assignments as $assignment) {
85 $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
86 (string) $assignment->getId(),
87 $this->getAssignmentTitle($assignment->getId())
88 );
89 }
90 } else {
91 $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
92 $id,
93 $this->getAssignmentTitle((int) $id)
94 );
95 }
96 }
97 echo($this->ui_ren->renderAsync([
98 $this->ui_fac->modal()->interruptive(
99 "",
100 empty($items) ? $this->lng->txt("no_checkbox") : $this->lng->txt("skmg_confirm_user_removal"),
101 $this->ctrl->getFormActionByClass("ilskillprofilegui", "removeUsers")
102 )
103 ->withAffectedItems($items)
104 ->withActionButtonLabel(empty($items) ? $this->lng->txt("ok") : $this->lng->txt("delete"))
105 ]));
106 exit();
107 }
108
109 $table = $this->ui_fac->table()
110 ->data($data_retrieval, $this->lng->txt("skmg_assigned_users"), $columns)
111 ->withId(
112 self::class . "_" .
113 $this->profile->getId()
114 )
115 ->withActions($actions)
116 ->withRequest($this->request);
117
118 return $table;
119 }
120
121 protected function getColumns(): array
122 {
123 $columns = [
124 "type" => $this->ui_fac->table()->column()->text($this->lng->txt("type"))
125 ->withIsSortable(false),
126 "name" => $this->ui_fac->table()->column()->text($this->lng->txt("name")),
127 "object" => $this->ui_fac->table()->column()->text($this->lng->txt("object"))
128 ];
129
130 return $columns;
131 }
132
133 protected function getActions(): array
134 {
135 $query_params_namespace = ["skl_profile_user_assignment_table"];
136
137 $url_builder_delete = new UI\URLBuilder($this->df->uri($this->request->getUri()->__toString()));
138 list($url_builder_delete, $action_parameter_token_delete, $row_id_token_delete) =
139 $url_builder_delete->acquireParameters(
140 $query_params_namespace,
141 "action",
142 "ass_ids"
143 );
144
145 $actions = [];
146 if ($this->tree_access_manager->hasManageProfilesPermission() && !$this->profile->getRefId() > 0) {
147 $actions["delete"] = $this->ui_fac->table()->action()->multi(
148 $this->lng->txt("delete"),
149 $url_builder_delete->withParameter($action_parameter_token_delete, "removeUsers"),
150 $row_id_token_delete
151 )
152 ->withAsync();
153 }
154
155 return $actions;
156 }
157
158 protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
159 {
160 $data_retrieval = new class (
163 ) implements UI\Component\Table\DataRetrieval {
164 use TableRecords;
165
166 public function __construct(
167 protected Profile\SkillProfile $profile,
168 protected Profile\SkillProfileManager $profile_manager
169 ) {
170 }
171
172 public function getRows(
173 UI\Component\Table\DataRowBuilder $row_builder,
174 array $visible_column_ids,
176 Data\Order $order,
177 mixed $additional_viewcontrol_data,
178 mixed $filter_data,
179 mixed $additional_parameters
180 ): \Generator {
181 $records = $this->getRecords($range, $order);
182 foreach ($records as $idx => $record) {
183 $row_id = $record["id"];
184
185 yield $row_builder->buildDataRow((string) $row_id, $record);
186 }
187 }
188
189 public function getTotalRowCount(
190 mixed $additional_viewcontrol_data,
191 mixed $filter_data,
192 mixed $additional_parameters
193 ): ?int {
194 return count($this->getRecords());
195 }
196
197 protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
198 {
199 $assignments = $this->profile_manager->getAssignments($this->profile->getId());
200
201 $records = [];
202 $i = 0;
203 foreach ($assignments as $assignment) {
204 $records[$i]["id"] = $assignment->getId();
205 $records[$i]["type"] = $assignment->getType();
206 $records[$i]["name"] = $assignment->getName();
207 $records[$i]["object"] = ($assignment instanceof Profile\SkillProfileRoleAssignment)
208 ? $assignment->getObjTitle()
209 : "";
210
211 $i++;
212 }
213
214 if ($order) {
215 $records = $this->orderRecords($records, $order);
216 }
217
218 if ($range) {
219 $records = $this->limitRecords($records, $range);
220 }
221
222 return $records;
223 }
224 };
225
226 return $data_retrieval;
227 }
228
229 protected function getAssignmentTitle(int $obj_id): string
230 {
231 $type = \ilObject::_lookupType($obj_id);
232 switch ($type) {
233 case "usr":
234 $ass_title = \ilUserUtil::getNamePresentation($obj_id);
235 break;
236
237 case "role":
238 $ass_title = \ilObjRole::_lookupTitle($obj_id);
239 break;
240
241 default:
242 $ass_title = $this->lng->txt("not_available");
243 }
244
245 return $ass_title;
246 }
247}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Request wrapper for guis in skill administration.
__construct(Profile\SkillProfile $profile, Access\SkillTreeAccess $tree_access_manager)
Definition: UI.php:24
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26