ILIAS  release_8 Revision v8.24
class.ilPreviewSettings.php
Go to the documentation of this file.
1<?php
28{
29 public const MAX_PREVIEWS_DEFAULT = 5;
30 public const MAX_PREVIEWS_MIN = 1;
31 public const MAX_PREVIEWS_MAX = 20;
32
33 private const IMAGE_SIZE_DEFAULT = 280;
34 private const IMAGE_SIZE_MIN = 50;
35 private const IMAGE_SIZE_MAX = 600;
36
37 private const IMAGE_QUALITY_DEFAULT = 85;
38 private const IMAGE_QUALITY_MIN = 20;
39 private const IMAGE_QUALITY_MAX = 100;
40
44 private static ?\ilPreviewSettings $instance = null;
45
49 private ?\ilSetting $settings = null;
50
54 private bool $preview_enabled = true;
55
60
65
70
74 private function __construct()
75 {
76 $this->settings = new ilSetting("preview");
77 $this->preview_enabled = (bool) $this->settings->get('preview_enabled', '0') === true;
78 $this->max_previews = $this->settings->get('max_previews_per_object', self::MAX_PREVIEWS_DEFAULT);
79 }
80
86 public static function setPreviewEnabled(bool $a_value): void
87 {
89 $instance->preview_enabled = $a_value === true;
90 $instance->settings->set('preview_enabled', $instance->preview_enabled);
91 }
92
98 public static function isPreviewEnabled(): bool
99 {
100 return self::getInstance()->preview_enabled;
101 }
102
108 public static function setMaximumPreviews(int $a_value): void
109 {
111 $instance->max_previews = self::adjustNumeric($a_value, self::MAX_PREVIEWS_MIN, self::MAX_PREVIEWS_MAX, self::MAX_PREVIEWS_DEFAULT);
112 $instance->settings->set('max_previews_per_object', $instance->max_previews);
113 }
114
120 public static function getMaximumPreviews(): int
121 {
122 return self::getInstance()->max_previews;
123 }
124
130 public static function setImageSize(int $a_value): void
131 {
133 $instance->image_size = self::adjustNumeric($a_value, self::IMAGE_SIZE_MIN, self::IMAGE_SIZE_MAX, self::IMAGE_SIZE_DEFAULT);
134 $instance->settings->set('preview_image_size', $instance->image_size);
135 }
136
142 public static function getImageSize(): int
143 {
144 return self::getInstance()->image_size;
145 }
146
152 public static function setImageQuality(int $a_value): void
153 {
155 $instance->image_quality = self::adjustNumeric($a_value, self::IMAGE_QUALITY_MIN, self::IMAGE_QUALITY_MAX, self::IMAGE_QUALITY_DEFAULT);
156 $instance->settings->set('preview_image_quality', $instance->image_quality);
157 }
158
164 public static function getImageQuality(): int
165 {
166 return self::getInstance()->image_quality;
167 }
168
172 private static function getInstance(): \ilPreviewSettings
173 {
174 if (self::$instance === null) {
175 self::$instance = new ilPreviewSettings();
176 }
177
178 return self::$instance;
179 }
180
181 private static function adjustNumeric($value, int $min, int $max, int $default): int
182 {
183 // is number?
184 if (is_numeric($value)) {
185 // don't allow to large numbers
186 $value = (int) $value;
187 if ($value < $min) {
188 $value = $min;
189 } elseif ($value > $max) {
190 $value = $max;
191 }
192 } else {
193 $value = $default;
194 }
195
196 return $value;
197 }
198}
int $image_quality
Defines the quality (compression) of the preview images (1-100).
static setMaximumPreviews(int $a_value)
Sets the maximum number of preview pictures per object.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
static ilPreviewSettings $instance
The instance of the ilPreviewSettings.
static setImageQuality(int $a_value)
Sets the quality (compression) of the preview images (1-100).
ilSetting $settings
Settings object.
static getInstance()
Gets the instance of the ilPreviewSettings.
static getImageSize()
Gets the size of the preview images in pixels.
static setImageSize(int $a_value)
Sets the size of the preview images in pixels.
bool $preview_enabled
Indicates whether the preview functionality is enabled.
__construct()
Private constructor.
int $image_size
Defines the maximum width and height of the preview images.
int $max_previews
Defines the maximum number of previews pictures per object.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).
static adjustNumeric($value, int $min, int $max, int $default)
static setPreviewEnabled(bool $a_value)
Sets whether the preview functionality is enabled.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...