ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
GroupingHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ilLanguage;
31 use ilObject;
36 
38 {
39  protected const string ID = 'grouping_id';
40  protected const string ACTION = 'table_action';
41  protected const string NAMESPACE = 'grouping';
42 
43  public const string ACTION_DELETE = 'delete';
44  public const string ACTION_EDIT = 'edit';
45 
46  public const string COL_TITLE = 'title';
47  public const string COL_DESCRIPTION = 'description';
48  public const string COL_SOURCE = 'source';
49  public const string COL_UNIQUE_FIELD = 'unique_field';
50  public const string COL_ASSIGNED_OBJS = 'assigned_objs';
51 
56 
57  public function __construct(
58  protected string $action,
59  protected int $content_obj_id,
60  protected ilLanguage $lng,
61  protected UIFactory $ui_factory,
62  protected DataFactory $data_factory,
63  protected HTTP $http,
64  protected Refinery $refinery,
66  ) {
67  $this->data_retrieval = new GroupingRetrieval(
68  $this->content_obj_id,
69  $this->lng,
70  $this->ui_factory,
71  $this->data_factory,
72  $static_url
73  );
74  }
75 
76  public function getTable(): DataTable
77  {
78  return $this->ui_factory->table()->data(
79  $this->data_retrieval,
80  $this->lng->txt('groupings'),
81  $this->buildColumns()
82  )->withRequest($this->http->request())
83  ->withActions($this->buildActions());
84  }
85 
89  protected function buildColumns(): array
90  {
91  $f = $this->ui_factory->table()->column();
92  $type = ilObject::_lookupType($this->content_obj_id);
93  return [
94  self::COL_TITLE => $f->text($this->lng->txt('title'))->withIsSortable(true),
95  self::COL_DESCRIPTION => $f->text($this->lng->txt('description'))->withIsSortable(true),
96  self::COL_SOURCE => $f->link($this->lng->txt('groupings_source'))->withIsSortable(true),
97  self::COL_UNIQUE_FIELD => $f->text($this->lng->txt('unambiguousness'))->withIsSortable(true),
98  self::COL_ASSIGNED_OBJS => $f->linkListing($this->lng->txt('groupings_assigned_obj_' . $type))->withIsSortable(true)
99  ];
100  }
101 
105  protected function buildActions(): array
106  {
107  $f = $this->ui_factory->table()->action();
108  return [
109  self::ACTION_EDIT => $f->single(
110  $this->lng->txt('edit'),
111  $this->URLBuilder()->withParameter($this->actionToken(), self::ACTION_EDIT),
112  $this->IDToken()
113  ),
114  self::ACTION_DELETE => $f->standard(
115  $this->lng->txt('delete'),
116  $this->URLBuilder()->withParameter($this->actionToken(), self::ACTION_DELETE),
117  $this->IDToken()
118  )
119  ];
120  }
121 
122  protected function URLBuilder(): URLBuilder
123  {
124  if (!isset($this->url_builder)) {
125  $this->initURLBuilderAndTokens();
126  }
127  return $this->url_builder;
128  }
129 
130  protected function actionToken(): URLBuilderToken
131  {
132  if (!isset($this->action_token)) {
133  $this->initURLBuilderAndTokens();
134  }
135  return $this->action_token;
136  }
137 
138  protected function IDToken(): URLBuilderToken
139  {
140  if (!isset($this->id_token)) {
141  $this->initURLBuilderAndTokens();
142  }
143  return $this->id_token;
144  }
145 
146  protected function initURLBuilderAndTokens(): void
147  {
148  $url_builder = new URLBuilder($this->data_factory->uri(
149  ltrim(ILIAS_HTTP_PATH, '/') . '/' . $this->action
150  ));
151  list($url_builder, $action_token, $id_token) = $url_builder->acquireParameters(
152  [self::NAMESPACE],
153  self::ACTION,
154  self::ID
155  );
156  $this->url_builder = $url_builder;
157  $this->action_token = $action_token;
158  $this->id_token = $id_token;
159  }
160 
161  public function getSelectedTableAction(): string
162  {
163  $action = '';
164  if ($this->http->wrapper()->query()->has($this->actionToken()->getName())) {
165  $action = $this->http->wrapper()->query()->retrieve(
166  $this->actionToken()->getName(),
167  $this->refinery->identity()
168  );
169  }
170  return $action;
171  }
172 
176  public function getSelectedGroupingIDs(): array
177  {
178  $grouping_ids = [];
179  $data_retrieval = $this->data_retrieval;
180 
181  $retrieval_trafo = $this->refinery->byTrying([
182  $this->refinery->custom()->transformation(function ($v) use ($data_retrieval) {
183  if ((string) $v[0] === 'ALL_OBJECTS') {
184  return $data_retrieval->getAllGroupingIDs();
185  }
186  throw new \Exception('not all selected');
187  }),
188  $this->refinery->kindlyTo()->listOf(
189  $this->refinery->kindlyTo()->int()
190  )
191  ]);
192 
193  if ($this->http->wrapper()->query()->has($this->IDToken()->getName())) {
194  $grouping_ids = $this->http->wrapper()->query()->retrieve(
195  $this->IDToken()->getName(),
196  $retrieval_trafo
197  );
198  }
199 
200  return $grouping_ids;
201  }
202 }
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138
$http
Definition: deliver.php:30
$static_url
Definition: goto.php:29
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected string $action, protected int $content_obj_id, protected ilLanguage $lng, protected UIFactory $ui_factory, protected DataFactory $data_factory, protected HTTP $http, protected Refinery $refinery, StaticURL $static_url)
global $lng
Definition: privfeed.php:31
URLBuilder.
Definition: URLBuilder.php:40
static _lookupType(int $id, bool $reference=false)