[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/tags/form/ -> select.tag.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once 'limb/wact/src/tags/form/control.inc.php';
  11  
  12  /**

  13   * Compile time component for building runtime select components

  14   * @tag select

  15   * @runat_as WactFormTag

  16   * @suppress_attributes errorclass errorstyle displayname

  17   * @restrict_self_nesting

  18   * @runat client

  19   * @package wact
  20   * @version $Id: select.tag.php 5945 2007-06-06 08:31:43Z pachanga $
  21   */
  22  class WactSelectTag extends WactControlTag
  23  {
  24    function prepare()
  25    {
  26      if ($this->getBoolAttribute('multiple'))
  27      {
  28        $this->runtimeIncludeFile = 'limb/wact/src/components/form/WactSelectMultipleComponent.class.php';
  29        $this->runtimeComponentName = 'WactSelectMultipleComponent';
  30  
  31        // Repetition of ControlTag::prepare but required for special case

  32        // of SelectMultiple to provide meaningful error messages

  33        if (!$this->getBoolAttribute('name'))
  34        {
  35          if ( $this->getBoolAttribute('id') )
  36            $this->setAttribute('name',$this->getAttribute('id').'[]'); // Note - appends [] to id value

  37          else
  38            $this->raiseRequiredAttributeError('name');
  39        }
  40  
  41        if (!is_integer(strpos($this->getAttribute('name'), '[]')))
  42        {
  43          $this->raiseCompilerError('Array brackets "[]" required in name attribute, e.g. name="foo[]"',
  44                                    array('name' => $this->getAttribute('name')));
  45        }
  46      }
  47      else
  48      {
  49        $this->runtimeIncludeFile = 'limb/wact/src/components/form/WactSelectSingleComponent.class.php';
  50        $this->runtimeComponentName = 'WactSelectSingleComponent';
  51      }
  52  
  53      parent::prepare();
  54    }
  55  
  56    /**

  57     * Ignore the compiler time contents and generate the contents at run time.

  58     * @return void

  59     */
  60    function generateTagContent($code_writer)
  61    {
  62      $writer = new WactCodeWriter();
  63      foreach($this->getChildren() as $option_tag)
  64      {
  65        if(!is_a($option_tag, 'WactCompilerTag'))
  66          continue;
  67  
  68        $value = $option_tag->getAttribute('value');
  69        $prepend = $option_tag->getBoolAttribute('prepend');
  70        $option_tag->generateNow($writer);
  71        $text = addslashes($writer->getCode());
  72        $writer->reset();
  73        if($prepend)
  74          $code_writer->writePHP($this->getComponentRefCode() . '->prependToChoices("'. $value .'","'. $text.'");');
  75        else
  76          $code_writer->writePHP($this->getComponentRefCode() . '->addToChoices("'. $value .'","'. $text.'");');
  77  
  78        if($option_tag->hasAttribute('selected'))
  79          $code_writer->writePHP($this->getComponentRefCode() . '->addToDefaultSelection("'. $value .'");');
  80      }
  81  
  82      $code_writer->writePHP($this->getComponentRefCode() . '->renderContents();');
  83    }
  84  }
  85  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7