ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
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  return self::$instance;
171  }
172 
183  private static function adjustNumeric($value, $min, $max, $default)
184  {
185  // is number?
186  if (is_numeric($value))
187  {
188  // don't allow to large numbers
189  $value = (int)$value;
190  if ($value < $min)
191  $value = $min;
192  else if ($value > $max)
193  $value = $max;
194  }
195  else
196  {
197  $value = $default;
198  }
199 
200  return $value;
201  }
202 }
203 ?>