home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Table / Matrix / Filler / InC.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.8 KB  |  91 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. require_once 'HTML/Table/Matrix/Filler.php';
  4.  
  5. /**
  6.  * Fill inwards, clockwise.
  7.  *
  8.  * @author Arpad Ray <arpad@rajeczy.com>
  9.  * @package HTML_Table_Matrix
  10.  */
  11. class HTML_Table_Matrix_Filler_InC extends HTML_Table_Matrix_Filler {
  12.  
  13.     /**
  14.      * Number of columns to move towards the right for the next cell
  15.      *
  16.      * @type int
  17.      */
  18.     var $_right = 1;
  19.  
  20.     /**
  21.      * Number of rows to move downwards for the next cell
  22.      *
  23.      * @type int
  24.      */
  25.     var $_down = 0;
  26.  
  27.     /**
  28.      * Number of cells inwards for the current revolution
  29.      *
  30.      * @type int
  31.      */
  32.     var $_in = 0;
  33.     
  34.     /**
  35.      * Constructor
  36.      *
  37.      * @param Object $matrix Reference to the HTML_Table_Matrix instance we are
  38.      *                       filling data for.
  39.      * @param array $options Options for this Filler
  40.      * @return void
  41.      */
  42.     function HTML_Table_Matrix_Filler_InC(&$matrix, $options = false) {
  43.         $this->setOptions($options);
  44.         $this->matrix = $matrix;
  45.     }
  46.  
  47.     /**
  48.      * Get the next cell.
  49.      *
  50.      * @param int $index Where we're at in the data-set
  51.      * @return array 1-dimensional array in the form of (row, col) containing the
  52.      *               coordinates to put the data for this loop iteration
  53.      */
  54.     function next($index) {
  55.         if ($index == 0) {
  56.             $this->row = $this->matrix->_fillStartRow;
  57.             $this->col = $this->matrix->_fillStartCol;
  58.         } else {
  59.             $this->row += $this->_down;
  60.             $this->col += $this->_right;
  61.             if ($this->row == $this->matrix->_rows - $this->_in - 1
  62.                  && $this->row != $this->matrix->_fillStartRow + $this->_in) {
  63.                 // last row, revolution width != 1
  64.                 if ($this->col == $this->matrix->_cols - $this->_in - 1) {
  65.                     // last column
  66.                     $this->_right = -1;
  67.                     $this->_down = 0;
  68.                 } else if ($this->col == $this->matrix->_fillStartCol + $this->_in) {
  69.                     // first column
  70.                     $this->_right = 0;
  71.                     $this->_down = -1;
  72.                 }
  73.             } else if ($this->row == $this->matrix->_fillStartRow + $this->_in
  74.                  && $this->col == $this->matrix->_cols - $this->_in - 1) {
  75.                 // first row, last column
  76.                 $this->_right = 0;
  77.                 $this->_down = 1;
  78.             } else if ($this->col + $this->_right == $this->matrix->_fillStartCol + $this->_in
  79.                  && $this->row + $this->_down == $this->matrix->_fillStartRow + $this->_in) {
  80.                 // next cell would be the starting
  81.                 $this->_in++;
  82.                 $this->_right = 1;
  83.                 $this->_down = 0;
  84.             }
  85.         }
  86.         
  87.         return array($this->row, $this->col);
  88.     }
  89. }
  90. ?>
  91.