[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/tags/form/ -> select_date.tag.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2004 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TAG
   8  * @version $Id: select_date.tag.php,v 1.11 2004/11/21 02:42:30 jeffmoore Exp $
   9  */
  10  
  11  /**
  12  * Includes
  13  */
  14  require_once WACT_ROOT . 'template/tags/form/select.tag.php';
  15  require_once WACT_ROOT . 'template/tags/core/block.tag.php';
  16  
  17  /**
  18  * Register the tags
  19  */
  20  $taginfo =& new TagInfo('form:selectdate', 'SelectDateTag');
  21  $taginfo->setCompilerAttributes(array('errorclass', 'errorstyle', 'displayname'));
  22  $taginfo->setKnownParent('FormTag');
  23  TagDictionary::registerTag($taginfo, __FILE__);
  24  
  25  $taginfo =& new TagInfo('form:selectyear', 'SelectYearTag');
  26  $taginfo->setCompilerAttributes(array('errorclass', 'errorstyle', 'displayname'));
  27  $taginfo->setKnownParent('FormTag');
  28  TagDictionary::registerTag($taginfo, __FILE__);
  29  
  30  $taginfo =& new TagInfo('form:selectmonth', 'SelectMonthTag');
  31  $taginfo->setCompilerAttributes(array('errorclass', 'errorstyle', 'displayname'));
  32  $taginfo->setKnownParent('FormTag');
  33  TagDictionary::registerTag($taginfo, __FILE__);
  34  
  35  $taginfo =& new TagInfo('form:selectday', 'SelectDayTag');
  36  $taginfo->setCompilerAttributes(array('errorclass', 'errorstyle', 'displayname'));
  37  $taginfo->setKnownParent('FormTag');
  38  TagDictionary::registerTag($taginfo, __FILE__);
  39  
  40  /**
  41   * Compile time component for building runtime select date components
  42   * @see http://wact.sourceforge.net/index.php/SelectDateTag
  43   * @access protected
  44   * @package WACT_TAG
  45   */
  46  class SelectYearTag extends SelectTag
  47  {
  48      /**
  49       * File to include at runtime
  50       * @var string path to runtime component relative to WACT_ROOT
  51       * @access private
  52       */
  53      var $runtimeIncludeFile = 'template/components/form/select_date.inc.php';
  54  
  55      /**
  56       * Name of runtime component class
  57       * @var string
  58       * @access private
  59       */
  60      var $runtimeComponentName = 'FormSelectDateComponent';
  61  
  62      /**
  63       * @var object
  64       * @access protected
  65       */
  66      var $selectYearObjectRefCode;
  67  
  68      /**
  69       * @var object
  70       * @access protected
  71       */
  72      var $selComponent;
  73  
  74      /**
  75       * @param CodeWriter
  76       * @return void
  77        * @access protected
  78       */
  79  	function preGenerate(&$code) {
  80          if ($this->hasAttribute('name')) {
  81              $this->removeAttribute('name');
  82          }
  83          $code->writeHTML('<select name="');
  84          $code->writePHP('echo '.$this->selComponent.'->groupName;');
  85          $code->writePHP('if ('.$this->selComponent.'->asArray)');
  86          $code->writePHP('{ echo "[Year]"; } else { echo "_Year"; }');
  87          $code->writeHTML('"');
  88          $this->generateAttributeList($code, array('name', 'groupName', 'asArray'));
  89          $code->writeHTML('>');
  90      }
  91  
  92      /**
  93       * @param CodeWriter
  94       * @return void
  95        * @access protected
  96       */
  97  	function postGenerate(&$code) {
  98          $code->writeHTML('</select>');
  99      }
 100  
 101      /**
 102       * @param CodeWriter
 103       * @return void
 104       * @access protected
 105       */
 106  	function generateContents(&$code)
 107      {
 108          $code->writePHP('$'.$this->selectYearObjectRefCode.'->renderContents();');
 109      }
 110  }
 111  
 112  //--------------------------------------------------------------------------------
 113  
 114  /**
 115   * Compile time component for building runtime select date components
 116   * @see http://wact.sourceforge.net/index.php/SelectDateTag
 117   * @access protected
 118   * @package WACT_TAG
 119   */
 120  class SelectMonthTag extends SelectTag
 121  {
 122      /**
 123       * File to include at runtime
 124       * @var string path to runtime component relative to WACT_ROOT
 125       * @access private
 126       */
 127      var $runtimeIncludeFile = 'template/components/form/select_date.inc.php';
 128  
 129      /**
 130       * Name of runtime component class
 131       * @var string
 132       * @access private
 133       */
 134      var $runtimeComponentName = 'FormSelectDateComponent';
 135  
 136      /**
 137       * @var object
 138       * @access protected
 139       */
 140      var $selectMonthObjectRefCode;
 141  
 142      /**
 143       * @var object
 144       * @access protected
 145       */
 146      var $selComponent;
 147  
 148      /**
 149       * @param CodeWriter
 150       * @return void
 151        * @access protected
 152       */
 153  	function preGenerate(&$code)
 154      {
 155          if ($this->hasAttribute('name')) {
 156              $this->removeAttribute('name');
 157          }
 158  
 159          $code->writeHTML('<select name="');
 160          $code->writePHP('echo '.$this->selComponent.'->groupName;');
 161          $code->writePHP('if ('.$this->selComponent.'->asArray)');
 162          $code->writePHP('{ echo "[Month]"; } else { echo "_Month"; }');
 163          $code->writeHTML('"');
 164          $this->generateAttributeList($code, array('name', 'groupName', 'asArray', 'format'));
 165          $code->writeHTML('>');
 166      }
 167  
 168      /**
 169       * @param CodeWriter
 170       * @return void
 171        * @access protected
 172       */
 173  	function postGenerate(&$code) {
 174          $code->writeHTML('</select>');
 175      }
 176  
 177      /**
 178       * @param CodeWriter
 179       * @return void
 180       * @access protected
 181       */
 182  	function generateContents(&$code)
 183      {
 184          $format = ($this->hasAttribute('format') ? $this->getAttribute('format') : 'long');
 185          $code->writePHP('$'.$this->selectMonthObjectRefCode.'->setFormat("'.$format.'");');
 186  
 187          //$value_format = ($this->hasAttribute('value_format') ? $this->getAttribute('value_format') : 'numeric');
 188          //$code->writePHP('$'.$this->selectMonthObjectRefCode.'->setValueFormat("'.$value_format.'");');
 189  
 190          $code->writePHP('$'.$this->selectMonthObjectRefCode.'->fillChoices();');
 191          $code->writePHP('$'.$this->selectMonthObjectRefCode.'->renderContents();');
 192      }
 193  }
 194  
 195  //--------------------------------------------------------------------------------
 196  
 197  /**
 198   * Compile time component for building runtime select date components
 199   * @see http://wact.sourceforge.net/index.php/SelectDateTag
 200   * @access protected
 201   * @package WACT_TAG
 202   */
 203  class SelectDayTag extends SelectTag
 204  {
 205      /**
 206       * File to include at runtime
 207       * @var string path to runtime component relative to WACT_ROOT
 208       * @access private
 209       */
 210      var $runtimeIncludeFile = 'template/components/form/select_date.inc.php';
 211  
 212      /**
 213       * Name of runtime component class
 214       * @var string
 215       * @access private
 216       */
 217      var $runtimeComponentName = 'FormSelectDateComponent';
 218  
 219      /**
 220       * @var object
 221       * @access protected
 222       */
 223      var $selectDayObjectRefCode;
 224  
 225      /**
 226       * @var object
 227       * @access protected
 228       */
 229      var $selComponent;
 230  
 231      /**
 232       * @param CodeWriter
 233       * @return void
 234        * @access protected
 235       */
 236  	function preGenerate(&$code)
 237      {
 238          //discard
 239          if ($this->hasAttribute('name')) {
 240              $this->removeAttribute('name');
 241          }
 242          $code->writeHTML('<select name="');
 243          $code->writePHP('echo '.$this->selComponent.'->groupName;');
 244          $code->writePHP('if ('.$this->selComponent.'->asArray)');
 245          $code->writePHP('{ echo "[Day]"; } else { echo "_Day"; }');
 246          $code->writeHTML('"');
 247          $this->generateAttributeList($code, array('name', 'groupName'));
 248          $code->writeHTML('>');
 249      }
 250  
 251      /**
 252       * @param CodeWriter
 253       * @return void
 254        * @access protected
 255       */
 256  	function postGenerate(&$code) {
 257          $code->writeHTML('</select>');
 258      }
 259  
 260      /**
 261       * @param CodeWriter
 262       * @return void
 263       * @access protected
 264       */
 265  	function generateContents(&$code)
 266      {
 267          $code->writePHP('$'.$this->selectDayObjectRefCode.'->renderContents();');
 268      }
 269  }
 270  
 271  //--------------------------------------------------------------------------------
 272  
 273  /**
 274   * Compile time component for building runtime select date components
 275   * @see http://wact.sourceforge.net/index.php/SelectDateTag
 276   * @access protected
 277   * @package WACT_TAG
 278   */
 279  class SelectDateTag extends CoreBlockTag  //ControlTag
 280  {
 281      /**
 282        * File to include at runtime
 283       * @var string path to runtime component relative to WACT_ROOT
 284       * @access private
 285       */
 286      var $runtimeIncludeFile = 'template/components/form/select_date.inc.php';
 287  
 288      /**
 289       * Name of runtime component class
 290       * @var string
 291       * @access private
 292       */
 293      var $runtimeComponentName = 'FormSelectDateComponent';
 294  
 295      /**
 296       * @param CodeWriter
 297       * @return void
 298       * @access protected
 299       */
 300      function generateYear(&$code)
 301      {
 302          $selectYearObjectRefCode  = getNewServerId();
 303          $SelectYear = & $this->findChildByClass('SelectYearTag');
 304          $SelectYear->selComponent = $this->getComponentRefCode();
 305          $SelectYear->selectYearObjectRefCode = $selectYearObjectRefCode;
 306  
 307          $SelectYear->setAttribute('groupName', $this->getAttribute('name'));
 308  
 309          $code->writePHP($this->getComponentRefCode() . '->prepareYear();');
 310  
 311          $code->writePHP('$'. $selectYearObjectRefCode . '='.
 312              $this->getComponentRefCode() . '->getYear();');
 313  
 314          $SelectYear->preGenerate($code);
 315          $SelectYear->generateContents($code);
 316          $SelectYear->postGenerate($code);
 317      }
 318  
 319      /**
 320       * @param CodeWriter
 321       * @return void
 322       * @access protected
 323       */
 324      function generateMonth(&$code)
 325      {
 326          $selectMonthObjectRefCode = getNewServerId();
 327          $SelectMonth = & $this->findChildByClass('SelectMonthTag');
 328          $SelectMonth->selComponent = $this->getComponentRefCode();
 329          $SelectMonth->selectMonthObjectRefCode = $selectMonthObjectRefCode;
 330  
 331          $SelectMonth->setAttribute('groupName', $this->getAttribute('name'));
 332  
 333          $code->writePHP($this->getComponentRefCode() . '->prepareMonth();');
 334          $code->writePHP('$'. $selectMonthObjectRefCode . '='.
 335              $this->getComponentRefCode() . '->getMonth();');
 336  
 337          $SelectMonth->preGenerate($code);
 338          $SelectMonth->generateContents($code);
 339          $SelectMonth->postGenerate($code);
 340      }
 341  
 342      /**
 343       * @param CodeWriter
 344       * @return void
 345       * @access protected
 346       */
 347      function generateDay(&$code)
 348      {
 349          $selectDayObjectRefCode = getNewServerId();
 350          $SelectDay = & $this->findChildByClass('SelectDayTag');
 351          $SelectDay->selComponent = $this->getComponentRefCode();
 352          $SelectDay->selectDayObjectRefCode = $selectDayObjectRefCode;
 353  
 354          $SelectDay->setAttribute('groupName', $this->getAttribute('name'));
 355  
 356          $code->writePHP($this->getComponentRefCode() . '->prepareDay();');
 357  
 358          $code->writePHP('$'. $selectDayObjectRefCode . '='.
 359              $this->getComponentRefCode() . '->getDay();');
 360  
 361          $SelectDay->preGenerate($code);
 362          $SelectDay->generateContents($code);
 363          $SelectDay->postGenerate($code);
 364      }
 365  
 366      /**
 367       * @param CodeWriter
 368       * @return void
 369       * @access protected
 370       */
 371  	function generateContents(&$code)
 372      {
 373          $functionMap = array(
 374              'selectyeartag'  => 'generateYear',
 375              'selectmonthtag' => 'generateMonth',
 376              'selectdaytag'   => 'generateDay'
 377          );
 378  
 379          $code->writePHP($this->getComponentRefCode() . '->setGroupName("'.$this->getAttribute('name').'");');
 380          $code->writePHP($this->getComponentRefCode() . '->setAsArray();');
 381  
 382          foreach ($this->children as $key => $child) {
 383              $childClass = strtolower(get_class($child));
 384              if (in_array($childClass, array_keys($functionMap))) {
 385                  $this->$functionMap[$childClass]($code);
 386              } else {
 387                  $this->children[$key]->generate($code);
 388              }
 389          }
 390      }
 391  }
 392  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5