ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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;
34 
36 {
42 
43  public function __construct()
44  {
45  $this->crop_definition = new ilObjectTileImageFlavourDefinition();
46  $this->extract_definition = new FirstPageToTileImageFlavourDefinition();
47  $this->settings = (new SettingsFactory())->getSettings();
48  $this->info = new ilObjFileInfoRepository();
49  $this->icons = new IconDatabaseRepository();
50  }
51 
53  int $obj_id,
54  ImageFactory $factory,
55  StorageService $irss
56  ): ?Image {
57  if (!$this->settings->hasTilePreviews()) {
58  return null;
59  }
60 
61  $rid = (new ilObjFileInfoRepository())->getByObjectId($obj_id)->getRID();
62 
63  if ($rid === null) {
64  return null;
65  }
66  if ($irss->flavours()->possible($rid, $this->crop_definition)) {
67  $flavour = $irss->flavours()->get($rid, $this->crop_definition);
68  return $this->getImageFromIRSS($irss, $factory, $flavour);
69  }
70  if ($irss->flavours()->possible($rid, $this->extract_definition)) {
71  $flavour = $irss->flavours()->get($rid, $this->extract_definition);
72  return $this->getImageFromIRSS($irss, $factory, $flavour);
73  }
74 
75  return null;
76  }
77 
78  private function getImageFromIRSS(
79  StorageService $irss,
80  ImageFactory $factory,
81  Flavour $flavour
82  ): ?Image {
83  $urls = $irss->consume()->flavourUrls($flavour)->getURLsAsArray();
84 
85  if ($urls === []) {
86  return null;
87  }
88 
89  $available_widths = $this->crop_definition->getWidths();
90  array_pop($available_widths);
91 
92  if (!isset($urls[count($available_widths)])) {
93  return null;
94  }
95 
96  $image = $factory->responsive($urls[count($available_widths)], '');
97  return array_reduce(
98  $available_widths,
99  function ($carry, $size) use ($urls) {
100  $image = $carry['image']->withAdditionalHighResSource($urls[$carry['counter']], $size / 2);
101  $counter = ++$carry['counter'];
102  return [
103  'image' => $image,
104  'counter' => $counter
105  ];
106  },
107  ['image' => $image, 'counter' => 0]
108  )['image'];
109  }
110 
111  public function getObjectTypeSpecificIcon(
112  int $obj_id,
113  IconFactory $icon_factory,
114  StorageService $irss
115  ): ?CustomIcon {
116  $info = $this->info->getByObjectId($obj_id);
117  if (($path = $this->icons->getIconFilePathBySuffix($info->getSuffix()))) {
118  return $icon_factory->custom($path, $info->getSuffix());
119  }
120 
121  return null;
122  }
123 }
getObjectTypeSpecificIcon(int $obj_id, IconFactory $icon_factory, StorageService $irss)
$path
Definition: ltiservices.php:30
info()
description: > Example for rendering a info message box.
Definition: info.php:18
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)