ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
BaseTypeRenderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data\URI;
34 use Throwable;
36 
42 {
44  MakeSlateAsync::hash insteadof SlateSessionStateCode;
45  MakeSlateAsync::unhash insteadof SlateSessionStateCode;
46  }
47  use isSupportedTrait;
48 
50 
51  protected \ilLanguage $lng;
52  protected Factory $ui_factory;
53 
55 
59  public function __construct()
60  {
61  global $DIC;
62  $this->ui_factory = $DIC->ui()->factory();
63  $this->ui_renderer = $DIC->ui()->renderer();
64  $this->lng = $DIC->language();
65  }
66 
67  public function getComponentForItem(isItem $item, bool $with_content = true): Component
68  {
69  $component = $this->applyComponentDecorator(
70  $with_content
71  ? $this->getComponentWithContent($item)
72  : $this->getComponentWithoutContent($item),
73  $item
74  );
75  if ($component instanceof HasHelpTopics) {
76  return $this->applyTopics($component, $item);
77  }
78 
79  return $component;
80  }
81 
82  public function getComponentWithContent(isItem $item): Component
83  {
84  return $this->ui_factory->legacy()->content($item->getProviderIdentification()->serialize());
85  }
86 
87  public function getComponentWithoutContent(isItem $item): Component
88  {
89  if (!$this->supportsAsyncContent($item)) {
90  return $this->getComponentWithContent($item);
91  }
93  $content = $this->ui_factory->legacy()->content('...');
94  $name = $item instanceof hasTitle ? $item->getTitle() : "-";
95  $slate = $this->ui_factory->mainControls()->slate()->legacy(
96  $name,
97  $this->getStandardSymbol($item),
98  $content
99  );
100  $slate = $this->addAsyncLoadingCode($slate, $item);
101 
102  return $this->addOnloadCode($slate, $item);
103  }
104 
105  private function supportsAsyncContent(isItem $item): bool
106  {
107  return $item instanceof supportsAsynchronousLoading && $item->supportsAsynchronousLoading();
108  }
109 
114  protected function getStandardSymbol(isItem $item): Symbol
115  {
116  if ($item instanceof hasSymbol && $item->hasSymbol()) {
117  $c = $item->getSymbolDecorator();
118  if ($c !== null) {
119  return $this->applySymbolDecorator($item->getSymbol(), $item);
120  }
121 
122  return $item->getSymbol();
123  }
124  if ($item instanceof hasTitle) {
125  if (function_exists('mb_substr')) {
126  $abbr = strtoupper(mb_substr($item->getTitle(), 0, 1));
127  } else {
128  $abbr = strtoupper(substr($item->getTitle(), 0, 1));
129  }
130  } else {
131  $abbr = strtoupper(substr(uniqid('', true), -1));
132  }
133 
134  return $this->ui_factory->symbol()
135  ->icon()
136  ->standard(
137  $abbr,
138  $abbr,
139  'small',
140  true
141  )
142  ->withAbbreviation($abbr);
143  }
144 
149  protected function getURI(string $uri_string): URI
150  {
151  $uri_string = trim($uri_string, " ");
152 
153  if (str_starts_with($uri_string, 'http')) {
154  $checker = self::getURIChecker();
155  if ($checker($uri_string)) {
156  return new URI($uri_string);
157  }
158  return new URI(rtrim(ILIAS_HTTP_PATH, "/") . "/" . ltrim($_SERVER['REQUEST_URI'] ?? '', "./"));
159  }
160 
161  return new URI(rtrim(ILIAS_HTTP_PATH, "/") . "/" . ltrim($uri_string, "./"));
162  }
163 
164  public static function getURIChecker(): callable
165  {
166  return static function (string $v): bool {
167  $v = self::getURIConverter()($v);
168  try {
169  new URI($v);
170  } catch (Throwable) {
171  return false;
172  }
173  return true;
174  };
175  }
176 
177  public static function getURIConverter(): callable
178  {
179  return static function (string $v): string {
180  if (str_starts_with($v, './')) {
181  $v = ltrim($v, './');
182  return ILIAS_HTTP_PATH . '/' . $v;
183  }
184 
185  return $v;
186  };
187  }
188 }
This describes a symbol.
Definition: Symbol.php:29
getComponentWithoutContent(isItem $item)
This is called when only the relevant part of the item is needed during the synchronous rendering of ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: deliver.php:25
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
addAsyncLoadingCode(Slate $slate, supportsAsynchronousLoading $item)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
getComponentWithContent(isItem $item)
This is called in cases when the Full Item with it&#39;s content is needed, e.g.
global $DIC
Definition: shib_login.php:22
Interface supportsAsynchronousLoading Types, which implement this interface, can load their content a...
Builds data types.
Definition: Factory.php:35
Class TypeRenderer Every Type should have a renderer, if you won&#39;t provide on in your TypeInformation...