ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ProfileTable.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;
25 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;
42  protected ArrayBasedRequestWrapper $query;
43  protected Data\Factory $df;
44  protected Access\SkillTreeAccess $tree_access_manager;
45  protected Profile\SkillProfileManager $profile_manager;
46  protected Service\SkillAdminGUIRequest $admin_gui_request;
47  protected string $requested_table_profile_action = "";
48 
52  protected array $requested_table_profile_ids = [];
53  protected int $skill_tree_id = 0;
54 
55  public function __construct(int $ref_id, int $skill_tree_id)
56  {
57  global $DIC;
58 
59  $this->ctrl = $DIC->ctrl();
60  $this->lng = $DIC->language();
61  $this->ui_fac = $DIC->ui()->factory();
62  $this->ui_ren = $DIC->ui()->renderer();
63  $this->request = $DIC->http()->request();
64  $this->query = $DIC->http()->wrapper()->query();
65  $this->df = new Data\Factory();
66  $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($ref_id);
67  $this->profile_manager = $DIC->skills()->internal()->manager()->getProfileManager();
68  $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
69  $this->requested_table_profile_action = $this->admin_gui_request->getTableProfileAction();
70  $this->requested_table_profile_ids = $this->admin_gui_request->getTableProfileIds();
71  $this->skill_tree_id = $skill_tree_id;
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_action === "deleteProfiles") {
81  $items = [];
82  foreach ($this->requested_table_profile_ids as $id) {
83  if ($id === "ALL_OBJECTS") {
84  $profiles = $this->skill_tree_id
85  ? $this->profile_manager->getProfilesForSkillTree($this->skill_tree_id)
86  : $this->profile_manager->getProfilesForAllSkillTrees();
87  foreach ($profiles as $profile) {
88  $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
89  (string) $profile->getId(),
90  $profile->getTitle()
91  );
92  }
93  } else {
94  $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
95  $id,
96  $this->profile_manager->lookupTitle((int) $id)
97  );
98  }
99  }
100  echo($this->ui_ren->renderAsync([
101  $this->ui_fac->modal()->interruptive(
102  "",
103  empty($items) ? $this->lng->txt("no_checkbox") : $this->lng->txt("skmg_delete_profiles"),
104  $this->ctrl->getFormActionByClass("ilskillprofilegui", "deleteProfiles")
105  )
106  ->withAffectedItems($items)
107  ->withActionButtonLabel(empty($items) ? $this->lng->txt("ok") : $this->lng->txt("delete"))
108  ]));
109  exit();
110  }
111 
112  $table = $this->ui_fac->table()
113  ->data($this->lng->txt("skmg_skill_profiles"), $columns, $data_retrieval)
114  ->withId(
115  self::class . "_" .
116  $this->skill_tree_id
117  )
118  ->withActions($actions)
119  ->withRequest($this->request);
120 
121  return $table;
122  }
123 
124  protected function getColumns(): array
125  {
126  $columns = [
127  "title" => $this->ui_fac->table()->column()->link($this->lng->txt("title")),
128  "context" => $this->ui_fac->table()->column()->text($this->lng->txt("context"))
129  ->withIsSortable(false),
130  "users" => $this->ui_fac->table()->column()->text($this->lng->txt("users"))
131  ->withIsSortable(false),
132  "roles" => $this->ui_fac->table()->column()->text($this->lng->txt("roles"))
133  ->withIsSortable(false),
134  ];
135 
136  return $columns;
137  }
138 
139  protected function getActions(): array
140  {
141  $query_params_namespace = ["skl_profile_table"];
142 
143  $url_builder_delete = new UI\URLBuilder($this->df->uri($this->request->getUri()->__toString()));
144  list($url_builder_delete, $action_parameter_token_delete, $row_id_token_delete) =
145  $url_builder_delete->acquireParameters(
146  $query_params_namespace,
147  "action",
148  "profile_ids"
149  );
150 
151  $uri_export = $this->df->uri(
152  ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass("ilskillprofilegui", "exportProfiles")
153  );
154  $url_builder_export = new UI\URLBuilder($uri_export);
155  list($url_builder_export, $action_parameter_token_export, $row_id_token_export) =
156  $url_builder_export->acquireParameters(
157  $query_params_namespace,
158  "action",
159  "profile_ids"
160  );
161 
162  $actions = [];
163  if ($this->tree_access_manager->hasManageProfilesPermission()) {
164  $actions["delete"] = $this->ui_fac->table()->action()->multi(
165  $this->lng->txt("delete"),
166  $url_builder_delete->withParameter($action_parameter_token_delete, "deleteProfiles"),
167  $row_id_token_delete
168  )
169  ->withAsync();
170  $actions["export"] = $this->ui_fac->table()->action()->multi(
171  $this->lng->txt("export"),
172  $url_builder_export->withParameter($action_parameter_token_export, "exportProfiles"),
173  $row_id_token_export
174  );
175  }
176 
177  return $actions;
178  }
179 
181  {
182  $data_retrieval = new class (
183  $this->lng,
188  ) implements UI\Component\Table\DataRetrieval {
189  use TableRecords;
190 
191  public function __construct(
192  protected \ilLanguage $lng,
193  protected int $skill_tree_id,
194  protected Profile\SkillProfileManager $skill_profile_manager,
195  protected UI\Factory $ui_fac,
196  protected \ilCtrl $ctrl
197  ) {
198  }
199 
200  public function getRows(
201  UI\Component\Table\DataRowBuilder $row_builder,
202  array $visible_column_ids,
203  Data\Range $range,
204  Data\Order $order,
205  ?array $filter_data,
206  ?array $additional_parameters
207  ): \Generator {
208  $records = $this->getRecords($range, $order);
209  foreach ($records as $idx => $record) {
210  $row_id = (string) $record["profile_id"];
211 
212  yield $row_builder->buildDataRow($row_id, $record);
213  }
214  }
215 
216  public function getTotalRowCount(
217  ?array $filter_data,
218  ?array $additional_parameters
219  ): ?int {
220  return count($this->getRecords());
221  }
222 
223  protected function getRecords(Data\Range $range = null, Data\Order $order = null): array
224  {
225  if ($this->skill_tree_id) {
226  $profiles = $this->skill_profile_manager->getProfilesForSkillTree($this->skill_tree_id);
227  } else {
228  $profiles = $this->skill_profile_manager->getProfilesForAllSkillTrees();
229  }
230 
231  $records = [];
232  $i = 0;
233  foreach ($profiles as $profile) {
234  $records[$i]["profile_id"] = $profile->getId();
235  $this->ctrl->setParameterByClass("ilskillprofilegui", "sprof_id", $profile->getId());
236  $records[$i]["title"] = $this->ui_fac->link()->standard(
237  $profile->getTitle(),
238  $this->ctrl->getLinkTargetByClass("ilskillprofilegui", "showLevels")
239  );
240  $this->ctrl->clearParameterByClass("ilskillprofilegui", "sprof_id");
241  $profile_ref_id = $this->skill_profile_manager->lookupRefId($profile->getId());
242  $profile_obj_id = \ilContainerReference::_lookupObjectId($profile_ref_id);
243  $profile_obj_title = \ilObject::_lookupTitle($profile_obj_id);
244  if ($profile_ref_id > 0) {
245  $records[$i]["context"] = $this->lng->txt("skmg_context_local") . " (" . $profile_obj_title . ")";
246  } else {
247  $records[$i]["context"] = $this->lng->txt("skmg_context_global");
248  }
249  $records[$i]["users"] = $this->skill_profile_manager->countUsers($profile->getId());
250  $records[$i]["roles"] = $this->skill_profile_manager->countRoles($profile->getId());
251  $i++;
252  }
253 
254  if ($order) {
255  $records = $this->orderRecords($records, $order);
256  }
257 
258  if ($range) {
259  $records = $this->limitRecords($records, $range);
260  }
261 
262  return $records;
263  }
264  };
265 
266  return $data_retrieval;
267  }
268 }
__construct(int $ref_id, int $skill_tree_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...
Service SkillAdminGUIRequest $admin_gui_request
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
$ref_id
Definition: ltiauth.php:66
static _lookupTitle(int $obj_id)
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:25
static _lookupObjectId(int $ref_id)
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:24
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...