ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FileObjectPropertyProviders.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\UI\Component\Image\Factory as ImageFactory;
27use ILIAS\ResourceStorage\Services as StorageService;
33
35{
41
42 public function __construct()
43 {
44 $this->crop_definition = new TileImageFlavourDefinition();
45 $this->extract_definition = new FirstPageToTileImageFlavourDefinition();
46 $this->settings = (new SettingsFactory())->getSettings();
47 $this->info = new ilObjFileInfoRepository();
48 $this->icons = new IconDatabaseRepository();
49 }
50
52 int $obj_id,
53 ImageFactory $factory,
54 StorageService $irss
55 ): ?Image {
56 if (!$this->settings->hasTilePreviews()) {
57 return null;
58 }
59
60 $rid = (new ilObjFileInfoRepository())->getByObjectId($obj_id)->getRID();
61
62 if ($rid === null) {
63 return null;
64 }
65 if ($irss->flavours()->possible($rid, $this->crop_definition)) {
66 $flavour = $irss->flavours()->get($rid, $this->crop_definition);
67 return $this->getImageFromIRSS($irss, $factory, $flavour);
68 }
69 if ($irss->flavours()->possible($rid, $this->extract_definition)) {
70 $flavour = $irss->flavours()->get($rid, $this->extract_definition);
71 return $this->getImageFromIRSS($irss, $factory, $flavour);
72 }
73
74 return null;
75 }
76
77 private function getImageFromIRSS(
78 StorageService $irss,
79 ImageFactory $factory,
80 Flavour $flavour
81 ): ?Image {
82 $urls = $irss->consume()->flavourUrls($flavour)->getURLsAsArray();
83
84 if ($urls === []) {
85 return null;
86 }
87
88 $available_widths = $this->crop_definition->getWidths();
89 array_pop($available_widths);
90
91 if (!isset($urls[count($available_widths)])) {
92 return null;
93 }
94
95 $image = $factory->responsive($urls[count($available_widths)], '');
96 return array_reduce(
97 $available_widths,
98 function (array $carry, $size) use ($urls): array {
99 $image = $carry['image']->withAdditionalHighResSource($urls[$carry['counter']], $size / 2);
100 $counter = ++$carry['counter'];
101 return [
102 'image' => $image,
103 'counter' => $counter
104 ];
105 },
106 ['image' => $image, 'counter' => 0]
107 )['image'];
108 }
109
111 int $obj_id,
112 IconFactory $icon_factory,
113 StorageService $irss
114 ): ?CustomIcon {
115 $info = $this->info->getByObjectId($obj_id);
116 $path = $this->icons->getIconFilePathBySuffix($info->getSuffix());
117 if (($path !== '' && $path !== '0')) {
118 return $icon_factory->custom($path, $info->getSuffix());
119 }
120
121 return null;
122 }
123}
getObjectTypeSpecificTileImage(int $obj_id, ImageFactory $factory, StorageService $irss)
getObjectTypeSpecificIcon(int $obj_id, IconFactory $icon_factory, StorageService $irss)
getImageFromIRSS(StorageService $irss, ImageFactory $factory, Flavour $flavour)
$info
Definition: entry_point.php:21
This is how the factory for UI elements looks.
Definition: Factory.php:28
This describes the behavior of an custom icon.
Definition: Custom.php:27
This is how a factory for icons looks like.
Definition: Factory.php:27
$path
Definition: ltiservices.php:30
if(!file_exists('../ilias.ini.php'))
$counter