ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Settings.php
Go to the documentation of this file.
1 <?php
2 
20 
23 use ilSetting;
24 
28 class Settings extends ilSetting implements Setting
29 {
30  public const V_MAX_PREVIEWS_DEFAULT = 5;
31  public const V_MAX_PREVIEWS_MIN = 1;
32  public const V_MAX_PREVIEWS_MAX = 100;
33 
34  public const V_IMAGE_SIZE_DEFAULT = 868;
35  public const V_IMAGE_SIZE_MIN = 50;
36  public const V_IMAGE_SIZE_MAX = 1000;
37 
41  private const V_IMAGE_QUALITY_DEFAULT = 85;
45  private const V_IMAGE_QUALITY_MIN = 1;
49  private const V_IMAGE_QUALITY_MAX = 100;
50 
51  public const MODULE_NAME = 'preview';
52 
56  private const F_PREVIEW_ENABLED = 'preview_enabled';
60  private const F_MAX_PREVIEWS_PER_OBJECT = 'max_previews_per_object';
64  private const F_PREVIEW_IMAGE_SIZE = 'preview_image_size';
68  private const F_PREVIEW_PERSISTING = 'preview_persisting';
72  private const F_PREVIEW_IMAGE_QUALITY = 'preview_image_quality';
76  private const F_TILE_PREVIEWS = 'tile_previews';
81 
82  public function __construct()
83  {
84  parent::__construct(self::MODULE_NAME, false);
85  $this->imagick = new ImagickEngine();
86  }
87 
88  public function setPersisting(bool $a_value): void
89  {
90  $this->set(self::F_PREVIEW_PERSISTING, $this->boolToStr($a_value));
91  }
92 
93  public function isPersisting(): bool
94  {
95  return $this->strToBool($this->get(self::F_PREVIEW_PERSISTING, '1'));
96  }
97 
98  public function setTilePreviews(bool $a_value): void
99  {
100  $this->set(self::F_TILE_PREVIEWS, $this->boolToStr($a_value));
101  }
102 
103  public function hasTilePreviews(): bool
104  {
105  return $this->strToBool($this->get(self::F_TILE_PREVIEWS, '1'));
106  }
107 
108  public function isPreviewPossible(): bool
109  {
110  return $this->imagick->isRunning(); // &&(new GDEngine())->isRunning();
111  }
112 
113  public function setPreviewEnabled(bool $a_value): void
114  {
115  $this->set(self::F_PREVIEW_ENABLED, $this->boolToStr($a_value));
116  }
117 
118  public function isPreviewEnabled(): bool
119  {
120  if (!$this->isPreviewPossible()) {
121  return false;
122  }
123  return $this->strToBool($this->get(self::F_PREVIEW_ENABLED, '1'));
124  }
125 
126  public function setMaximumPreviews(int $max_previews): void
127  {
128  $max_previews = $this->adjustNumeric(
129  $max_previews,
130  self::V_MAX_PREVIEWS_MIN,
131  self::V_MAX_PREVIEWS_MAX,
132  self::V_MAX_PREVIEWS_DEFAULT
133  );
134  $this->set(self::F_MAX_PREVIEWS_PER_OBJECT, $this->intToStr($max_previews));
135  }
136 
137  public function getMaximumPreviews(): int
138  {
139  return $this->strToInt($this->get(self::F_MAX_PREVIEWS_PER_OBJECT, (string) self::V_MAX_PREVIEWS_DEFAULT));
140  }
141 
142  public function setImageSize(int $image_size): void
143  {
144  $image_size = $this->adjustNumeric(
145  $image_size,
146  self::V_IMAGE_SIZE_MIN,
147  self::V_IMAGE_SIZE_MAX,
148  self::V_IMAGE_SIZE_DEFAULT
149  );
150  $this->set(self::F_PREVIEW_IMAGE_SIZE, $this->intToStr($image_size));
151  }
152 
153  public function getImageSize(): int
154  {
155  return $this->strToInt($this->get(self::F_PREVIEW_IMAGE_SIZE, (string) self::V_IMAGE_SIZE_DEFAULT));
156  }
157 
158  public function setImageQuality(int $quality): void
159  {
160  $quality = $this->adjustNumeric(
161  $quality,
162  self::V_IMAGE_QUALITY_MIN,
163  self::V_IMAGE_QUALITY_MAX,
164  self::V_IMAGE_QUALITY_DEFAULT
165  );
166  $this->set(self::F_PREVIEW_IMAGE_QUALITY, $this->intToStr($quality));
167  }
168 
169  public function getImageQuality(): int
170  {
171  return $this->strToInt($this->get(self::F_PREVIEW_IMAGE_QUALITY, (string) self::V_IMAGE_QUALITY_DEFAULT));
172  }
173 
174  private function adjustNumeric(int $value, int $min, int $max, int $default): int
175  {
176  // is number?
177  if (is_numeric($value)) {
178  // don't allow to large numbers
179  $value = (int) $value;
180  if ($value < $min) {
181  $value = $min;
182  } elseif ($value > $max) {
183  $value = $max;
184  }
185  } else {
186  $value = $default;
187  }
188 
189  return $value;
190  }
191 
192  // HELPERS
193 
194  private function strToBool(string $value): bool
195  {
196  return $value === '1';
197  }
198 
199  private function boolToStr(bool $value): string
200  {
201  return $value ? '1' : '0';
202  }
203 
204  private function intToStr(int $int): string
205  {
206  return (string) $int;
207  }
208 
209  private function strToInt(string $str): int
210  {
211  return (int) $str;
212  }
213 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:19
setMaximumPreviews(int $max_previews)
Definition: Settings.php:126
adjustNumeric(int $value, int $min, int $max, int $default)
Definition: Settings.php:174
__construct(Container $dic, ilPlugin $plugin)