ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ShortlinkAdministrationGUI Class Reference
+ Inheritance diagram for ShortlinkAdministrationGUI:
+ Collaboration diagram for ShortlinkAdministrationGUI:

Public Member Functions

 __construct (Pons $pons)
 
 executeCommand ()
 
 getTokensToKeep ()
 
- Public Member Functions inherited from ILIAS\GlobalScreen\GUI\AbstractPonsGUI
 __construct (protected Pons $pons)
 
 __construct (Pons $pons)
 
 executeCommand ()
 
 getTokensToKeep ()
 

Data Fields

const string CMD_FORM = 'form'
 
const string CMD_SAVE = 'save'
 
const string CMD_CONFIRM_DELETE = 'confirmDelete'
 
const string CMD_DELETE = 'delete'
 
const string CMD_CONFIRM_TOGGLE = 'confirmToggle'
 
const string CMD_TOGGLE = 'toggle'
 
const string CMD_SAVE_ORDERING = 'saveOrdering'
 
- Data Fields inherited from ILIAS\GlobalScreen\GUI\PonsGUI
const CMD_DEFAULT = 'index'
 

Private Member Functions

 getForm ()
 
 save ()
 
 form ()
 
 index ()
 
 confirm (string $target_command, string $title, string $message, string $button_title,)
 
 confirmDelete ()
 
 delete ()
 
 confirmToggle ()
 
 toggle ()
 
 saveOrdering ()
 
 getAllIds ()
 

Private Attributes

ilToolbarGUI $toolbar
 
Factory $ui_factory
 
Repository $repository
 
TokenContainer $token
 
TargetLinkResolver $link_resolver
 
Configuration $configuration
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ShortlinkAdministrationGUI::__construct ( Pons  $pons)

Implements ILIAS\GlobalScreen\GUI\PonsGUI.

Definition at line 61 of file ShortlinkAdministrationGUI.php.

62 {
63 global $DIC;
65 $this->toolbar = $pons->out()->toolbar();
66 $this->ui_factory = $pons->out()->ui()->factory();
67 $this->repository = new RepositoryDB(
68 $DIC->database(),
70 $DIC->repositoryTree()
71 )
72 );
73 $this->link_resolver = new TargetLinkResolver(
74 $DIC['static_url']->builder(),
75 $DIC[\ILIAS\Data\Factory::class],
76 $this->ui_factory,
77 );
78 $this->token = $this->pons->in()->buildToken('alias', 'id');
79 $this->configuration = $DIC['static_url.config'];
80 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\GlobalScreen\GUI\Pons\out(), ILIAS\UI\examples\Deck\repository(), and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

Member Function Documentation

◆ confirm()

ShortlinkAdministrationGUI::confirm ( string  $target_command,
string  $title,
string  $message,
string  $button_title 
)
private

Definition at line 211 of file ShortlinkAdministrationGUI.php.

