Skip to content

Commit

Permalink
[FIX] 0042303: Automatically generated preview image for tile view ca…
Browse files Browse the repository at this point in the history
…n't be deactivated
  • Loading branch information
chfsx committed Jan 17, 2025
1 parent dc96e82 commit 7963219
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,30 @@
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(
int $obj_id,
ImageFactory $factory,
StorageService $irss
): ?Image {
if (!$this->settings->hasTilePreviews()) {
return null;
}

$rid = (new ilObjFileInfoRepository())->getByObjectId($obj_id)->getRID();

if ($rid === null) {
Expand Down
16 changes: 15 additions & 1 deletion Modules/File/classes/Preview/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
);
}
Expand Down
11 changes: 11 additions & 0 deletions Modules/File/classes/Preview/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7963219

Please sign in to comment.