summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b8fc08a)
raw | patch | inline | side by side (parent: b8fc08a)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 27 Sep 2010 13:30:25 +0000 (13:30 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 27 Sep 2010 13:30:25 +0000 (13:30 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19802 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/goto/admin/systems/goto/Config/class_DeviceConfig.inc | patch | blob | history | |
gosa-plugins/goto/admin/systems/goto/Config/class_TemplateEngine.inc | patch | blob | history |
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 4b519b2bf306e0a97e95ff366dbd23df8819eab7..a40c864a145112bb8c1da4ba9d09ecc0581231fd 100644 (file)
// Update the template engine to use another type of item and
// some other values.
- $this->TemplateEngine->setType($this->currentItemType);
- $this->TemplateEngine->setValues($this->currentItem['values']);
+ $this->TemplateEngine->setValues($this->currentItemType,$this->currentItem['values']);
}
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 3ef186298a3f7a6feb85bd7abd9b2d619bb558ad..fb4d55a7681ff36e23e8f7b9c3642e909bcf7411 100644 (file)
<?php
+/*! \brief A template engine used to render dynamic template
+ * for the GOsa-devices.
+ */
class TemplateEngine
{
private $config;
private $data = array();
private $template = "";
-
private $itemType = '';
private $widgets = array();
+
+ /*! \brief Constructs the template engine.
+ * @param Config The GOsa configuration object.
+ */
function __construct($config)
{
$this->config = &$config;
}
- function setValues($values)
+
+ /*! \brief Load/Sets the instruction-set to use for the current
+ * device configuration.
+ * A device configruation tells us what options
+ * an item can have and what children.
+ * @param Array The instruction set to use.
+ */
+ function load($array)
{
- foreach($values as $name => $value){
- if(!isset($this->widgets[$name])){
- $class = get_class();
- echo "Unknown option '{$name}' for {$class}!)}<br>";
- continue;
- }
- $this->widgets[$name]->setValue($value);
- }
+ $this->data = $array;
+ }
+
+
+ /*! \brief Set the template which will be used to generate
+ * the HTML content for this configuration session.
+ * @param String A template filename.
+ */
+ function setTemplate($tmpl)
+ {
+ $this->template = $tmpl;
}
- function setType($name)
+
+ /*! \brief Returns the list of widgets which are currently used
+ * by the template engine to render the plugin.
+ * @return Array A list of widgets.
+ */
+ function getWidgets()
+ {
+ return($this->widgets);
+ }
+
+
+ /*! \brief Sets the current item type we want to render
+ * E.g. 'KickstartTemplate' and the corresponding values.
+ *
+ * @param String The name of the item we want to render now.
+ * @param Array The initial value.
+ */
+ function setValues($name)
{
+ // Set the current item type and reset the widget list.
$this->itemType = $name;
$this->widgets = array();
+ // Do nothing if something seems to be wrong.
if(!isset($this->data[$this->itemType])){
echo "Undefined item type '{$name}'!<br>";
return;
}
+
+ // Get the options provided by the item and create widget for them.
$data = $this->data[$this->itemType];
if(isset($data['options']) && count($data['options'])){
foreach($data['options'] as $name => $item){
-
$widgetClassName = "TemplateWidget_{$item['type']}";
+
+ // Check if the widget is available, if it is not, use a default (string).
if(!class_available($widgetClassName)){
echo "Unknown widget class {$widgetClassName}! Falling back to default widget.<br>";
$widgetClassName = "TemplateWidget_string";
}
+ // Prepare the value for the widget
+ $value = $item['value'];
+ if(isset($values[$name])){
+ $value = $values[$name];
+ }
+
+ // Create the new widget.
$this->widgets[$name] = new $widgetClassName($this->config, $name,
- $item['value'],
- $item['description'],
- $item['required'],
- $item['type'],
- $item['display']);
+ $item['value'],
+ $item['description'],
+ $item['required'],
+ $item['type'],
+ $item['display']);
}
}
}
- function load($array)
- {
- $this->data = $array;
- }
-
- function setTemplate($tmpl)
- {
- $this->template = $tmpl;
- }
-
- function getWidgets()
- {
- return($this->widgets);
- }
+ /*! \brief Creates the HTML content for the given list of widgets
+ * @return String The HTML content.
+ */
function render()
{
$smarty = get_smarty();
$smarty->assign("type", $this->itemType);
+
+ // Tell smarty the HTML-content for each widget and the name that should be
+ // displayed.
foreach($this->widgets as $widget){
$smarty->assign($widget->getName(), $widget->render());
$smarty->assign($widget->getName()."Name", $widget->getDisplayName());
return($smarty->fetch(get_template_path("goto/Config/{$this->template}", TRUE)));
}
+
+ /*! \brief Keep track of posted values.
+ */
function save_object()
{
foreach($this->widgets as $widget){