ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
13  private $id;
14  private $type;
15  private $title;
16  private $description;
17  private $setting = array();
18  private $hidden_tab = array();
19 
20  // begin-patch loc
21  private $auto_generated = false;
22  // end-patch loc
23 
28  private $config;
29 
35  function __construct($a_id = 0, $config = null)
36  {
37  if ($a_id > 0)
38  {
39  if ($config)
40  $this->setConfig($config);
41  $this->setId($a_id);
42  $this->read();
43  }
44  }
45 
51  function setId($a_val)
52  {
53  $this->id = $a_val;
54  }
55 
61  function getId()
62  {
63  return $this->id;
64  }
65 
66  // begin-patch lok
71  public function setAutoGenerated($a_status)
72  {
73  $this->auto_generated = $a_status;
74  }
75 
80  public function getAutoGenerated()
81  {
82  return $this->auto_generated;
83  }
84  // end-patch lok
85 
91  function setTitle($a_val)
92  {
93  $this->title = $a_val;
94  }
95 
101  function getTitle()
102  {
103  return $this->title;
104  }
105 
111  public function setType($a_val)
112  {
113  $this->type = $a_val;
114  }
115 
121  public function getType()
122  {
123  return $this->type;
124  }
125 
131  public function setDescription($a_val)
132  {
133  $this->description = $a_val;
134  }
135 
141  public function getDescription()
142  {
143  return $this->description;
144  }
145 
153  function setSetting($a_setting, $a_value, $a_hide = false)
154  {
155  if ($this->getConfig()) {
156  $settings = $this->getConfig()->getSettings();
157 
158  if ($settings[$a_setting]['type'] == ilSettingsTemplateConfig::CHECKBOX) {
159  if (is_array($a_value))
160  $a_value = serialize($a_value);
161  else
162  $a_value = unserialize($a_value);
163  }
164  }
165 
166  $this->setting[$a_setting] = array(
167  "value" => $a_value,
168  "hide" => $a_hide
169  );
170  }
171 
177  function removeSetting($a_setting)
178  {
179  unset($this->setting[$a_setting]);
180  }
181 
185  function removeAllSettings()
186  {
187  $this->setting = array();
188  }
189 
193  function getSettings()
194  {
195  return $this->setting;
196  }
197 
204  function addHiddenTab($a_tab_id)
205  {
206  $this->hidden_tab[$a_tab_id] = $a_tab_id;
207  }
208 
213  {
214  $this->hidden_tab = array();
215  }
216 
220  function getHiddenTabs()
221  {
222  return $this->hidden_tab;
223  }
224 
231  public function getConfig() {
232  return $this->config;
233  }
234 
241  $this->config = $config;
242  }
243 
244 
251  function read()
252  {
253  global $ilDB;
254 
255  // read template
256  $set = $ilDB->query("SELECT * FROM adm_settings_template WHERE ".
257  " id = ".$ilDB->quote($this->getId(), "integer")
258  );
259  $rec = $ilDB->fetchAssoc($set);
260  $this->setTitle($rec["title"]);
261  $this->setType($rec["type"]);
262  $this->setDescription($rec["description"]);
263  // begin-patch lok
264  $this->setAutoGenerated($rec['auto_generated']);
265  // end-patch lok
266 
267  // read template setttings
268  $set = $ilDB->query("SELECT * FROM adm_set_templ_value WHERE ".
269  " template_id = ".$ilDB->quote($this->getId(), "integer")
270  );
271  while ($rec = $ilDB->fetchAssoc($set))
272  {
273  $this->setSetting($rec["setting"],
274  $rec["value"], $rec["hide"]);
275  }
276 
277  // read hidden tabs
278  $set = $ilDB->query("SELECT * FROM adm_set_templ_hide_tab WHERE ".
279  " template_id = ".$ilDB->quote($this->getId(), "integer")
280  );
281  while ($rec = $ilDB->fetchAssoc($set))
282  {
283  $this->addHiddenTab($rec["tab_id"]);
284  }
285  }
286 
290  function create()
291  {
292  global $ilDB;
293 
294  $this->setId($ilDB->nextId("adm_settings_template"));
295 
296  // write template
297  $ilDB->insert("adm_settings_template", array(
298  "id" => array("integer", $this->getId()),
299  "title" => array("text", $this->getTitle()),
300  "type" => array("text", $this->getType()),
301  // begin-patch lok
302  "description" => array("clob", $this->getDescription()),
303  'auto_generated' => array('integer',$this->getAutoGenerated())
304  // end-patch lok
305  ));
306 
307  // write settings
308  $this->insertSettings();
309 
310  // write hidden tabs
311  $this->insertHiddenTabs();
312  }
313 
317  public function update()
318  {
319  global $ilDB;
320 
321  // update template
322  $ilDB->update("adm_settings_template", array(
323  "title" => array("text", $this->getTitle()),
324  "type" => array("text", $this->getType()),
325  // begin-patch lok
326  "description" => array("clob", $this->getDescription()),
327  'auto_generated' => array('integer',$this->getAutoGenerated())
328  ), array(
329  "id" => array("integer", $this->getId()),
330  ));
331 
332  // delete settings and hidden tabs
333  $ilDB->manipulate("DELETE FROM adm_set_templ_value WHERE "
334  ." template_id = ".$ilDB->quote($this->getId(), "integer")
335  );
336  $ilDB->manipulate("DELETE FROM adm_set_templ_hide_tab WHERE "
337  ." template_id = ".$ilDB->quote($this->getId(), "integer")
338  );
339 
340  // insert settings and hidden tabs
341  $this->insertSettings();
342  $this->insertHiddenTabs();
343 
344  }
345 
349  private function insertSettings()
350  {
351  global $ilDB;
352 
353  foreach ($this->getSettings() as $s => $set)
354  {
355  $ilDB->manipulate("INSERT INTO adm_set_templ_value ".
356  "(template_id, setting, value, hide) VALUES (".
357  $ilDB->quote($this->getId(), "integer").",".
358  $ilDB->quote($s, "text").",".
359  $ilDB->quote($set["value"], "text").",".
360  $ilDB->quote($set["hide"], "integer").
361  ")");
362  }
363  }
364 
368  function insertHiddenTabs()
369  {
370  global $ilDB;
371 
372  foreach ($this->getHiddenTabs() as $tab_id)
373  {
374  $ilDB->manipulate("INSERT INTO adm_set_templ_hide_tab ".
375  "(template_id, tab_id) VALUES (".
376  $ilDB->quote($this->getId(), "integer").",".
377  $ilDB->quote($tab_id, "text").
378  ")");
379  }
380  }
381 
385  function delete()
386  {
387  global $ilDB;
388 
389  $ilDB->manipulate("DELETE FROM adm_settings_template WHERE "
390  ." id = ".$ilDB->quote($this->getId(), "integer")
391  );
392  $ilDB->manipulate("DELETE FROM adm_set_templ_value WHERE "
393  ." template_id = ".$ilDB->quote($this->getId(), "integer")
394  );
395  $ilDB->manipulate("DELETE FROM adm_set_templ_hide_tab WHERE "
396  ." template_id = ".$ilDB->quote($this->getId(), "integer")
397  );
398  }
399 
405  static function getAllSettingsTemplates($a_type, $a_include_auto_generated = false)
406  {
407  global $ilDB;
408 
409  // begin-patch lok
410  if($a_include_auto_generated)
411  {
412  $set = $ilDB->query("SELECT * FROM adm_settings_template ".
413  " WHERE type = ".$ilDB->quote($a_type, "text").
414  " ORDER BY title");
415  }
416  else
417  {
418  $set = $ilDB->query("SELECT * FROM adm_settings_template ".
419  " WHERE type = ".$ilDB->quote($a_type, "text").
420  'AND auto_generated = '.$ilDB->quote(0,'integer').' '.
421  " ORDER BY title");
422  }
423  // end-patch lok
424 
425 
426  $settings_template = array();
427  while ($rec = $ilDB->fetchAssoc($set))
428  {
429  $settings_template[] = $rec;
430  }
431  return $settings_template;
432  }
433 
440  protected static function lookupProperty($a_id, $a_prop)
441  {
442  global $ilDB;
443 
444  $set = $ilDB->query("SELECT $a_prop FROM adm_settings_template WHERE ".
445  " id = ".$ilDB->quote($a_id, "integer")
446  );
447  $rec = $ilDB->fetchAssoc($set);
448  return $rec[$a_prop];
449  }
450 
451  // begin-patch lok
458  static function lookupTitle($a_id)
459  {
460  return self::lookupProperty($a_id, 'title');
461  }
468  static function lookupDescription($a_id)
469  {
470  return self::lookupProperty($a_id, 'description');
471  }
472 
473  // begin-patch lok
474  public static function translate($a_title_desc)
475  {
476  if(substr($a_title_desc, 0, 3) == 'il_')
477  {
478  return $GLOBALS['lng']->txt($a_title_desc);
479  }
480  return $a_title_desc;
481  }
482  // end-patch lok
483 }
484 ?>
setDescription($a_val)
Set description.
static getAllSettingsTemplates($a_type, $a_include_auto_generated=false)
Get all settings templates of type.
setTitle($a_val)
Set title.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getDescription()
Get description.
setAutoGenerated($a_status)
Set auto generated status.
removeAllHiddenTabs()
Remove all hidden tabs.
setConfig(ilSettingsTemplateConfig $config)
Sets the template config for this template.
$a_type
Definition: workflow.php:93
getHiddenTabs()
Get hidden tabs.
static translate($a_title_desc)
insertHiddenTabs()
Insert hidden tabs.
update()
Update settings template.
__construct($a_id=0, $config=null)
Constructor.
removeAllSettings()
Remove all settings.
static lookupTitle($a_id)
Lookup title.
addHiddenTab($a_tab_id)
Add hidden tab.
Create styles array
The data for the language used.
Settings template config class.
setSetting($a_setting, $a_value, $a_hide=false)
Set setting.
create()
Create settings template.
global $ilDB
removeSetting($a_setting)
Remove setting.
getAutoGenerated()
Get auto generated status.
insertSettings()
Insert settings to db.
getConfig()
Returns the template config associated with this template or NULL if none is given.
Settings template application class.
static lookupProperty($a_id, $a_prop)
Lookup property.
static lookupDescription($a_id)
Lookup title.