ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
16  const MAX_PREVIEWS_MIN = 1;
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 
24  const IMAGE_QUALITY_MIN = 20;
25  const IMAGE_QUALITY_MAX = 100;
26 
31  private static $instance = null;
32 
37  private $settings = null;
38 
43  private $preview_enabled = true;
44 
49  private $max_previews = self::MAX_PREVIEWS_DEFAULT;
50 
55  private $image_size = self::IMAGE_SIZE_DEFAULT;
56 
61  private $image_quality = self::IMAGE_QUALITY_DEFAULT;
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  {
80  $instance = self::getInstance();
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  {
102  $instance = self::getInstance();
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  {
124  $instance = self::getInstance();
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  {
146  $instance = self::getInstance();
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 }
static setMaximumPreviews($a_value)
Sets the maximum number of preview pictures per object.
settings()
Definition: settings.php:2
static getImageQuality()
Gets 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 setImageSize($a_value)
Sets the size of the preview images in pixels.
static getInstance()
Gets the instance of the ilPreviewSettings.
static setImageQuality($a_value)
Sets the quality (compression) of the preview images (1-100).
__construct()
Private constructor.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
$default
Definition: build.php:20
static getImageSize()
Gets the size of the preview images in pixels.
static setPreviewEnabled($a_value)
Sets whether the preview functionality is enabled.