ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.TreeTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Skill\Table;
22 
23 use ILIAS\Data;
24 use ILIAS\UI;
29 
33 class TreeTable
34 {
35  protected \ilCtrl $ctrl;
36  protected \ilLanguage $lng;
37  protected UI\Factory $ui_fac;
39  protected Data\Factory $df;
40  protected Service\SkillInternalManagerService $skill_manager;
41  protected Access\SkillManagementAccess $skill_management_access_manager;
42  protected Tree\SkillTreeManager $skill_tree_manager;
43  protected Tree\SkillTreeFactory $skill_tree_factory;
44 
45  public function __construct(int $ref_id)
46  {
47  global $DIC;
48 
49  $this->ctrl = $DIC->ctrl();
50  $this->lng = $DIC->language();
51  $this->ui_fac = $DIC->ui()->factory();
52  $this->request = $DIC->http()->request();
53  $this->df = new Data\Factory();
54  $this->skill_manager = $DIC->skills()->internal()->manager();
55  $this->skill_management_access_manager = $this->skill_manager->getManagementAccessManager($ref_id);
56  $this->skill_tree_manager = $this->skill_manager->getTreeManager();
57  $this->skill_tree_factory = $DIC->skills()->internal()->factory()->tree();
58  }
59 
60  public function getComponent(): UI\Component\Table\Data
61  {
62  $columns = $this->getColumns();
63  $actions = $this->getActions();
64  $data_retrieval = $this->getDataRetrieval();
65 
66  $table = $this->ui_fac->table()
67  ->data($data_retrieval, $this->lng->txt("skmg_skill_trees"), $columns)
68  ->withId(self::class)
69  ->withActions($actions)
70  ->withRequest($this->request);
71 
72  return $table;
73  }
74 
75  protected function getColumns(): array
76  {
77  $columns = [
78  "title" => $this->ui_fac->table()->column()->link($this->lng->txt("title"))
79  ];
80 
81  return $columns;
82  }
83 
84  protected function getActions(): array
85  {
86  $query_params_namespace = ["skl_tree_table"];
87 
88  $uri_delete = $this->df->uri(
89  ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass("ilobjskilltreegui", "delete")
90  );
91  $url_builder_delete = new UI\URLBuilder($uri_delete);
92  list($url_builder_delete, $action_parameter_token_delete, $row_id_token_delete) =
93  $url_builder_delete->acquireParameters(
94  $query_params_namespace,
95  "action",
96  "tree_ids"
97  );
98 
99  $actions = [];
100  if ($this->skill_management_access_manager->hasCreateTreePermission()) {
101  $actions["delete"] = $this->ui_fac->table()->action()->multi(
102  $this->lng->txt("delete"),
103  $url_builder_delete->withParameter($action_parameter_token_delete, "deleteTrees"),
104  $row_id_token_delete
105  );
106  }
107 
108  return $actions;
109  }
110 
111  protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
112  {
113  $data_retrieval = new class (
119  ) implements UI\Component\Table\DataRetrieval {
120  use TableRecords;
121 
122  public function __construct(
123  protected Service\SkillInternalManagerService $skill_manager,
124  protected Tree\SkillTreeManager $skill_tree_manager,
125  protected Tree\SkillTreeFactory $skill_tree_factory,
126  protected UI\Factory $ui_fac,
127  protected \ilCtrl $ctrl
128  ) {
129  }
130 
131  public function getRows(
132  UI\Component\Table\DataRowBuilder $row_builder,
133  array $visible_column_ids,
134  Data\Range $range,
135  Data\Order $order,
136  ?array $filter_data,
137  ?array $additional_parameters
138  ): \Generator {
139  $records = $this->getRecords($range, $order);
140  foreach ($records as $idx => $record) {
141  $row_id = (string) $record["tree_id"];
142 
143  yield $row_builder->buildDataRow($row_id, $record);
144  }
145  }
146 
147  public function getTotalRowCount(
148  ?array $filter_data,
149  ?array $additional_parameters
150  ): ?int {
151  return count($this->getRecords());
152  }
153 
154  protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
155  {
156  $items = array_filter(array_map(
157  function (\ilObjSkillTree $skillTree): array {
158  $tree_access_manager = $this->skill_manager->getTreeAccessManager($skillTree->getRefId());
159  if ($tree_access_manager->hasVisibleTreePermission()) {
160  return [
161  "tree" => $skillTree
162  ];
163  }
164  return [];
165  },
166  iterator_to_array($this->skill_tree_manager->getTrees())
167  ));
168 
169  $records = [];
170  $i = 0;
171  foreach ($items as $item) {
173  $tree_obj = $item["tree"];
174  $tree = $this->skill_tree_factory->getTreeById($tree_obj->getId());
175  $records[$i]["tree_id"] = $tree->readRootId();
176  $this->ctrl->setParameterByClass("ilobjskilltreegui", "ref_id", $tree_obj->getRefId());
177  $records[$i]["title"] = $this->ui_fac->link()->standard(
178  $tree_obj->getTitle(),
179  $this->ctrl->getLinkTargetByClass("ilobjskilltreegui", "editSkills")
180  );
181  $this->ctrl->clearParameterByClass("ilobjskilltreegui", "ref_id");
182  $i++;
183  }
184 
185  if ($order) {
186  $records = $this->orderRecords($records, $order);
187  }
188 
189  if ($range) {
190  $records = $this->limitRecords($records, $range);
191  }
192 
193  return $records;
194  }
195  };
196 
197  return $data_retrieval;
198  }
199 }
Skill tree object in skill management (repository object class)
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Service SkillInternalManagerService $skill_manager
$ref_id
Definition: ltiauth.php:65
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:22
Access SkillManagementAccess $skill_management_access_manager
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28