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

Source for file TableFragment.php

Documentation is available at TableFragment.php

  1. <?php
  2. /*
  3.  * Created on 04.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  4.  *
  5.  * PHP versions 5.2 or better.
  6.  *
  7.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  9.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  10.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  11.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  12.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  13.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  14.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  15.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  16.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  17.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18.  *
  19.  * This software consists of voluntary contributions made by many individuals
  20.  * and is licensed under the GPL. For more information please see
  21.  * <http://opendocumentphp.org>.
  22.  * 
  23.  * $Id: TableFragment.php 136 2007-03-02 18:02:29Z nmarkgraf $
  24.  */
  25. require_once 'OpenDocumentPHP/content/body/table/TableCell.php';
  26. require_once 'OpenDocumentPHP/util/Fragment.php';
  27. /**
  28.  * TableFragment class.
  29.  *  
  30.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  31.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  32.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  33.  * @version        $Revision: 136 $
  34.  * @package        OpenDocumentPHP
  35.  * @since         0.5.0 - 08.02.2007
  36.  */
  37. class TableFragment extends Fragment {
  38.     private $cells;
  39.     private $minx 9999999;
  40.     private $maxx 0;
  41.     private $miny 9999999;
  42.     private $maxy 0;
  43.     /**
  44.      * Constructor method.
  45.      * 
  46.      * @since         0.5.0 - 08.02.2007
  47.      */
  48.     function __construct($domFragment{
  49.         parent :: __construct($domFragment);
  50.         $this->root = $this->domFragment->createElementNS(self :: TABLE'table:table');
  51.         $this->cells array ();
  52.     }
  53.     /**
  54.      * 
  55.      * @access         public
  56.      * @since         0.5.0 - 08.02.2007
  57.      */
  58.     function setTableName($name{
  59.         $this->root->setAttributeNS(self :: TABLE'table:name'$name);
  60.     }
  61.     /**
  62.      * 
  63.      * @access         public
  64.      * @since         0.5.0 - 08.02.2007
  65.      */
  66.     function getCell($col$row{
  67.         $ret null;
  68.         if (isset ($this->cells[$row]&& isset ($this->cells[$row][$col])) {
  69.             $ret $this->cells[$row][$col];
  70.         else {
  71.             $ret new TableCell($this->domFragment$col$row);
  72.             $this->cells[$row][$col$ret;
  73.         }
  74.         return $ret;
  75.     }
  76.     /**
  77.      * 
  78.      * @access         public
  79.      * @since         0.5.0 - 08.02.2007
  80.      */
  81.     function setCellContent($content$col$row{
  82.         $tmp $this->getCell($col$row);
  83.         $tmp->setContent($content);
  84.     }
  85.     /**
  86.      * 
  87.      * @access         public
  88.      * @since         0.5.0 - 08.02.2007
  89.      */
  90.     private function includeCells({
  91.         $cells $this->cells;
  92.         ksort($cells);
  93.         $currentRow 0;
  94.         foreach ($this->cells as $row => $cols{
  95.             if ($currentRow $row -1{
  96.                 $tbRow $this->domFragment->createElementNS(self :: TABLE'table-row');
  97.                 $tbRow->setAttributeNS(self :: TABLE'table:number-rows-repeated'($row $currentRow -1));
  98.                 $tbCell $this->domFragment->createElementNS(self :: TABLE'table-cell');
  99.                 $tbCell->setAttributeNS(self :: TABLE'table:style-name''ce1');
  100.                 $tbRow->appendChild($tbCell);
  101.                 $this->root->appendChild($tbRow);
  102.             }
  103.             ksort($cols);
  104.             $currentCol 0;
  105.             $tbRow $this->domFragment->createElementNS(self :: TABLE'table-row');
  106.             foreach ($cols as $col => $cell{
  107.                 if ($currentCol $col -1{
  108.                     $tbCell $this->domFragment->createElementNS(self :: TABLE'table-cell');
  109.                     $tbCell->setAttributeNS(self :: TABLE'table:number-columns-repeated'($col $currentCol -1));
  110.                     $tbRow->appendChild($tbCell);
  111.                 }
  112.                 $currentCol $col;
  113.                 $tbRow->appendChild($cell->getDocumentFragment());
  114.             }
  115.             $this->root->appendChild($tbRow);
  116.             $currentRow $row;
  117.         }
  118.     }
  119.     /**
  120.      * 
  121.      * @access         public
  122.      * @since         0.5.0 - 08.02.2007
  123.      */
  124.     function getDocumentFragment({
  125.         $this->includeCells();
  126.         return $this->root;
  127.     }
  128. }
  129. ?>

Documentation generated on Tue, 12 Jun 2007 10:00:53 +0200 by phpDocumentor 1.3.2