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

Source for file TableFragment.php

Documentation is available at TableFragment.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 04. Jan. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * TableFragment class file.
  11.  * 
  12.  * PHP versions 5
  13.  *   
  14.  * LICENSE:
  15.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  *
  27.  * This software consists of voluntary contributions made by many individuals
  28.  * and is licensed under the GPL. For more information please see
  29.  * <http://opendocumentphp.org>.
  30.  * 
  31.  * $Id: TableFragment.php 256 2007-08-01 14:16:10Z nmarkgraf $
  32.  * 
  33.  * @category    File Formats
  34.  * @package     OpenDocumentPHP
  35.  * @subpackage  content_body_table
  36.  * @author      Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  37.  * @copyright   Copyright in 2006, 2007 by The OpenDocumentPHP Team
  38.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  39.  * @version     SVN: $Id: TableFragment.php 256 2007-08-01 14:16:10Z nmarkgraf $
  40.  * @link        http://opendocumentphp.org
  41.  * @since       0.5.0 - 08. Feb. 2007
  42.  */
  43.  
  44. /**
  45.  *
  46.  */
  47. require_once 'OpenDocumentPHP/content/body/table/TableCell.php';
  48. require_once 'OpenDocumentPHP/util/ODPElement.php';
  49.  
  50. /**
  51.  * TableFragment class.
  52.  * 
  53.  * @category    File Formats
  54.  * @package     OpenDocumentPHP
  55.  * @subpackage  content_body_table
  56.  * @author      Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  57.  * @copyright   Copyright in 2006, 2007 by The OpenDocumentPHP Team
  58.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  59.  * @version     Release: @package_version@
  60.  * @link        http://opendocumentphp.org
  61.  * @since       0.5.0 - 08. Feb. 2007
  62.  */
  63. class TableFragment extends ODPElement
  64. {
  65.     /**
  66.      * @access      private
  67.      * @since       0.5.0 - 08. Feb. 2007
  68.      */
  69.     private $cells;
  70.     
  71.     /**
  72.      * @access      private
  73.      * @since       0.5.0 - 08. Feb. 2007
  74.      */
  75.     private $minx 9999999;
  76.     
  77.     /**
  78.      * @access      private
  79.      * @since       0.5.0 - 08. Feb. 2007
  80.      */
  81.     private $maxx 0;
  82.     
  83.     /**
  84.      * @access      private
  85.      * @since       0.5.0 - 08. Feb. 2007
  86.      */
  87.     private $miny 9999999;
  88.     
  89.     /**
  90.      * @access      private
  91.      * @since       0.5.0 - 08. Feb. 2007
  92.      */
  93.     private $maxy 0;
  94.     
  95.     /**
  96.      * Constructor method.
  97.      * 
  98.      * @since       0.5.0 - 08. Feb. 2007
  99.      */
  100.     function __construct($elem=null
  101.     {         
  102.         if (is_null($elem)) {
  103.            parent::__construct('table:table'''self::TABLE);
  104.         else {
  105.            parent::__construct($elem);         
  106.         }
  107.         $this->cells array ();
  108.     }
  109.     
  110.     /**
  111.      * 
  112.      * @access      public
  113.      * @since       0.5.0 - 08. Feb. 2007
  114.      */
  115.     function setTableName($name{
  116.         $this->setAttributeNS(self :: TABLE'table:name'$name);
  117.     }
  118.     
  119.     /**
  120.      * 
  121.      * @access      public
  122.      * @since       0.5.3 - 23. Jul. 2007
  123.      */
  124.     function getTableName($name{
  125.         return $this->getAttributeNS(self :: TABLE'name');
  126.     }
  127.     
  128.     /**
  129.      * 
  130.      * @access      public
  131.      * @since       0.5.3 - 23. Jul. 2007
  132.      */
  133.     function setName($name{
  134.         $this->setAttributeNS(self :: TABLE'table:name'$name);
  135.     }
  136.     
  137.     /**
  138.      * 
  139.      * @access      public
  140.      * @since       0.5.3 - 23. Jul. 2007
  141.      */
  142.     function getName($name{
  143.         return $this->getAttributeNS(self :: TABLE'name');
  144.     }
  145.     
  146.     /**
  147.      * 
  148.      * @access      public
  149.      * @since       0.5.3 - 23. Jul. 2007
  150.      */
  151.     function setStyleName($name{
  152.         $this->setAttributeNS(self :: TABLE'table:name'$name);
  153.     }
  154.     
  155.     /**
  156.      * 
  157.      * @access      public
  158.      * @since       0.5.3 - 23. Jul. 2007
  159.      */
  160.     function getStyleName($name{
  161.         return $this->getAttributeNS(self :: TABLE'name');
  162.     }
  163.  
  164.     /**
  165.      * 
  166.      * @access      public
  167.      * @since       0.5.3 - 23. Jul. 2007
  168.      */
  169.     function isProtected()
  170.     {
  171.         $ret false;
  172.         if ($this->hasAttributeNS(self::TABLE'protected')) {
  173.             $ret ($this->getAttributeNS(self::TABLE'protected'=== 'true');
  174.         }
  175.         return $ret;
  176.     }
  177.     
  178.     /**
  179.      * 
  180.      * @access      public
  181.      * @since       0.5.3 - 23. Jul. 2007
  182.      */
  183.     function getProtectionPassword()
  184.     {
  185.         $ret false;
  186.         if ($this->isProtected()) {
  187.             $ret $this->getAttributeNS(self::TABLE'protection-key');
  188.         }
  189.         return $ret;
  190.     }
  191.     
  192.     /**
  193.      * 
  194.      * @access      public
  195.      * @param       bool    $status 
  196.      * @param       string  $password 
  197.      * @since       0.5.3 - 23. Jul. 2007
  198.      */
  199.     function setProtection($status$password=null)
  200.     {
  201.         $ret true;
  202.         if ($status{
  203.             if (is_string($password)) {
  204.                 $this->setAttributeNS(self::TABLE'table:protected''true');
  205.                 $this->setAttributeNS(self::TABLE'table:pretection-key'$password);        
  206.             else {
  207.                 $ret false;
  208.             }
  209.         else {
  210.                 $this->setAttributeNS(self::TABLE'table:protected''false');                
  211.         }
  212.         return $ret;
  213.     }
  214.     
  215.     /**
  216.      * 
  217.      * @access      public
  218.      * @since       0.5.0 - 08. Feb. 2007
  219.      */
  220.     function getCell($col$row{
  221.         $ret null;
  222.         if (isset ($this->cells[$row]&& isset ($this->cells[$row][$col])) {
  223.             $ret $this->cells[$row][$col];
  224.         else {
  225.             $ret new TableCell(null$col$row);
  226.             $this->cells[$row][$col$ret;
  227.         }
  228.         return $ret;
  229.     }
  230.     
  231.     /**
  232.      * 
  233.      * @access      public
  234.      * @since       0.5.0 - 08. Feb. 2007
  235.      * @return      TableCell 
  236.      */
  237.     function setCellContent($content$col$row{
  238.         $tmp $this->getCell($col$row);
  239.         $tmp->setContent($content);
  240.         return $tmp;
  241.     }
  242.     
  243.     /**
  244.      * 
  245.      * @access      public
  246.      * @since       0.5.0 - 08. Feb. 2007
  247.      */
  248.     private function includeCells({
  249.         $cells $this->cells;
  250.         ksort($cells);
  251.         $currentRow 0;
  252.         foreach ($this->cells as $row => $cols{
  253.             if ($currentRow $row -1{
  254.                 $tbRow $this->documentElement->createElementNS(self :: TABLE'table-row');
  255.                 $tbRow->setAttributeNS(self :: TABLE'table:number-rows-repeated'($row $currentRow -1));
  256.                 $tbCell $this->documentElement->createElementNS(self :: TABLE'table-cell');
  257.                 $tbCell->setAttributeNS(self :: TABLE'table:style-name''ce1');
  258.                 $tbRow->appendChild($tbCell);
  259.                 $this->appendChild($tbRow);
  260.             }
  261.             ksort($cols);
  262.             $currentCol 0;
  263.             $tbRow $this->documentElement->createElementNS(self :: TABLE'table-row');
  264.             foreach ($cols as $col => $cell{
  265.                 if ($currentCol $col -1{
  266.                     $tbCell $this->documentElement->createElementNS(self :: TABLE'table-cell');
  267.                     $tbCell->setAttributeNS(self :: TABLE'table:number-columns-repeated'($col $currentCol -1));
  268.                     $tbRow->appendChild($tbCell);
  269.                 }
  270.                 $currentCol $col;
  271.                 $tbRow->appendChild($cell->getDocumentFragment());
  272.             }
  273.             $this->appendChild($tbRow);
  274.             $currentRow $row;
  275.         }
  276.     }
  277.     
  278.     /**
  279.      * 
  280.      * @access      public
  281.      * @since       0.5.0 - 08. Feb. 2007
  282.      */
  283.     function getDocumentFragment({
  284.         $this->includeCells();
  285.         return $this;
  286.     }   
  287. }
  288. ?>

Documentation generated on Wed, 18 Jun 2008 06:33:10 +0200 by phpDocumentor 1.3.2