ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilCtrl;
24use ILIAS\Data\Factory as DataFactory;
26use ILIAS\HTTP\Services as HTTPServices;
29use ILIAS\UI\Component\Table\Data as DataTable;
31use ILIAS\UI\URLBuilderToken as ilURLBuilderToken;
32use ilLanguage;
33use ILIAS\Refinery\Factory as RefineryFactory;
35
36class Handler implements HandlerInterface
37{
38 protected const string TABLE_ID = "sc_groups";
39 protected const string TABLE_ACTION_ID = "table_action";
40 protected const string ROW_ID = "row_ids";
41 public const string TABLE_COL_TITLE = 'title';
42 public const string TABLE_COL_DESCRIPTION = 'description';
43 public const string TABLE_COL_LAST_UPDATE = 'last_update';
44 public const string TABLE_COL_STATUS = 'status';
45 protected const string LNG_TABLE_TITLE = 'sysc_task_overview';
46 protected const string LNG_TABLE_COL_TITLE = 'title';
47 protected const string LNG_TABLE_COL_DESCRIPTION = 'description';
48 protected const string LNG_TABLE_COL_LAST_UPDATE = 'last_update';
49 protected const string LNG_TABLE_COL_STATUS = 'status';
50
51 protected DataTable $table;
53 protected ilURLBuilderToken $action_parameter_token;
54 protected ilURLBuilderToken $row_id_token;
55
56 public function __construct(
57 protected readonly DataFactory $data_factory,
58 protected readonly UIServices $ui,
59 protected readonly ilLanguage $lng,
60 protected readonly HTTPServices $http,
61 protected readonly DataRetrievalInterface $data_retrieval,
62 protected readonly RefineryFactory $refinery,
63 protected readonly ilCtrl $ctrl,
64 protected readonly bool $actions_permitted = false
65 ) {
66 $this->initTable();
67 }
68
69 final protected function getColumns(): array
70 {
71 return [
72 self::TABLE_COL_TITLE => $this->ui->factory()->table()->column()->text(
73 $this->lng->txt(self::LNG_TABLE_COL_TITLE)
74 )->withIsSortable(true),
75 self::TABLE_COL_DESCRIPTION => $this->ui->factory()->table()->column()->text(
76 $this->lng->txt(self::LNG_TABLE_COL_DESCRIPTION)
77 )->withIsSortable(true),
78 self::TABLE_COL_LAST_UPDATE => $this->ui->factory()->table()->column()->text(
79 $this->lng->txt(self::LNG_TABLE_COL_LAST_UPDATE)
80 )->withIsSortable(true),
81 self::TABLE_COL_STATUS => $this->ui->factory()->table()->column()->text(
82 $this->lng->txt(self::LNG_TABLE_COL_STATUS)
83 )->withIsSortable(true)
84 ];
85 }
86
87 final protected function getActions(): array
88 {
89 if (!$this->actions_permitted) {
90 return [];
91 }
92 $this->url_builder = new URLBuilder($this->data_factory->uri($this->http->request()->getUri()->__toString()));
93 list($this->url_builder, $this->action_parameter_token, $this->row_id_token) =
94 $this->url_builder->acquireParameters(
95 ['datatable', self::TABLE_ID],
96 self::TABLE_ACTION_ID,
97 self::ROW_ID
98 );
99 $actions = [];
100 foreach ($this->data_retrieval->getAllActions() as $command => $txt) {
101 $actions[$command] = $this->ui->factory()->table()->action()->single(
102 $txt,
103 $this->url_builder->withParameter($this->action_parameter_token, $command),
104 $this->row_id_token
105 );
106 }
107 return $actions;
108 }
109
110 final protected function initTable(): void
111 {
112 if (!isset($this->table)) {
113 $this->table = $this->ui->factory()->table()->data(
114 $this->data_retrieval,
115 $this->lng->txt(self::LNG_TABLE_TITLE),
116 $this->getColumns(),
117 )
118 ->withActions($this->getActions())
119 ->withId(self::TABLE_ID)->withRequest($this->http->request());
120 }
121 }
122
123 final protected function getTable(): DataTable
124 {
125 return $this->table;
126 }
127
128 final public function getHTML(): string
129 {
130 return $this->ui->renderer()->render([$this->getTable()]);
131 }
132
133 final public function handleTableActions(): void
134 {
135 if (!$this->http->wrapper()->query()->has($this->action_parameter_token->getName())) {
136 return;
137 }
138 if (!$this->http->wrapper()->query()->has($this->row_id_token->getName())) {
139 return;
140 }
141 if (!$this->actions_permitted) {
142 return;
143 }
144 $action = $this->http->wrapper()->query()->retrieve(
145 $this->action_parameter_token->getName(),
146 $this->refinery->kindlyTo()->string()
147 );
148 $tokens = $this->http->wrapper()->query()->retrieve(
149 $this->row_id_token->getName(),
150 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
151 );
152 $task_id = (int) $tokens[0];
153 $task_handler = ilSCComponentTaskFactory::getComponentTask($task_id);
154 $this->ctrl->setParameterByClass(get_class($task_handler), 'task_id', $task_id);
155 $this->ctrl->redirectByClass(get_class($task_handler), $action);
156 $this->ctrl->clearParameterByClass(get_class($task_handler), 'task_id');
157 }
158}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:43
ilURLBuilderToken $row_id_token
Definition: Handler.php:54
__construct(protected readonly DataFactory $data_factory, protected readonly UIServices $ui, protected readonly ilLanguage $lng, protected readonly HTTPServices $http, protected readonly DataRetrievalInterface $data_retrieval, protected readonly RefineryFactory $refinery, protected readonly ilCtrl $ctrl, protected readonly bool $actions_permitted=false)
Definition: Handler.php:56
ilURLBuilderToken $action_parameter_token
Definition: Handler.php:53
Class ilCtrl provides processing control methods.
language handling
This describes a Data Table.
Definition: Data.php:33
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:26