ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPreviewSettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
17 const MAX_PREVIEWS_MAX = 20;
18
19 const IMAGE_SIZE_DEFAULT = 280;
20 const IMAGE_SIZE_MIN = 50;
21 const IMAGE_SIZE_MAX = 600;
22
25 const IMAGE_QUALITY_MAX = 100;
26
31 private static $instance = null;
32
37 private $settings = null;
38
43 private $preview_enabled = true;
44
50
56
62
66 private function __construct()
67 {
68 $this->settings = new ilSetting("preview");
69 $this->preview_enabled = $this->settings->get('preview_enabled', false) == true;
70 $this->max_previews = $this->settings->get('max_previews_per_object', self::MAX_PREVIEWS_DEFAULT);
71 }
72
78 public static function setPreviewEnabled($a_value)
79 {
81 $instance->preview_enabled = $a_value == true;
82 $instance->settings->set('preview_enabled', $instance->preview_enabled);
83 }
84
90 public static function isPreviewEnabled()
91 {
92 return self::getInstance()->preview_enabled;
93 }
94
100 public static function setMaximumPreviews($a_value)
101 {
103 $instance->max_previews = self::adjustNumeric($a_value, self::MAX_PREVIEWS_MIN, self::MAX_PREVIEWS_MAX, self::MAX_PREVIEWS_DEFAULT);
104 $instance->settings->set('max_previews_per_object', $instance->max_previews);
105 }
106
112 public static function getMaximumPreviews()
113 {
114 return self::getInstance()->max_previews;
115 }
116
122 public static function setImageSize($a_value)
123 {
125 $instance->image_size = self::adjustNumeric($a_value, self::IMAGE_SIZE_MIN, self::IMAGE_SIZE_MAX, self::IMAGE_SIZE_DEFAULT);
126 $instance->settings->set('preview_image_size', $instance->image_size);
127 }
128
134 public static function getImageSize()
135 {
136 return self::getInstance()->image_size;
137 }
138
144 public static function setImageQuality($a_value)
145 {
147 $instance->image_quality = self::adjustNumeric($a_value, self::IMAGE_QUALITY_MIN, self::IMAGE_QUALITY_MAX, self::IMAGE_QUALITY_DEFAULT);
148 $instance->settings->set('preview_image_quality', $instance->image_quality);
149 }
150
156 public static function getImageQuality()
157 {
158 return self::getInstance()->image_quality;
159 }
160
165 private static function getInstance()
166 {
167 if (self::$instance == null) {
168 self::$instance = new ilPreviewSettings();
169 }
170
171 return self::$instance;
172 }
173
184 private static function adjustNumeric($value, $min, $max, $default)
185 {
186 // is number?
187 if (is_numeric($value)) {
188 // don't allow to large numbers
189 $value = (int) $value;
190 if ($value < $min) {
191 $value = $min;
192 } elseif ($value > $max) {
193 $value = $max;
194 }
195 } else {
196 $value = $default;
197 }
198
199 return $value;
200 }
201}
An exception for terminatinating execution or to throw for unit testing.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
static setImageQuality($a_value)
Sets the quality (compression) of the preview images (1-100).
static adjustNumeric($value, $min, $max, $default)
Adjusts the numeric value to fit between the specified minimum and maximum.
static getInstance()
Gets the instance of the ilPreviewSettings.
static getImageSize()
Gets the size of the preview images in pixels.
static setImageSize($a_value)
Sets the size of the preview images in pixels.
static setMaximumPreviews($a_value)
Sets the maximum number of preview pictures per object.
__construct()
Private constructor.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
static setPreviewEnabled($a_value)
Sets whether the preview functionality is enabled.
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).
ILIAS Setting Class.
settings()
Definition: settings.php:2