ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSettingsTemplate.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $db;
17
18 private $id;
19 private $type;
20 private $title;
21 private $description;
22 private $setting = array();
23 private $hidden_tab = array();
24
25 // begin-patch loc
26 private $auto_generated = false;
27 // end-patch loc
28
33 private $config;
34
40 public function __construct($a_id = 0, $config = null)
41 {
42 global $DIC;
43
44 $this->db = $DIC->database();
45 if ($a_id > 0) {
46 if ($config) {
47 $this->setConfig($config);
48 }
49 $this->setId($a_id);
50 $this->read();
51 }
52 }
53
59 public function setId($a_val)
60 {
61 $this->id = $a_val;
62 }
63
69 public function getId()
70 {
71 return $this->id;
72 }
73
74 // begin-patch lok
79 public function setAutoGenerated($a_status)
80 {
81 $this->auto_generated = $a_status;
82 }
83
88 public function getAutoGenerated()
89 {
91 }
92 // end-patch lok
93
99 public function setTitle($a_val)
100 {
101 $this->title = $a_val;
102 }
103
109 public function getTitle()
110 {
111 return $this->title;
112 }
113
119 public function setType($a_val)
120 {
121 $this->type = $a_val;
122 }
123
129 public function getType()
130 {
131 return $this->type;
132 }
133
139 public function setDescription($a_val)
140 {
141 $this->description = $a_val;
142 }
143
149 public function getDescription()
150 {
151 return $this->description;
152 }
153
161 public function setSetting($a_setting, $a_value, $a_hide = false)
162 {
163 if ($this->getConfig()) {
164 $settings = $this->getConfig()->getSettings();
165
166 if ($settings[$a_setting]['type'] == ilSettingsTemplateConfig::CHECKBOX) {
167 if (is_array($a_value)) {
168 $a_value = serialize($a_value);
169 } else {
170 $a_value = unserialize($a_value);
171 }
172 }
173 }
174
175 $this->setting[$a_setting] = array(
176 "value" => $a_value,
177 "hide" => $a_hide
178 );
179 }
180
186 public function removeSetting($a_setting)
187 {
188 unset($this->setting[$a_setting]);
189 }
190
194 public function removeAllSettings()
195 {
196 $this->setting = array();
197 }
198
202 public function getSettings()
203 {
204 return $this->setting;
205 }
206
213 public function addHiddenTab($a_tab_id)
214 {
215 $this->hidden_tab[$a_tab_id] = $a_tab_id;
216 }
217
221 public function removeAllHiddenTabs()
222 {
223 $this->hidden_tab = array();
224 }
225
229 public function getHiddenTabs()
230 {
231 return $this->hidden_tab;
232 }
233
240 public function getConfig()
241 {
242 return $this->config;
243 }
244
251 {
252 $this->config = $config;
253 }
254
255
262 public function read()
263 {
265
266 // read template
267 $set = $ilDB->query(
268 "SELECT * FROM adm_settings_template WHERE " .
269 " id = " . $ilDB->quote($this->getId(), "integer")
270 );
271 $rec = $ilDB->fetchAssoc($set);
272 $this->setTitle($rec["title"]);
273 $this->setType($rec["type"]);
274 $this->setDescription($rec["description"]);
275 // begin-patch lok
276 $this->setAutoGenerated($rec['auto_generated']);
277 // end-patch lok
278
279 // read template setttings
280 $set = $ilDB->query(
281 "SELECT * FROM adm_set_templ_value WHERE " .
282 " template_id = " . $ilDB->quote($this->getId(), "integer")
283 );
284 while ($rec = $ilDB->fetchAssoc($set)) {
285 $this->setSetting(
286 $rec["setting"],
287 $rec["value"],
288 $rec["hide"]
289 );
290 }
291
292 // read hidden tabs
293 $set = $ilDB->query(
294 "SELECT * FROM adm_set_templ_hide_tab WHERE " .
295 " template_id = " . $ilDB->quote($this->getId(), "integer")
296 );
297 while ($rec = $ilDB->fetchAssoc($set)) {
298 $this->addHiddenTab($rec["tab_id"]);
299 }
300 }
301
305 public function create()
306 {
308
309 $this->setId($ilDB->nextId("adm_settings_template"));
310
311 // write template
312 $ilDB->insert("adm_settings_template", array(
313 "id" => array("integer", $this->getId()),
314 "title" => array("text", $this->getTitle()),
315 "type" => array("text", $this->getType()),
316 // begin-patch lok
317 "description" => array("clob", $this->getDescription()),
318 'auto_generated' => array('integer',$this->getAutoGenerated())
319 // end-patch lok
320 ));
321
322 // write settings
323 $this->insertSettings();
324
325 // write hidden tabs
326 $this->insertHiddenTabs();
327 }
328
332 public function update()
333 {
335
336 // update template
337 $ilDB->update("adm_settings_template", array(
338 "title" => array("text", $this->getTitle()),
339 "type" => array("text", $this->getType()),
340 // begin-patch lok
341 "description" => array("clob", $this->getDescription()),
342 'auto_generated' => array('integer',$this->getAutoGenerated())
343 ), array(
344 "id" => array("integer", $this->getId()),
345 ));
346
347 // delete settings and hidden tabs
348 $ilDB->manipulate(
349 "DELETE FROM adm_set_templ_value WHERE "
350 . " template_id = " . $ilDB->quote($this->getId(), "integer")
351 );
352 $ilDB->manipulate(
353 "DELETE FROM adm_set_templ_hide_tab WHERE "
354 . " template_id = " . $ilDB->quote($this->getId(), "integer")
355 );
356
357 // insert settings and hidden tabs
358 $this->insertSettings();
359 $this->insertHiddenTabs();
360 }
361
365 private function insertSettings()
366 {
368
369 foreach ($this->getSettings() as $s => $set) {
370 $ilDB->manipulate("INSERT INTO adm_set_templ_value " .
371 "(template_id, setting, value, hide) VALUES (" .
372 $ilDB->quote($this->getId(), "integer") . "," .
373 $ilDB->quote($s, "text") . "," .
374 $ilDB->quote($set["value"], "text") . "," .
375 $ilDB->quote($set["hide"], "integer") .
376 ")");
377 }
378 }
379
383 public function insertHiddenTabs()
384 {
386
387 foreach ($this->getHiddenTabs() as $tab_id) {
388 $ilDB->manipulate("INSERT INTO adm_set_templ_hide_tab " .
389 "(template_id, tab_id) VALUES (" .
390 $ilDB->quote($this->getId(), "integer") . "," .
391 $ilDB->quote($tab_id, "text") .
392 ")");
393 }
394 }
395
399 public function delete()
400 {
402
403 $ilDB->manipulate(
404 "DELETE FROM adm_settings_template WHERE "
405 . " id = " . $ilDB->quote($this->getId(), "integer")
406 );
407 $ilDB->manipulate(
408 "DELETE FROM adm_set_templ_value WHERE "
409 . " template_id = " . $ilDB->quote($this->getId(), "integer")
410 );
411 $ilDB->manipulate(
412 "DELETE FROM adm_set_templ_hide_tab WHERE "
413 . " template_id = " . $ilDB->quote($this->getId(), "integer")
414 );
415 }
416
422 public static function getAllSettingsTemplates($a_type, $a_include_auto_generated = false)
423 {
424 global $DIC;
425
426 $ilDB = $DIC->database();
427
428 // begin-patch lok
429 if ($a_include_auto_generated) {
430 $set = $ilDB->query("SELECT * FROM adm_settings_template " .
431 " WHERE type = " . $ilDB->quote($a_type, "text") .
432 " ORDER BY title");
433 } else {
434 $set = $ilDB->query("SELECT * FROM adm_settings_template " .
435 " WHERE type = " . $ilDB->quote($a_type, "text") .
436 'AND auto_generated = ' . $ilDB->quote(0, 'integer') . ' ' .
437 " ORDER BY title");
438 }
439 // end-patch lok
440
441
442 $settings_template = array();
443 while ($rec = $ilDB->fetchAssoc($set)) {
444 $settings_template[] = $rec;
445 }
446 return $settings_template;
447 }
448
455 protected static function lookupProperty($a_id, $a_prop)
456 {
457 global $DIC;
458
459 $ilDB = $DIC->database();
460
461 $set = $ilDB->query(
462 "SELECT $a_prop FROM adm_settings_template WHERE " .
463 " id = " . $ilDB->quote($a_id, "integer")
464 );
465 $rec = $ilDB->fetchAssoc($set);
466 return $rec[$a_prop];
467 }
468
469 // begin-patch lok
476 public static function lookupTitle($a_id)
477 {
478 return self::lookupProperty($a_id, 'title');
479 }
486 public static function lookupDescription($a_id)
487 {
488 return self::lookupProperty($a_id, 'description');
489 }
490
491 // begin-patch lok
492 public static function translate($a_title_desc)
493 {
494 if (substr($a_title_desc, 0, 3) == 'il_') {
495 return $GLOBALS['lng']->txt($a_title_desc);
496 }
497 return $a_title_desc;
498 }
499 // end-patch lok
500}
An exception for terminatinating execution or to throw for unit testing.
Settings template config class.
Settings template application class.
setAutoGenerated($a_status)
Set auto generated status.
getConfig()
Returns the template config associated with this template or NULL if none is given.
getHiddenTabs()
Get hidden tabs.
static getAllSettingsTemplates($a_type, $a_include_auto_generated=false)
Get all settings templates of type.
static translate($a_title_desc)
create()
Create settings template.
addHiddenTab($a_tab_id)
Add hidden tab.
__construct($a_id=0, $config=null)
Constructor.
getAutoGenerated()
Get auto generated status.
setSetting($a_setting, $a_value, $a_hide=false)
Set setting.
removeSetting($a_setting)
Remove setting.
insertSettings()
Insert settings to db.
getDescription()
Get description.
removeAllHiddenTabs()
Remove all hidden tabs.
static lookupDescription($a_id)
Lookup title.
update()
Update settings template.
static lookupTitle($a_id)
Lookup title.
setConfig(ilSettingsTemplateConfig $config)
Sets the template config for this template.
setDescription($a_val)
Set description.
static lookupProperty($a_id, $a_prop)
Lookup property.
insertHiddenTabs()
Insert hidden tabs.
removeAllSettings()
Remove all settings.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$s
Definition: pwgen.php:45
global $DIC
Definition: saml.php:7
global $ilDB
$a_type
Definition: workflow.php:92