ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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;
33 
35 {
41 
42  public function __construct()
43  {
44  $this->crop_definition = new ilObjectTileImageFlavourDefinition();
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 
110  public function getObjectTypeSpecificIcon(
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 }
getObjectTypeSpecificIcon(int $obj_id, IconFactory $icon_factory, StorageService $irss)
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
info()
description: > Example for rendering a info message box.
Definition: info.php:34
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)