wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.DefaultValueRenderer.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.DefaultValueRenderer.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/core/class.WCMFException.php");
20 require_once(BASE."wcmf/lib/util/class.InifileParser.php");
21 require_once(BASE."wcmf/lib/presentation/class.View.php");
22 require_once(BASE."wcmf/lib/presentation/class.Controller.php");
23 
24 /**
25  * @class DefaultValueRenderer
26  * @ingroup Presentation
27  * @brief DefaultValueRenderer is responsible for rendering (Node) values of a given display type.
28  * Each display type is defined in a smarty template, which is configured by the appropriate entry
29  * in the configuration section 'htmldisplay' (e.g. the image display type has the entry 'image').
30  * The templates get a default set of variables assigned. Additional variables, needed only for
31  * certain display types, are assigned in the appropriate configure method (e.g. 'configure_image')
32  * which may be overridden by subclasses.
33  *
34  * New controls may be defined by defining the template, putting it into the configuration
35  * section 'htmlform' and maybe implementing a configure method in a subclass of DefaultControlRenderer.
36  * If a subclass is needed, the key 'ControlRenderer' in the configuration section 'implementation'
37  * must point to it (don't forget to give the class definition in the 'classmapping' section).
38  *
39  * @author ingo herwig <ingo@wemove.com>
40  */
42 {
43  var $view = null;
44 
45  /**
46  * Render a value of given type using the appropriate smarty template (defined in the
47  * config section 'htmldisplay'). The given parameters will be passed to the view. If additional
48  * parameters are needed an configure method must be implemented (name: configure_type)
49  * @param type The display type of the value (the template is selected based on the type)
50  * @param value The value to display
51  * @param attributes An attribute string to be placed in the html tag (defining its appearance)
52  * @return The HMTL representation of the value
53  */
54  function renderValue($type, $value, $attributes)
55  {
56  $parser = InifileParser::getInstance();
57 
58  // build input control
59  if ($view == null)
60  $view = new View();
61  else
62  $view->clear_all_assign();
63 
64  // set default view parameters
65  $view->setup();
66  $view->assign('value', $value);
67  $view->assign('attributes', $attributes);
68 
69  // split attributes into array and assign it
70  $attributeList = array();
71  $attributeParts = preg_split("/[\s,;]+/", $attributes);
72  foreach($attributeParts as $attribute)
73  {
74  if (strlen($attribute) > 0)
75  {
76  list($key, $value) = preg_split("/[=:]+/", $attribute);
77  $key = trim(stripslashes($key));
78  $value = trim(stripslashes($value));
79  $attributeList[$key] = $value;
80  }
81  }
82  $view->assign('attributeList', $attributeList);
83 
84  // set additional view parameters if needed
85  $configureFunction = "configure_".$type;
86  if (method_exists($this, $configureFunction))
87  $this->$configureFunction($view);
88 
89  if ($viewTpl = $parser->getValue($type, 'htmldisplay') === false)
90  WCMFException::throwEx("Unknown value display '".$type."'", __FILE__, __LINE__);
91 
92  $htmlString = $view->fetch(BASE.$parser->getValue($type, 'htmldisplay'));
93  return $htmlString;
94  }
95  /**
96  * Set additional parameters to the image html representation
97  * @param view A reference to the html view
98  */
99  function configure_image(&$view)
100  {
101  $value = $view->get_template_vars('value');
102  if (file_exists($value))
103  {
104  $properties = getimagesize($value);
105  $view->assign('width', $properties[0]);
106  $view->assign('height', $properties[1]);
107  $view->assign('filename', basename($value));
108  $view->assign('exists', true);
109  }
110  else
111  $view->assign('exists', false);
112  }
113  /**
114  * Set additional parameters to the text html representation
115  * @param view A reference to the html view
116  */
117  function configure_text(&$view)
118  {
119  }
120 }
121 ?>
renderValue($type, $value, $attributes)
throwEx($message, $file='', $line='')
View is used by Controller to handle the view presentation in MVC pattern. View is a subclass of Smar...
Definition: class.View.php:31
DefaultValueRenderer is responsible for rendering (Node) values of a given display type...