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 $widgetClassName = "TemplateWidget_{$item['type']}";
37 if(!class_available($widgetClassName)){
38 echo "Unknown widget class {$widgetClassName}! Falling back to default widget.<br>";
39 $widgetClassName = "TemplateWidget";
40 }
42 $this->widgets[$name] = new $widgetClassName($this->config, $name,
43 $item['value'],
44 $item['description'],
45 $item['required'],
46 $item['type'],
47 $item['display']);
48 }
49 }
50 }
52 function load($array)
53 {
54 $this->data = $array;
55 }
57 function setTemplate($tmpl)
58 {
59 $this->template = $tmpl;
60 }
62 function getWidgets()
63 {
64 return($this->widgets);
65 }
67 function render()
68 {
69 $smarty = get_smarty();
70 $smarty->assign("type", $this->itemType);
71 foreach($this->widgets as $widget){
72 $smarty->assign($widget->getName(), $widget->render());
73 }
74 return($smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE)));
75 }
77 function save_object()
78 {
79 foreach($this->widgets as $widget){
80 $widget->save_object();
81 }
82 }
83 }
86 ?>