ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
Table.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\GlobalScreen\GUI\I18n\Translator;
25use Psr\Http\Message\ServerRequestInterface;
26use Generator;
36
41{
42 public const string F_ALIAS = 'alias';
43 public const string F_ACTIVE = 'active';
44 public const string ACTION_TOGGLE = 'toggle';
45 public const string ACTION_DELETE = 'delete';
46 public const string ACTION_EDIT = 'edit';
47 public const string F_PREFIX = 'prefix';
48 public const string F_TARGET_LINK = 'target_link';
50 private Translator $i18n;
51 private ServerRequestInterface $request;
52 private string $link_prefix;
53
54 public function __construct(
55 private Pons $pons,
56 private Repository $repository,
57 private TargetLinkResolver $link_resolver,
58 private URI $ordering_target,
59 private TokenContainer $token,
60 Configuration $config,
61 private bool $can_edit = false,
62 ) {
63 $this->ui_factory = $pons->out()->ui()->factory();
64 $this->i18n = $pons->i18n();
65 $this->request = $pons->in()->request();
66 $this->link_prefix = $config->get(Config::ULTRA_SHORT)
67 ? ''
68 : $config->get(Config::STATIC_LINK_ENDPOINT) . $config->get(Config::SHORTLINK_NAMESPACE) . '/';
69 }
70
71 public function getRows(
72 OrderingRowBuilder $row_builder,
73 array $visible_column_ids
74 ): Generator {
75 foreach ($this->repository->getAll() as $shortlink) {
80 yield $row_builder->buildOrderingRow(
81 $this->pons->in()->hash($shortlink->getId()),
82 [
83 self::F_PREFIX => $this->link_prefix,
84 self::F_ALIAS => $this
85 ->ui_factory
86 ->link()
87 ->standard(
88 $shortlink->getAliasForPresentation($this->link_prefix),
89 $this->link_prefix . $shortlink->getAlias()
90 )
91 ->withOpenInNewViewport(true),
92 self::F_TARGET_LINK => $this
93 ->link_resolver
94 ->resolveLink($shortlink)
95 ?->withOpenInNewViewport(true),
96 self::F_ACTIVE => $shortlink->isActive(),
97 ]
98 )->withDisabledAction(
99 self::ACTION_EDIT,
100 !$this->can_edit
101 )->withDisabledAction(
102 self::ACTION_TOGGLE,
103 !$this->can_edit
104 )->withDisabledAction(
105 self::ACTION_DELETE,
106 !$this->can_edit
107 );
108 }
109 }
110
111 public function get(): \Generator
112 {
113 if ($this->can_edit) {
114 $actions = [
115 self::ACTION_TOGGLE => $this
116 ->ui_factory
117 ->table()
118 ->action()
119 ->standard(
120 $this->i18n->t(self::ACTION_TOGGLE, 'action'),
121 $this->token->builder()->withURI(
122 $this->pons->flow()->getHereAsURI(\ShortlinkAdministrationGUI::CMD_CONFIRM_TOGGLE)
123 ),
124 $this->token->token()
125 )
126 ->withAsync(true),
127 self::ACTION_EDIT => $this
128 ->ui_factory
129 ->table()
130 ->action()
131 ->standard(
132 $this->i18n->t(self::ACTION_EDIT, 'action'),
133 $this->token->builder()->withURI(
134 $this->pons->flow()->getHereAsURI(\ShortlinkAdministrationGUI::CMD_FORM)
135 ),
136 $this->token->token()
137 )
138 ->withAsync(true),
139 self::ACTION_DELETE => $this
140 ->ui_factory
141 ->table()
142 ->action()
143 ->standard(
144 $this->i18n->t(self::ACTION_DELETE, 'action'),
145 $this->token->builder()->withURI(
146 $this->pons->flow()->getHereAsURI(\ShortlinkAdministrationGUI::CMD_CONFIRM_DELETE)
147 ),
148 $this->token->token()
149 )
150 ->withAsync(true),
151 ];
152 } else {
153 $actions = [];
154 }
155
156 yield $this
157 ->ui_factory
158 ->table()
159 ->ordering(
160 $this,
161 $this->ordering_target,
162 $this->i18n->t('shortlinks'),
163 [
164 /*self::F_PREFIX => $this->ui_factory->table()->column()->text(
165 $this->i18n->t(self::F_PREFIX),
166 ),*/
167 self::F_ALIAS => $this->ui_factory->table()->column()->link(
168 $this->i18n->t(self::F_ALIAS),
169 ),
170 self::F_TARGET_LINK => $this->ui_factory->table()->column()->link(
171 $this->i18n->t(self::F_TARGET_LINK),
172 ),
173 self::F_ACTIVE => $this->ui_factory->table()->column()->boolean(
174 $this->i18n->t(self::F_ACTIVE),
175 $this->pons->out()->ok(),
176 $this->pons->out()->nok(),
177 )
178 ]
179 )
180 ->withOrderingDisabled(
181 !$this->can_edit
182 )
183 ->withRequest($this->request)
184 ->withActions($actions);
185 }
186
187}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getRows(OrderingRowBuilder $row_builder, array $visible_column_ids)
This is called by the (ordering-)table to retrieve rows; map data-records to rows using the $row_buil...
buildOrderingRow(string $id, array $record)
This is how the factory for UI elements looks.
Definition: Factory.php:38
$token
Definition: xapitoken.php:67