From bd68dd7bd16595eb09b9e5a0624d9d38e5900642 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 27 Sep 2010 07:51:00 +0000 Subject: [PATCH] Updated template engine git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19792 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../goto/Config/class_DeviceConfig.inc | 5 +++- .../goto/Config/class_TemplateEngine.inc | 26 ++++++++++++++++--- .../goto/admin/systems/goto/Config/puppet.tpl | 6 +++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc index f0ed51c56..01d9ecc48 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc @@ -69,6 +69,7 @@ class DeviceConfig extends plugin }'; $this->itemConfig = json_decode($str, TRUE); + $this->TemplateEngine->load($this->itemConfig); // Check for the root object if(!isset($this->itemConfig['root'])){ @@ -142,6 +143,7 @@ class DeviceConfig extends plugin { $this->currentItemName = $item; $this->currentItem = &$this->currentItemValues[$item]; + $this->currentItemType = $this->currentItem['type']; $this->currentItemDescriptor =&$this->itemConfig[$this->currentItem['type']]; } @@ -159,7 +161,8 @@ class DeviceConfig extends plugin - $this->TemplateEngine->load($this->currentItemDescriptor); + $this->TemplateEngine->setType($this->currentItemType); + $this->TemplateEngine->setValues($this->currentItem); $this->TemplateEngine->setTemplate('puppet.tpl'); $smarty->assign('template',$this->TemplateEngine->render()); return($smarty->fetch(get_template_path('goto/Config/DeviceConfig.tpl', TRUE))); diff --git a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc index 3d4606796..f976ed51a 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc +++ b/gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc @@ -6,15 +6,34 @@ class TemplateEngine private $data = array(); private $template = ""; + private $itemType = ''; + function __construct($config) { $this->config = &$config; } + function setValues($array) + { +# print_a($array); + } + + function setType($name) + { + $this->itemType = $name; + $this->widgets = array(); + + $data = $this->data[$this->itemType]; + if(isset($data['options']) && count($data['options'])){ + foreach($data['options'] as $name => $item){ + $this->widgets[] = new TemplateWidget($this->config, $name, $item['value']); + } + } + } + function load($array) { $this->data = $array; - } function setTemplate($tmpl) @@ -24,14 +43,13 @@ class TemplateEngine function getWidgets() { - $res = array(); -# $res[] = new TemplateWidget($this->config, 'name', 'herbert'); - return($res); + return($this->widgets); } function render() { $smarty = get_smarty(); + $smarty->assign("type", $this->itemType); foreach($this->getWidgets() as $widget){ $smarty->assign($widget->getName(), $widget->render()); } diff --git a/gosa-plugins/goto/admin/systems/goto/Config/puppet.tpl b/gosa-plugins/goto/admin/systems/goto/Config/puppet.tpl index e69de29bb..92506229e 100644 --- a/gosa-plugins/goto/admin/systems/goto/Config/puppet.tpl +++ b/gosa-plugins/goto/admin/systems/goto/Config/puppet.tpl @@ -0,0 +1,6 @@ +{if $type == 'PuppetModule'} +
{$dependency} +
{$version} +
{$name} +
{$description} +{/if} -- 2.30.2