ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGeneralSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 {
6  private static $_instance;
7 
8  public $db;
9  public $settings;
10 
11  public static function _getInstance()
12  {
13  if(!isset(self::$_instance))
14  {
15  self::$_instance = new ilGeneralSettings();
16  }
17 
18  return self::$_instance;
19  }
20 
21  public function ilGeneralSettings()
22  {
23  global $ilDB;
24 
25  $this->db = $ilDB;
26 
27  $this->__getSettings();
28  }
29 
35  private function fetchSettingsId()
36  {
37  $result = $this->db->query('SELECT settings_id FROM payment_settings');
38  while($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
39  {
40  $this->setSettingsId($row->settings_id);
41  }
42  }
43 
44  public function setSettingsId($a_settings_id = 0)
45  {
46  $this->settings_id = $a_settings_id;
47 
48  }
49  public function getSettingsId()
50  {
51  return $this->settings_id;
52  }
53 
54  public function get($a_type)
55  {
56  return $this->settings[$a_type];
57  }
58 
59  public function getAll()
60  {
61  return $this->settings;
62  }
63 
64  public function clearAll()
65  {
66  $statement = $this->db->manipulateF('
67  UPDATE payment_settings
68  SET currency_unit = %s,
69  currency_subunit = %s,
70  address = %s,
71  bank_data = %s,
72  add_info = %s,
73  pdf_path = %s,
74  topics_sorting_type = %s,
75  topics_sorting_direction = %s,
76  topics_allow_custom_sorting = %s,
77  max_hits = %s,
78  shop_enabled = %s,
79  hide_advanced_search = %s,
80  objects_allow_custom_sorting = %s,
81  hide_coupons = %s,
82  hide_news = %s
83  WHERE settings_id = %s',
84  array( 'text',
85  'text',
86  'text',
87  'text',
88  'text',
89  'text',
90  'integer',
91  'integer',
92  'text',
93  'integer',
94  'integer',
95  'integer',
96  'integer',
97  'integer',
98  'integer',
99  'integer'),
100  array( NULL,
101  NULL,
102  NULL,
103  NULL,
104  NULL,
105  NULL,
106  '1',
107  'asc',
108  '0',
109  '20',
110  '0',
111  '0',
112  '0',
113  '0',
114  '0',
115  $this->getSettingsId())
116  );
117 
118  return true;
119  }
120 
121  public function setAll($a_values)
122  {
123  global $ilDB;
124 
125  if ($this->getSettingsId())
126  {
127 
128  if(!$a_values['currency_unit']) $a_values['currency_unit'] = NULL;
129  if(!$a_values['currency_subunit']) $a_values['currency_subunit'] = NULL;
130  if(!$a_values['address']) $a_values['address'] = NULL;
131  if(!$a_values['bank_data']) $a_values['bank_data'] = NULL;
132  if(!$a_values['add_info']) $a_values['add_info'] = NULL;
133  if(!$a_values['pdf_path']) $a_values['pdf_path'] = NULL;
134 
135  if(!$a_values['topics_allow_custom_sorting']) $a_values['topics_allow_custom_sorting'] = 0;
136  if(!$a_values['topics_sorting_type']) $a_values['topics_sorting_type'] = 0;
137  if(!$a_values['topics_sorting_direction']) $a_values['topics_sorting_direction'] = NULL;
138  if(!$a_values['shop_enabled']) $a_values['shop_enabled'] = 0;
139  if(!$a_values['max_hits']) $a_values['max_hits'] = 0;
140  if(!$a_values['hide_advanced_search']) $a_values['hide_advanced_search'] = 0;
141  if(!$a_values['objects_allow_custom_sorting']) $a_values['objects_allow_custom_sorting'] = 0;
142  if(!$a_values['hide_coupons']) $a_values['hide_coupons'] = 0;
143  if(!$a_values['hide_news']) $a_values['hide_news'] = 0;
144 
145 
146  $statement = $this->db->manipulateF('
147  UPDATE payment_settings
148  SET currency_unit = %s,
149  currency_subunit = %s,
150  address = %s,
151  bank_data = %s,
152  add_info = %s,
153  pdf_path = %s,
154  topics_sorting_type = %s,
155  topics_sorting_direction = %s,
156  topics_allow_custom_sorting = %s,
157  max_hits = %s,
158  shop_enabled = %s,
159  hide_advanced_search = %s,
160  objects_allow_custom_sorting = %s,
161  hide_coupons = %s,
162  hide_news = %s
163  WHERE settings_id = %s',
164  array( 'text',
165  'text',
166  'text',
167  'text',
168  'text',
169  'text',
170  'integer',
171  'text',
172  'integer',
173  'integer',
174  'integer',
175  'integer',
176  'integer',
177  'integer',
178  'integer',
179  'integer'),
180  array(
181  $a_values['currency_unit'],
182  $a_values['currency_subunit'],
183  $a_values['address'],
184  $a_values['bank_data'],
185  $a_values['add_info'],
186  $a_values['pdf_path'],
187  $a_values['topics_sorting_type'],
188  $a_values['topics_sorting_direction'],
189  $a_values['topics_allow_custom_sorting'],
190  $a_values['max_hits'],
191  $a_values['shop_enabled'],
192  $a_values['hide_advanced_search'],
193  $a_values['objects_allow_custom_sorting'],
194  $a_values['hide_coupons'],
195  $a_values['hide_news'],
196  $this->getSettingsId())
197  );
198  }
199  else
200  {
201 
202 
203  if(!$a_values['currency_unit']) $a_values['currency_unit'] = NULL;
204  if(!$a_values['currency_subunit']) $a_values['currency_subunit'] = NULL;
205  if(!$a_values['address']) $a_values['address'] = NULL;
206  if(!$a_values['bank_data']) $a_values['bank_data'] = NULL;
207  if(!$a_values['add_info']) $a_values['add_info'] = NULL;
208 
209  if(!$a_values['pdf_path']) $a_values['pdf_path'] = NULL;
210 
211  if(!$a_values['topics_allow_custom_sorting']) $a_values['topics_allow_custom_sorting'] = 0;
212  if(!$a_values['topics_sorting_type']) $a_values['topics_sorting_type'] = 0;
213  if(!$a_values['topics_sorting_direction']) $a_values['topics_sorting_direction'] = NULL;
214  if(!$a_values['shop_enabled']) $a_values['shop_enabled'] = 0;
215  if(!$a_values['max_hits']) $a_values['max_hits'] = 0;
216  if(!$a_values['hide_advanced_search']) $a_values['hide_advanced_search'] = 0;
217  if(!$a_values['objects_allow_custom_sorting']) $a_values['objects_allow_custom_sorting'] = 0;
218  if(!$a_values['hide_coupons']) $a_values['hide_coupons'] = 0;
219  if(!$a_values['hide_news']) $a_values['hide_news'] = 0;
220 
221 
222  $next_id = $ilDB->nextId('payment_settings');
223  $statement = $this->db->manipulateF('
224  INSERT INTO payment_settings
225  ( settings_id,
226  currency_unit,
227  currency_subunit,
228  address,
229  bank_data,
230  add_info,
231  pdf_path,
232  topics_allow_custom_sorting,
233  topics_sorting_type,
234  topics_sorting_direction,
235  shop_enabled,
236  max_hits,
237  hide_advanced_search,
238  objects_allow_custom_sorting,
239  hide_coupons,
240  hide_news
241  )
242  VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
243  array( 'integer',
244  'text',
245  'text',
246  'text',
247  'text',
248  'text',
249  'text',
250  'integer',
251  'integer',
252  'text',
253  'integer',
254  'integer',
255  'integer',
256  'integer',
257  'integer',
258  'integer'),
259  array(
260  $next_id,
261  $a_values['currency_unit'],
262  $a_values['currency_subunit'],
263  $a_values['address'],
264  $a_values['bank_data'],
265  $a_values['add_info'],
266  $a_values['pdf_path'],
267  $a_values['topics_allow_custom_sorting'],
268  $a_values['topics_sorting_type'],
269  $a_values['topics_sorting_direction'],
270  $a_values['shop_enabled'],
271  $a_values['max_hits'],
272  $a_values['hide_advanced_search'],
273  $a_values['objects_allow_custom_sorting'],
274  $a_values['hide_coupons'],
275  $a_values['hide_news']
276  )
277  );
278  }
279 
280  $this->__getSettings();
281 
282  return true;
283  }
284 
285  private function __getSettings()
286  {
287  $this->fetchSettingsId();
288 
289  $result = $this->db->query('SELECT * FROM payment_settings');
290 
291  $data = array();
292  while($row = $result->fetchRow(DB_FETCHMODE_OBJECT))
293  {
294  $data['currency_unit'] = $row->currency_unit;
295  $data['currency_subunit'] = $row->currency_subunit;
296  $data['address'] = $row->address;
297  $data['bank_data'] = $row->bank_data;
298  $data['add_info'] = $row->add_info;
299  $data['pdf_path'] = $row->pdf_path;
300  $data['topics_allow_custom_sorting'] = $row->topics_allow_custom_sorting;
301  $data['topics_sorting_type'] = $row->topics_sorting_type;
302  $data['topics_sorting_direction'] = $row->topics_sorting_direction;
303  $data['max_hits'] = $row->max_hits;
304  $data['shop_enabled'] = $row->shop_enabled;
305  $data['hide_advanced_search'] = $row->hide_advanced_search;
306  $data['objects_allow_custom_sorting'] = $row->objects_allow_custom_sorting;
307  $data['hide_coupons'] = $row->hide_coupons;
308  $data['hide_news'] = $row->hide_news;
309  }
310  $this->settings = $data;
311  }
312 
313  public static function _isPaymentEnabled()
314  {
315  global $ilDB;
316 
317  $res = $ilDB->query('SELECT shop_enabled FROM payment_settings');
318  $row = $ilDB->fetchAssoc($res);
319 
320  return $row['shop_enabled'];
321  }
322 }
323 ?>