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