ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
FileObjectPropertyProviders.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 use ILIAS\UI\Component\Image\Factory as ImageFactory;
32 
34 {
40 
41  public function __construct()
42  {
43  $this->crop_definition = new ilObjectTileImageFlavourDefinition();
44  $this->extract_definition = new FirstPageToTileImageFlavourDefinition();
45  $this->settings = new Settings();
46  $this->info = new ilObjFileInfoRepository();
47  $this->icons = new IconDatabaseRepository();
48  }
49 
51  int $obj_id,
52  ImageFactory $factory,
53  StorageService $irss
54  ): ?Image {
55  if (!$this->settings->hasTilePreviews()) {
56  return null;
57  }
58 
59  $rid = (new ilObjFileInfoRepository())->getByObjectId($obj_id)->getRID();
60 
61  if ($rid === null) {
62  return null;
63  }
64  if ($irss->flavours()->possible($rid, $this->crop_definition)) {
65  $flavour = $irss->flavours()->get($rid, $this->crop_definition);
66  return $this->getImageFromIRSS($irss, $factory, $flavour);
67  }
68  if ($irss->flavours()->possible($rid, $this->extract_definition)) {
69  $flavour = $irss->flavours()->get($rid, $this->extract_definition);
70  return $this->getImageFromIRSS($irss, $factory, $flavour);
71  }
72 
73  return null;
74  }
75 
76  private function getImageFromIRSS(
77  StorageService $irss,
78  ImageFactory $factory,
79  Flavour $flavour
80  ): ?Image {
81  $urls = $irss->consume()->flavourUrls($flavour)->getURLsAsArray();
82 
83  if ($urls === []) {
84  return null;
85  }
86 
87  $available_widths = $this->crop_definition->getWidths();
88  array_pop($available_widths);
89 
90  if (!isset($urls[count($available_widths)])) {
91  return null;
92  }
93 
94  $image = $factory->responsive($urls[count($available_widths)], '');
95  return array_reduce(
96  $available_widths,
97  function ($carry, $size) use ($urls) {
98  $image = $carry['image']->withAdditionalHighResSource($urls[$carry['counter']], $size / 2);
99  $counter = ++$carry['counter'];
100  return [
101  'image' => $image,
102  'counter' => $counter
103  ];
104  },
105  ['image' => $image, 'counter' => 0]
106  )['image'];
107  }
108 
109  public function getObjectTypeSpecificIcon(
110  int $obj_id,
111  IconFactory $icon_factory,
112  StorageService $irss
113  ): ?CustomIcon {
114  $info = $this->info->getByObjectId($obj_id);
115  $path = $this->icons->getIconFilePathBySuffix($info->getSuffix());
116  if (($path !== '' && $path !== '0')) {
117  return $icon_factory->custom($path, $info->getSuffix());
118  }
119 
120  return null;
121  }
122 }
getObjectTypeSpecificIcon(int $obj_id, IconFactory $icon_factory, StorageService $irss)
$path
Definition: ltiservices.php:32
This is how a factory for icons looks like.
Definition: Factory.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getObjectTypeSpecificTileImage(int $obj_id, ImageFactory $factory, StorageService $irss)
This is how the factory for UI elements looks.
Definition: Factory.php:27
getImageFromIRSS(StorageService $irss, ImageFactory $factory, Flavour $flavour)