ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
TargetLinkResolver.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Data\Factory as DataFactory;
27use ILIAS\UI\Factory as UIFactory;
32
37{
38 public function __construct(
39 private URIBuilder $uri_builder,
40 private DataFactory $data_factory,
41 private ?UIFactory $ui_factory = null,
42 ) {
43 }
44
45 public function resolve(Shortlink $shortlink): URI|Signal|string|null
46 {
47 $data = $shortlink->getTargetData();
48
49 return match ($shortlink->getTargetType()) {
50 Type::REPO => $this->uri_builder->build(
51 $data['type'],
52 $this->data_factory->refId($data['ref_id'])
53 ),
54 Type::CUSTOM => '#',
55 default => null
56 };
57 }
58
59 protected function buildName(Shortlink $shortlink): string
60 {
61 $type_data = $shortlink->getTargetData();
62 return match ($shortlink->getTargetType()) {
63 Type::REPO => \ilObject2::_lookupTitle(\ilObject2::_lookupObjId($type_data['ref_id'])),
64 Type::CUSTOM => $shortlink->getAlias(),
65 default => '-'
66 };
67 }
68
69 public function resolveLink(Shortlink $shortlink): ?Link
70 {
71 if ($this->ui_factory === null) {
72 return null;
73 }
74
75 return $this->ui_factory->link()->standard(
76 $this->buildName($shortlink),
77 (string) $this->resolve($shortlink),
78 );
79 }
80
81 public function resolveStandardButton(Shortlink $shortlink): ?Button
82 {
83 return $this->ui_factory->button()->standard(
84 $this->buildName($shortlink),
85 $this->resolve($shortlink),
86 );
87 }
88
89}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This describes commonalities between standard and primary buttons.
Definition: Button.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21