HTML_QuickForm
[ class tree: HTML_QuickForm ] [ index: HTML_QuickForm ] [ all elements ]

Source for file ObjectFlexy.php

Documentation is available at ObjectFlexy.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Ron McClain <ron@humaniq.com>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: ObjectFlexy.php,v 1.8 2006/10/07 20:12:17 avb Exp $
  20.  
  21. require_once("HTML/QuickForm/Renderer/Object.php");
  22.  
  23. /**
  24.  * QuickForm renderer for Flexy template engine, static version.
  25.  * 
  26.  * A static renderer for HTML_Quickform.  Makes a QuickFormFlexyObject
  27.  * from the form content suitable for use with a Flexy template
  28.  *
  29.  * Usage:
  30.  * $form =& new HTML_QuickForm('form', 'POST');
  31.  * $template =& new HTML_Template_Flexy();
  32.  * $renderer =& new HTML_QuickForm_Renderer_ObjectFlexy(&$template);
  33.  * $renderer->setHtmlTemplate("html.html");
  34.  * $renderer->setLabelTemplate("label.html");
  35.  * $form->accept($renderer);
  36.  * $view = new StdClass;
  37.  * $view->form = $renderer->toObject();
  38.  * $template->compile("mytemplate.html");
  39.  *
  40.  * Based on the code for HTML_QuickForm_Renderer_ArraySmarty
  41.  *
  42.  * @see QuickFormFlexyObject
  43.  * @access public
  44.  */
  45. {
  46.     /**
  47.      * HTML_Template_Flexy instance
  48.      * @var object $_flexy 
  49.      */
  50.     var $_flexy;
  51.  
  52.     /**
  53.      * Current element index
  54.      * @var integer $_elementIdx 
  55.      */
  56.     var $_elementIdx;
  57.  
  58.     /**
  59.      * The current element index inside a group
  60.      * @var integer $_groupElementIdx 
  61.      */
  62.     var $_groupElementIdx = 0;
  63.  
  64.     /**
  65.      * Name of template file for form html
  66.      * @var string $_html 
  67.      * @see     setRequiredTemplate()
  68.      */
  69.     var $_html '';
  70.  
  71.     /**
  72.      * Name of template file for form labels
  73.      * @var string $label 
  74.      * @see        setErrorTemplate()
  75.      */
  76.     var $label = '';
  77.  
  78.     /**
  79.      * Class of the element objects, so you can add your own
  80.      * element methods
  81.      * @var string $_elementType 
  82.      */
  83.     var $_elementType 'QuickformFlexyElement';
  84.  
  85.     /**
  86.      * Constructor
  87.      *
  88.      * @param $flexy object   HTML_Template_Flexy instance
  89.      * @public
  90.      */
  91.     function HTML_QuickForm_Renderer_ObjectFlexy(&$flexy)
  92.     {
  93.         $this->HTML_QuickForm_Renderer_Object(true);
  94.         $this->_obj = new QuickformFlexyForm();
  95.         $this->_flexy =$flexy;
  96.     // end constructor
  97.  
  98.     function renderHeader(&$header)
  99.     {
  100.         if($name $header->getName()) {
  101.             $this->_obj->header->$name $header->toHtml();
  102.         else {
  103.             $this->_obj->header[$this->_sectionCount$header->toHtml();
  104.         }
  105.         $this->_currentSection $this->_sectionCount++;
  106.     // end func renderHeader
  107.  
  108.     function startGroup(&$group$required$error)
  109.     {
  110.         parent::startGroup($group$required$error);
  111.         $this->_groupElementIdx = 1;
  112.     //end func startGroup
  113.  
  114.     /**
  115.      * Creates an object representing an element containing
  116.      * the key for storing this
  117.      *
  118.      * @access private
  119.      * @param element object     An HTML_QuickForm_element object
  120.      * @param required bool        Whether an element is required
  121.      * @param error string    Error associated with the element
  122.      * @return object 
  123.      */
  124.     function _elementToObject(&$element$required$error)
  125.     {
  126.         $ret = parent::_elementToObject($element$required$error);
  127.         if($ret->type == 'group'{
  128.             $ret->html = $element->toHtml();
  129.             unset($ret->elements);
  130.         }
  131.         if(!empty($this->_label)) {
  132.             $this->_renderLabel($ret);
  133.         }
  134.  
  135.         if(!empty($this->_html)) {
  136.             $this->_renderHtml($ret);
  137.             $ret->error = $error;
  138.         }
  139.  
  140.         // Create an element key from the name
  141.         if (false !== ($pos strpos($ret->name'[')) || is_object($this->_currentGroup)) {
  142.             if (!$pos{
  143.                 $keys '->{\'' str_replace(array('\\''\'')array('\\\\''\\\'')$ret->name'\'}';
  144.             else {
  145.                 $keys '->{\'' str_replace(
  146.                             array('\\''\'''['']')array('\\\\''\\\'''\'}->{\'''')
  147.                             $ret->name
  148.                         '\'}';
  149.             }
  150.             // special handling for elements in native groups
  151.             if (is_object($this->_currentGroup)) {
  152.                 // skip unnamed group items unless radios: no name -> no static access
  153.                 // identification: have the same key string as the parent group
  154.                 if ($this->_currentGroup->keys == $keys && 'radio' != $ret->type{
  155.                     return false;
  156.                 }
  157.                 // reduce string of keys by remove leading group keys
  158.                 if (0 === strpos($keys$this->_currentGroup->keys)) {
  159.                     $keys substr_replace($keys''0strlen($this->_currentGroup->keys));
  160.                 }
  161.             }
  162.         elseif (0 == strlen($ret->name)) {
  163.             $keys '->{\'element_' $this->_elementIdx '\'}';
  164.         else {
  165.             $keys '->{\'' str_replace(array('\\''\'')array('\\\\''\\\'')$ret->name'\'}';
  166.         }
  167.         // for radios: add extra key from value
  168.         if ('radio' == $ret->type && '[]' != substr($keys-2)) {
  169.             $keys .= '->{\'' str_replace(array('\\''\'')array('\\\\''\\\'')$ret->value'\'}';
  170.         }
  171.         $ret->keys = $keys;
  172.         $this->_elementIdx++;
  173.         return $ret;
  174.     }
  175.  
  176.     /**
  177.      * Stores an object representation of an element in the
  178.      * QuickformFormObject instance
  179.      *
  180.      * @access private
  181.      * @param elObj object  Object representation of an element
  182.      * @return void 
  183.      */
  184.     function _storeObject($elObj
  185.     {
  186.         if ($elObj{
  187.             $keys $elObj->keys;
  188.             unset($elObj->keys);
  189.             if(is_object($this->_currentGroup&& ('group' != $elObj->type)) {
  190.                 $code '$this->_currentGroup' $keys ' = $elObj;';
  191.             else {
  192.                 $code '$this->_obj' $keys ' = $elObj;';
  193.             }
  194.             eval($code);
  195.         }
  196.     }
  197.  
  198.     /**
  199.      * Set the filename of the template to render html elements.
  200.      * In your template, {html} is replaced by the unmodified html.
  201.      * If the element is required, {required} will be true.
  202.      * Eg.
  203.      * {if:error}
  204.      *   <font color="red" size="1">{error:h}</font><br />
  205.      * {end:}
  206.      * {html:h}
  207.      *
  208.      * @access public
  209.      * @param template string   Filename of template
  210.      * @return void 
  211.      */
  212.     function setHtmlTemplate($template)
  213.     {
  214.         $this->_html $template;
  215.     
  216.  
  217.     /**
  218.      * Set the filename of the template to render form labels
  219.      * In your template, {label} is replaced by the unmodified label.
  220.      * {error} will be set to the error, if any.  {required} will
  221.      * be true if this is a required field
  222.      * Eg.
  223.      * {if:required}
  224.      * <font color="orange" size="1">*</font>
  225.      * {end:}
  226.      * {label:h}
  227.      *
  228.      * @access public
  229.      * @param template string   Filename of template
  230.      * @return void 
  231.      */
  232.     function setLabelTemplate($template
  233.     {
  234.         $this->_label $template;
  235.     }
  236.  
  237.     function _renderLabel(&$ret)
  238.     {
  239.         $this->_flexy->compile($this->_label);
  240.         $ret->label = $this->_flexy->bufferedOutputObject($ret);
  241.     }
  242.  
  243.     function _renderHtml(&$ret)
  244.     {
  245.         $this->_flexy->compile($this->_html);
  246.         $ret->html = $this->_flexy->bufferedOutputObject($ret);
  247.     }
  248. // end class HTML_QuickForm_Renderer_ObjectFlexy
  249.  
  250. /**
  251.  * Adds nothing to QuickformForm, left for backwards compatibility
  252.  */
  253. {
  254. }
  255.  
  256. /**
  257.  * Adds nothing to QuickformElement, left for backwards compatibility
  258.  */
  259. {
  260. }
  261. ?>

Documentation generated on Mon, 11 Mar 2019 14:46:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.