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

Source for file Button.php

Documentation is available at Button.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 Table
  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: Button.php 27 2007-07-19 18:47:54Z lfrost $
  25.  */
  26.  
  27. /**
  28.  * HTML Table Button class
  29.  *
  30.  * This class is probably not useful directly.  It could be an inner class
  31.  * of Html_Table, if PHP supported inner classes.
  32.  *
  33.  * @category Cnz
  34.  * @package Cnz_Html
  35.  * @subpackage Table
  36.  */
  37. {
  38.     const DEFAULT_METHOD        = 'post';
  39.  
  40.     /**#@+ @var array */
  41.     private $paramArray        array();
  42.     private $row            array();
  43.     /**#@-*/
  44.  
  45.     /**#@+ @var string */
  46.     private $action            NULL;
  47.     private $label            NULL;
  48.     private $method            self::DEFAULT_METHOD;
  49.     private $value            NULL;
  50.     /**#@-*/
  51.  
  52.     /* Getters/Setters ===================================================*/
  53.  
  54.     /** @return string Name */
  55.     public function getName()
  56.     {
  57.         return $this->name;
  58.     }
  59.  
  60.     /**
  61.      * @param  array $row Row of data
  62.      * @return void 
  63.      */
  64.     public function setRow(array $row)
  65.     {
  66.         $this->row $row;
  67.         return;
  68.     }
  69.  
  70.     /* Methods ===========================================================*/
  71.  
  72.     /**
  73. /**
  74.      * Option fields:
  75.      *   none
  76.      *
  77.      * Configuration fields:
  78.      *   action   Form action for button press
  79.      *   label    Button label
  80.      *   method   Form method for button press
  81.      *   param    Parameter to pass with button press
  82.      *
  83.      * @param  array       $options Options
  84.      * @param  Zend_Config $config  Configuration
  85.      */
  86.     public function __construct(array $options array()Zend_Config $config NULL)
  87.     {
  88.         parent::__construct($options);
  89.  
  90.         // Process configuration.
  91.         if (isset($config->action)) $this->action $config->action;
  92.         if (isset($config->label)) $this->label $config->label;
  93.         if (isset($config->method)) $this->method $config->method;
  94.         if (isset($config->param)) $this->paramArray Cnz_Html::listToArray($config->param);
  95.         return;
  96.     }
  97.  
  98.     /**
  99.      * @param  string $style Value for outermost style attribute
  100.      * @return void 
  101.      */
  102.     public function display($style NULL)
  103.     {
  104.         $is Cnz_Html::getIndentString();
  105.         $indent Cnz_Html::indentGenerate();
  106.  
  107.         if ($this->action[0== ':')
  108.         {
  109.             $column substr($this->action1);
  110.             if (empty($this->row[$column]))
  111.             {
  112.                 return;
  113.             }
  114.             $action $this->row[$column];
  115.         }
  116.         else
  117.         {
  118.             $action $this->action;
  119.         }
  120.  
  121.         if ($this->method == 'post')
  122.         {
  123.             echo $indent$is$is'<form action = "'$action'" class = "'$this->genStyles('button')'" method = "'$this->method'">';
  124.             foreach ($this->paramArray as $src => $target)
  125.             {
  126.                 if (empty($target)) $target $src;
  127.                 echo '<input name = "'$target'" type = "hidden" value = "'$this->row[$src]'"/>';
  128.             }
  129.             echo '<button class = "'$this->genStyles()'" type = "submit">'$this->label'</button>';
  130.             echo '</form>'"\n";
  131.         }
  132.         else
  133.         {
  134.             echo $indent'<a href = "'$action;
  135.             $count 0;
  136.             foreach ($this->paramArray as $src => $target)
  137.             {
  138.                 if (empty($target)) $target $src;
  139.                 echo $count == '?' '&amp;';
  140.                 echo $target'='$this->row[$src];
  141.                 $count++;
  142.             }
  143.             echo '">';
  144.             echo '<button class = "'$this->genStyles()'" type = "submit">'$this->label'</button>';
  145.             echo '</a>'"\n";
  146.         }
  147.  
  148.         return;
  149.     }
  150. }

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