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

Source for file Abstract.php

Documentation is available at Abstract.php

  1. <?php
  2. /**
  3.  * CNZ Framework
  4.  *
  5.  * A Framework for Creating and Using Complex Web Elements
  6.  *
  7.  * The purpose of this framework is to provide a library of high-level objects
  8.  * to facilitate common HTML coding tasks, such as menus, tables, and forms.
  9.  * The intent is to reduce repetitive HTML coding as much as possible, replacing
  10.  * it with a combination of configuration files and style sheets with
  11.  * standardized naming conventions.
  12.  *
  13.  * This framework is built on and requires the
  14.  * {@link http://framework.zend.com/ Zend Framework}.
  15.  *
  16.  * @category   Cnz
  17.  * @package    Cnz_Html
  18.  * @subpackage Form
  19.  *
  20.  * @author    Lyle Frost <lfrost@cnz.com>
  21.  * @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
  22.  * @filesource
  23.  * @license   http://www.citadelnetwork.com/license/cnzframework New BSD License
  24.  * @version   $Id: Abstract.php 27 2007-07-19 18:47:54Z lfrost $
  25.  */
  26.  
  27. /**
  28.  * Required classes.
  29.  *
  30.  * @ignore
  31.  */
  32. Zend_Loader::loadClass('Cnz_Html_Element');
  33. Zend_Loader::loadClass('Cnz_Html_Form_Checkbox');
  34. Zend_Loader::loadClass('Cnz_Html_Form_File');
  35. Zend_Loader::loadClass('Cnz_Html_Form_Group');
  36. Zend_Loader::loadClass('Cnz_Html_Form_Hidden');
  37. Zend_Loader::loadClass('Cnz_Html_Form_Password');
  38. Zend_Loader::loadClass('Cnz_Html_Form_Radio');
  39. Zend_Loader::loadClass('Cnz_Html_Form_Select');
  40. Zend_Loader::loadClass('Cnz_Html_Form_Text');
  41. Zend_Loader::loadClass('Cnz_Html_Form_Textarea');
  42.  
  43. /**
  44.  * HTML Form Abstract class
  45.  *
  46.  * Abstract base class for forms.
  47.  *
  48.  * @category   Cnz
  49.  * @package    Cnz_Html
  50.  * @subpackage Form
  51.  */
  52. abstract class Cnz_Html_Form_Abstract extends Cnz_Html_Element
  53. {
  54.     const HAS_CONFIG    = true;
  55.  
  56.     /**#@+ @var array */
  57.     private $data        NULL;
  58.     private    $defaultArray    array();
  59.     private    $itemArray    NULL;
  60.     /**#@-*/
  61.  
  62.     /**#@+ @var boolean */
  63.     protected $fileFlag    = false;
  64.     /**#@-*/
  65.  
  66.     /** @var Zend_Db_Table_Row_Abstract */
  67.     protected $row        = NULL;
  68.  
  69.     /* Methods ===========================================================*/
  70.  
  71.     /**
  72.      * Option fields:
  73.      *   default  Associative array containing default field values
  74.      *   row      Zend_Db_Table_Row containing data for this form
  75.      *
  76.      * @param  array       $options Options
  77.      * @param  Zend_Config $config  Configuration
  78.      */
  79.     public function __construct(array $options array())
  80.     {
  81.         parent::__construct($options);
  82.  
  83.         if (isset($options['default'])) $this->defaultArray $options['default'];
  84.         if (isset($options['row'])) $this->row = $options['row'];
  85.  
  86.         // Create items.
  87.         $i 0;
  88.         if (isset($this->config->item))
  89.         {
  90.             for ($this->config->item->rewind()$this->config->item->valid()$this->config->item->next())
  91.             {
  92.                 $type =  ucfirst(strtolower($this->config->item->current()->type));
  93.                 if ($type == 'File'$this->fileFlag = true;
  94.                 $className 'Cnz_Html_Form_' $type;
  95.                 $options['name'$this->config->item->key();
  96.                 if (isset($this->defaultArray[$options['name']]))
  97.                 {
  98.                     $options['initial'$this->defaultArray[$options['name']];
  99.                 }
  100.                 elseif (is_object($this->row&& isset($this->row->$options['name']))
  101.                 {
  102.                     $options['initial'$this->row->$options['name'];
  103.                 }
  104.                 else unset($options['initial']);
  105.                 $this->itemArray[$inew $className($options$this->config->item->current());
  106.                 if ($this->itemArray[$iinstanceof $this)
  107.                 {
  108.                     if ($this->itemArray[$i].hasFile()) $this->fileFlag = true;
  109.                 }
  110.                 $i++;
  111.             }
  112.         }
  113.  
  114.         return;
  115.     }
  116.  
  117.     /**
  118.      * @return boolean Has a file field
  119.      */
  120.     public function hasFile()
  121.     {
  122.         return $this->fileFlag;
  123.     }
  124.  
  125.     /**
  126.      * @param  string $style Value for outermost style attribute
  127.      * @return void 
  128.      */
  129.     public function display($style NULL)
  130.     {
  131.         $count count($this->itemArray);
  132.         for ($i 0$i $count$i++)
  133.         {
  134.             $this->itemArray[$i]->display($style);
  135.             // IE hack
  136.             if (!Cnz_Html::isXhtml(&& !$this->itemArray[$iinstanceof Cnz_Html_Form_Hiddenecho '<br>';
  137.         }
  138.         return;
  139.     }
  140.  
  141.     /**
  142.      * This function returns a string formatted for display or submission by
  143.      * mail.
  144.      *
  145.      * @param  array  $data Form data
  146.      * @return string 
  147.      */
  148.     public function submitString(array $data NULL)
  149.     {
  150.         $result '';
  151.         $count count($this->itemArray);
  152.         for ($i 0$i $count$i++)
  153.         {
  154.             $result .= $this->itemArray[$i]->submitString($data);
  155.         }
  156.         return $result;
  157.     }
  158. }

Documentation generated on Thu, 19 Jul 2007 15:01:55 -0400 by phpDocumentor 1.4.0RC2