Source for file AGridLayout.php

Documentation is available at AGridLayout.php

  1. <?php
  2. /**
  3.  * AGridLayout
  4.  *
  5.  * @package Alia
  6.  * @subpackage Layouts
  7.  */
  8.  
  9. /**
  10.  * Lays out the widgets in a grid
  11.  *
  12.  * @author Jordan Wambaugh <jordan@wambaugh.org>
  13.  * @package Alia
  14.  * @subpackage Layouts
  15.  */
  16. class AGridLayout extends ALayout
  17. {
  18.  
  19.     private $col=0;
  20.     private $rows=0;
  21.     
  22.     /**
  23.      * adds widgets to the layout.
  24.      *
  25.      * @param AWidget $widget the parent widget
  26.      * @param int $row the row (starting at 0)
  27.      * @param int $col the column (starting at 0)
  28.      * @param int|null$colspan Number of columns the widget spans. Optional.
  29.      */
  30.     public function addWidget(AWidget $widget$row,$col,$colspan=null){
  31.  
  32.         $row=(int)$row;
  33.         $col=(int)$col;
  34.         if($colspan){
  35.             $colspan=(int)$colspan;
  36.         }
  37.         $this->__widgets[$row][$col]['widget']=$widget;
  38.         $this->__widgets[$row][$col]['colspan']=$colspan;
  39.     }
  40.     
  41.     
  42.     
  43.     /**
  44.      * Renders the
  45.      *
  46.      * @return string 
  47.      */
  48.     public function render(){
  49.         //get the max number of columns
  50.         $max=0;
  51.         foreach ($this->__widgets as $row){
  52.             if(($x=max(array_keys($row)))>$max){
  53.                 $max $x;
  54.             }
  55.         }
  56.         $max++;
  57.         //render the table
  58.         $buffer="\n<table".$this->getAttributeHTML().">";
  59.         $rows=max(array_keys($this->__widgets))+1;
  60.         for($x=0;$x<$rows;$x++){
  61.             $buffer.= "\n<tr>";
  62.             for($y=0;$y $max;$y++){
  63.                 $buffer.="\n<td";
  64.                 //prevent annoying notice errors with this if
  65.                 if(isset($this->__widgets[$x][$y])){
  66.                     $buffer.=($span=$this->__widgets[$x][$y]['colspan']" colspan='$span'>">";
  67.                     if(is_object(($text=$this->__widgets[$x][$y]['widget'])))$buffer.=$text->render();
  68.                 }
  69.                 if ($span)$y+=($span-1);
  70.                 $buffer.="</td>";
  71.             }
  72.             $buffer.="\n</tr>";
  73.         }
  74.         $buffer.="\n</table>";
  75.         return $buffer;
  76.     }
  77.  
  78. // end of AGridLayout
  79. ?>

Documentation generated on Fri, 11 Jul 2008 13:28:39 -0400 by phpDocumentor 1.4.2