1 <?php
3 class TemplateEngine
4 {
5 private $config;
6 private $data = array();
7 private $template = "";
9 private $itemType = '';
11 function __construct($config)
12 {
13 $this->config = &$config;
14 }
16 function setValues($values)
17 {
18 foreach($values as $name => $value){
19 $this->widgets[$name]->setValue($value);
20 }
21 }
23 function setType($name)
24 {
25 $this->itemType = $name;
26 $this->widgets = array();
28 if(!isset($this->data[$this->itemType])){
29 trigger_error("Undefined item type '{$name}'!");
30 return;
31 }
32 $data = $this->data[$this->itemType];
33 if(isset($data['options']) && count($data['options'])){
34 foreach($data['options'] as $name => $item){
36 $this->widgets[$name] = new TemplateWidget($this->config, $name,
37 $item['value'],
38 $item['description'],
39 $item['required'],
40 $item['type'],
41 $item['display']);
42 }
43 }
44 }
46 function load($array)
47 {
48 $this->data = $array;
49 }
51 function setTemplate($tmpl)
52 {
53 $this->template = $tmpl;
54 }
56 function getWidgets()
57 {
58 return($this->widgets);
59 }
61 function render()
62 {
63 $smarty = get_smarty();
64 $smarty->assign("type", $this->itemType);
65 foreach($this->widgets as $widget){
66 $smarty->assign($widget->getName(), $widget->render());
67 }
68 return($smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE)));
69 }
71 function save_object()
72 {
73 foreach($this->widgets as $widget){
74 $widget->save_object();
75 }
76 }
77 }
80 ?>