From 7963219b0c7f7b92706f72915a87d4367bef8007 Mon Sep 17 00:00:00 2001 From: Fabian Schmid Date: Fri, 17 Jan 2025 14:39:08 +0100 Subject: [PATCH] [FIX] 0042303: Automatically generated preview image for tile view can't be deactivated --- .../FileObjectPropertyProviders.php | 7 +++++++ Modules/File/classes/Preview/Form.php | 16 +++++++++++++++- Modules/File/classes/Preview/Settings.php | 11 +++++++++++ lang/ilias_de.lang | 2 ++ lang/ilias_en.lang | 2 ++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Modules/File/classes/ObjectProperties/FileObjectPropertyProviders.php b/Modules/File/classes/ObjectProperties/FileObjectPropertyProviders.php index a963c21ca1d3..76184223c326 100644 --- a/Modules/File/classes/ObjectProperties/FileObjectPropertyProviders.php +++ b/Modules/File/classes/ObjectProperties/FileObjectPropertyProviders.php @@ -27,16 +27,19 @@ use ILIAS\ResourceStorage\Services as StorageService; use ILIAS\ResourceStorage\Flavour\Flavour; use ILIAS\ResourceStorage\Flavour\Definition\FlavourDefinition; +use ILIAS\Modules\File\Preview\Settings; class FileObjectPropertyProviders implements ilObjectTypeSpecificPropertyProviders { private FlavourDefinition $crop_definition; private FlavourDefinition $extract_definition; + private Settings $settings; public function __construct() { $this->crop_definition = new ilObjectTileImageFlavourDefinition(); $this->extract_definition = new FirstPageToTileImageFlavourDefinition(); + $this->settings = new Settings(); } public function getObjectTypeSpecificTileImage( @@ -44,6 +47,10 @@ public function getObjectTypeSpecificTileImage( ImageFactory $factory, StorageService $irss ): ?Image { + if (!$this->settings->hasTilePreviews()) { + return null; + } + $rid = (new ilObjFileInfoRepository())->getByObjectId($obj_id)->getRID(); if ($rid === null) { diff --git a/Modules/File/classes/Preview/Form.php b/Modules/File/classes/Preview/Form.php index 333a8a2ad4bb..e5fadbcc4d43 100644 --- a/Modules/File/classes/Preview/Form.php +++ b/Modules/File/classes/Preview/Form.php @@ -103,12 +103,26 @@ public function asFormGroup(): Group }) ); + $tile_previews = $this->field_factory + ->checkbox( + $this->language->txt('previews_for_tiles'), + $this->language->txt('previews_for_tiles_info') + ) + ->withDisabled(!$possible) + ->withValue($this->settings->hasTilePreviews()) + ->withAdditionalTransformation( + $this->refinery->custom()->transformation(function ($v): void { + $this->settings->setTilePreviews($v); + }) + ); + return $this->field_factory->group( [ $activated, $image_size, $max_previews, - $persisting + $persisting, + $tile_previews ] ); } diff --git a/Modules/File/classes/Preview/Settings.php b/Modules/File/classes/Preview/Settings.php index 540fbdca4426..501601b808e9 100644 --- a/Modules/File/classes/Preview/Settings.php +++ b/Modules/File/classes/Preview/Settings.php @@ -46,6 +46,7 @@ class Settings extends ilSetting implements Setting private const F_PREVIEW_IMAGE_SIZE = 'preview_image_size'; private const F_PREVIEW_PERSISTING = 'preview_persisting'; private const F_PREVIEW_IMAGE_QUALITY = 'preview_image_quality'; + private const F_TILE_PREVIEWS = 'tile_previews'; /** * @readonly */ @@ -67,6 +68,16 @@ public function isPersisting(): bool return $this->strToBool($this->get(self::F_PREVIEW_PERSISTING, '1')); } + public function setTilePreviews(bool $a_value): void + { + $this->set(self::F_TILE_PREVIEWS, $this->boolToStr($a_value)); + } + + public function hasTilePreviews(): bool + { + return $this->strToBool($this->get(self::F_TILE_PREVIEWS, '1')); + } + public function isPreviewPossible(): bool { return $this->imagick->isRunning(); // &&(new GDEngine())->isRunning(); diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 0cc3733c1adf..8224a3cb7d90 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -9783,6 +9783,8 @@ file#:#preview_caption#:#Vorschau %svon %s file#:#preview_image_size_info#:#Die Vorschauversionen der Bilder werden je nach Bedarf verkleinert oder vergrößert, so dass ihre längste Seite der hier eingegebenen Länge (in px) entspricht. file#:#preview_persisting#:#Vorschaubilder speichern file#:#preview_persisting_info#:#Vorschaubilder werden generiert und gespeichert. Sie müssen nicht mehr bei jedem Aufruf neu erzeugt werden. Das verbessert die Performanz. +file#:#previews_for_tiles#:#Kachelbilder +file#:#previews_for_tiles_info#:#Verwende Vorschaubilder für Kacheln. file#:#publish_before_delete#:#Version(en) konnte(n) nicht gelöscht werden, da ein noch unveröffentlichter Entwurf existiert. file#:#replace_file_info#:#Alle früheren Dateiversionen werden gelöscht. file#:#resource_id#:#Ressourcen ID diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 887f26daf2e3..41fde2df87e0 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -9783,6 +9783,8 @@ file#:#preview_caption#:#Preview %sof %s file#:#preview_image_size_info#:#The preview versions of images will be downscaled or upscaled as appropriate, so that their longest side is the length (in px) entered here. file#:#preview_persisting#:#Persistent Preview Images file#:#preview_persisting_info#:#Generated preview images will be stored by ILIAS and used from then on each time the preview icon for that file is clicked on. If deactivated, previews will be generated anew each time. +file#:#previews_for_tiles#:#Tiles +file#:#previews_for_tiles_info#:#Use Preview for Tiles where possible. file#:#publish_before_delete#:#It was not possible to delete any of the existing versions because an unpublished draft exists. file#:#replace_file_info#:#All previous file versions will be deleted. file#:#resource_id#:#Resource ID