216 : void {
217 $items = [];
218 $from_request = $this->getAllIds();
219
220 $this->pons->out()->nok();
221 $this->pons->out()->ok();
222
223 foreach ($from_request as $id) {
224 $shortlink = $this->repository->getById($id);
225 if ($shortlink === null) {
226 continue;
227 }
228 $id = $this->hash($id);
229
230 $items[] = $this->ui_factory->modal()->interruptiveItem()->standard(
231 $id,
232 $shortlink->getAlias(),
233 );
234 }
235
236 $this->pons->out()->outAsyncAsConfirmation(
237 $title,
238 $message,
239 $button_title,
240 $this->pons->flow()->getHereAsURI($target_command),
241 ...$items
242 );
243 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ confirmDelete()

ShortlinkAdministrationGUI::confirmDelete ( )
private

Definition at line 246 of file ShortlinkAdministrationGUI.php.

246 : void
247 {
248 $this->confirm(
249 self::CMD_DELETE,
250 $this->pons->i18n()->t('delete_shortlink'),
251 $this->pons->i18n()->t('delete_shortlink_msg'),
252 $this->pons->i18n()->t('delete')
253 );
254 }
confirm(string $target_command, string $title, string $message, string $button_title,)

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ confirmToggle()

ShortlinkAdministrationGUI::confirmToggle ( )
private

Definition at line 273 of file ShortlinkAdministrationGUI.php.

273 : void
274 {
275 $this->confirm(
276 self::CMD_TOGGLE,
277 $this->pons->i18n()->t('toggle_shortlink'),
278 $this->pons->i18n()->t('toggle_shortlink_msg'),
279 $this->pons->i18n()->t('toggle')
280 );
281 }

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ delete()

ShortlinkAdministrationGUI::delete ( )
private

Definition at line 257 of file ShortlinkAdministrationGUI.php.

257 : void
258 {
259 $from_request = $this->getAllIds();
260 foreach ($from_request as $id) {
261 $shortlink = $this->repository->getById($id);
262 if ($shortlink === null) {
263 continue;
264 }
265 $this->repository->delete($shortlink);
266 }
267
268 $this->pons->out()->success($this->pons->i18n()->t('shortlinks_deleted'));
269 $this->pons->flow()->redirect(self::CMD_DEFAULT);
270 }

References $id, and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ executeCommand()

ShortlinkAdministrationGUI::executeCommand ( )
Returns
bool true if you handled this command aka you were the CtrlClass, otherwise false

Implements ILIAS\GlobalScreen\GUI\PonsGUI.

Definition at line 102 of file ShortlinkAdministrationGUI.php.

102 : bool
103 {
104 if ($this->pons->handle(ilObjStaticUrlServiceGUI::TAB_INDEX)) {
105 return true;
106 }
107
108 match ($cmd = $this->pons->flow()->getCommand(self::CMD_DEFAULT)) {
109 self::CMD_DEFAULT => $this->index(),
110 self::CMD_FORM => $this->form(),
111 self::CMD_SAVE => $this->save(),
112 self::CMD_CONFIRM_DELETE => $this->confirmDelete(),
113 self::CMD_DELETE => $this->delete(),
114 self::CMD_CONFIRM_TOGGLE => $this->confirmToggle(),
115 self::CMD_TOGGLE => $this->toggle(),
116 self::CMD_SAVE_ORDERING => $this->saveOrdering(),
117 default => $this->pons->out()->outString(
118 'Unknown command: ' . $cmd
119 ),
120 };
121 return true;
122 }

References confirmDelete(), confirmToggle(), form(), index(), save(), saveOrdering(), ilObjStaticUrlServiceGUI\TAB_INDEX, and toggle().

+ Here is the call graph for this function:

◆ form()

ShortlinkAdministrationGUI::form ( )
private

Definition at line 157 of file ShortlinkAdministrationGUI.php.

157 : void
158 {
159 $form = $this->getForm();
160
161 $this->pons->in()->keep(
162 $this->token
163 );
164
165 $this->pons->out()->outAsyncAsModal(
166 $this->pons->i18n()->t('shortlink'),
167 $this->pons->flow()->getHereAsURI(self::CMD_SAVE),
168 ...iterator_to_array($form->get())
169 );
170 }

References getForm().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllIds()

ShortlinkAdministrationGUI::getAllIds ( )
private

Definition at line 315 of file ShortlinkAdministrationGUI.php.

315 : array
316 {
317 $from_request = $this->pons->in()->getAllFromRequest($this->token);
318 if (($from_request[0] ?? null) === Input::ALL_OBJECTS) {
319 return array_map(
320 static fn(Shortlink $s): string => $s->getId(),
321 iterator_to_array($this->repository->getAll())
322 );
323 }
324 return array_unique($from_request);
325 }

References ILIAS\StaticURL\Shortlinks\Shortlink\Shortlink\getId(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ getForm()

ShortlinkAdministrationGUI::getForm ( )
private

Definition at line 82 of file ShortlinkAdministrationGUI.php.

82 : Form
83 {
84 $id_from_request = $this->pons->in()->getFirstFromRequest($this->token);
85
86 if ($this->repository->hasId($id_from_request)) {
87 $shortlink = $this->repository->getById(
88 $id_from_request
89 );
90 } else {
91 $shortlink = $this->repository->blank();
92 }
93
94 return new Form(
95 $this->pons,
96 $this->repository,
97 $this->pons->flow()->getHereAsURI(self::CMD_SAVE),
98 $shortlink
99 );
100 }

References ILIAS\UI\examples\Deck\repository().

Referenced by form(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTokensToKeep()

ShortlinkAdministrationGUI::getTokensToKeep ( )

Implements ILIAS\GlobalScreen\GUI\PonsGUI.

Definition at line 124 of file ShortlinkAdministrationGUI.php.

124 : array
125 {
126 return [];
127 }

◆ index()

ShortlinkAdministrationGUI::index ( )
private

Definition at line 173 of file ShortlinkAdministrationGUI.php.

173 : void
174 {
175 if ($this->pons->access()->hasUserPermissionTo('write')) {
176 $this->toolbar->addComponent(
177 $modal = $this->ui_factory->modal()->roundtrip(
178 $this->pons->i18n()->t('create_shortlink'),
179 null,
180 [],
181 null
182 )->withAsyncRenderUrl(
183 (string) $this->pons->flow()->getHereAsURI(self::CMD_FORM),
184 )
185 );
186
187 $this->toolbar->addComponent(
188 $button = $this->ui_factory->button()->primary(
189 $this->pons->i18n()->t('create_shortlink'),
190 (string) $this->pons->flow()->getHereAsURI(self::CMD_FORM), // TODO make async again
191 )->withOnClick(
192 $modal->getShowSignal()
193 )
194 );
195 }
196
197 $table = new Table(
198 $this->pons,
199 $this->repository,
200 $this->link_resolver,
201 $this->pons->flow()->getHereAsURI(self::CMD_SAVE_ORDERING),
202 $this->token,
203 $this->configuration,
204 $this->pons->access()->hasUserPermissionTo('write'),
205 );
206
207 $this->pons->out()->out(...iterator_to_array($table->get()));
208 }

References ILIAS\UI\examples\Deck\repository(), and ILIAS\Repository\toolbar().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ShortlinkAdministrationGUI::save ( )
private

Definition at line 130 of file ShortlinkAdministrationGUI.php.

130 : void
131 {
132 $form = $this->getForm();
133 if (($out_form = $form->save()) instanceof Standard) {
134 $this->pons->out()->out(
135 $out_form
136 );
137 return;
138 }
139 $this
140 ->pons
141 ->out()
142 ->success(
143 $this->pons->i18n()->t(
144 'stus_stored_sucessfully'
145 )
146 );
147
148 $this
149 ->pons
150 ->flow()
151 ->redirect(
152 self::CMD_DEFAULT
153 );
154 }
This describes a standard form.
Definition: Standard.php:30

References getForm().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveOrdering()

ShortlinkAdministrationGUI::saveOrdering ( )
private

Definition at line 304 of file ShortlinkAdministrationGUI.php.

304 : void
305 {
306 foreach ($this->pons->in()->request()->getParsedBody() as $hashed_id => $position) {
307 $item = $this->repository->getById($this->unhash($hashed_id));
308 $item = $item->withPosition((int) $position);
309 $this->repository->store($item);
310 }
311 $this->pons->out()->success($this->pons->i18n()->translate('order_saved'));
312 $this->pons->flow()->redirect(self::CMD_DEFAULT);
313 }

References ILIAS\UI\examples\Deck\repository().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggle()

ShortlinkAdministrationGUI::toggle ( )
private

Definition at line 284 of file ShortlinkAdministrationGUI.php.

284 : void
285 {
286 $from_request = $this->getAllIds();
287 foreach ($from_request as $id) {
288 $shortlink = $this->repository->getById($id);
289 if ($shortlink === null) {
290 continue;
291 }
292 $shortlink = $shortlink->withActive(
293 !$shortlink->isActive()
294 );
295
296 $this->repository->store($shortlink);
297 }
298
299 $this->pons->out()->success($this->pons->i18n()->t('shortlinks_toggled'));
300 $this->pons->flow()->redirect(self::CMD_DEFAULT);
301 }

References $id, and ILIAS\UI\examples\Deck\repository().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $configuration

Configuration ShortlinkAdministrationGUI::$configuration
private

Definition at line 59 of file ShortlinkAdministrationGUI.php.

◆ $link_resolver

TargetLinkResolver ShortlinkAdministrationGUI::$link_resolver
private

Definition at line 58 of file ShortlinkAdministrationGUI.php.

◆ $repository

Repository ShortlinkAdministrationGUI::$repository
private

Definition at line 56 of file ShortlinkAdministrationGUI.php.

◆ $token

TokenContainer ShortlinkAdministrationGUI::$token
private

Definition at line 57 of file ShortlinkAdministrationGUI.php.

◆ $toolbar

ilToolbarGUI ShortlinkAdministrationGUI::$toolbar
private

Definition at line 54 of file ShortlinkAdministrationGUI.php.

◆ $ui_factory

Factory ShortlinkAdministrationGUI::$ui_factory
private

Definition at line 55 of file ShortlinkAdministrationGUI.php.

◆ CMD_CONFIRM_DELETE

const string ShortlinkAdministrationGUI::CMD_CONFIRM_DELETE = 'confirmDelete'

◆ CMD_CONFIRM_TOGGLE

const string ShortlinkAdministrationGUI::CMD_CONFIRM_TOGGLE = 'confirmToggle'

◆ CMD_DELETE

const string ShortlinkAdministrationGUI::CMD_DELETE = 'delete'

Definition at line 50 of file ShortlinkAdministrationGUI.php.

◆ CMD_FORM

const string ShortlinkAdministrationGUI::CMD_FORM = 'form'

◆ CMD_SAVE

const string ShortlinkAdministrationGUI::CMD_SAVE = 'save'

Definition at line 48 of file ShortlinkAdministrationGUI.php.

◆ CMD_SAVE_ORDERING

const string ShortlinkAdministrationGUI::CMD_SAVE_ORDERING = 'saveOrdering'

Definition at line 53 of file ShortlinkAdministrationGUI.php.

◆ CMD_TOGGLE

const string ShortlinkAdministrationGUI::CMD_TOGGLE = 'toggle'

Definition at line 52 of file ShortlinkAdministrationGUI.php.


The documentation for this class was generated from the following file: