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

Source for file Borders.php

Documentation is available at Borders.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Style
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** PHPExcel_Style_Border */
  30. require_once 'PHPExcel/Style/Border.php';
  31.  
  32. /** PHPExcel_IComparable */
  33. require_once 'PHPExcel/IComparable.php';
  34.  
  35.  
  36. /**
  37.  * PHPExcel_Style_Borders
  38.  *
  39.  * @category   PHPExcel
  40.  * @package    PHPExcel_Style
  41.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  42.  */
  43. class PHPExcel_Style_Borders implements PHPExcel_IComparable
  44. {
  45.     /* Diagonal directions */
  46.     const DIAGONAL_NONE        0;
  47.     const DIAGONAL_UP        1;
  48.     const DIAGONAL_DOWN        2;
  49.     
  50.     /**
  51.      * Left
  52.      *
  53.      * @var PHPExcel_Style_Border 
  54.      */
  55.     private $_left;
  56.     
  57.     /**
  58.      * Right
  59.      *
  60.      * @var PHPExcel_Style_Border 
  61.      */
  62.     private $_right;
  63.     
  64.     /**
  65.      * Top
  66.      *
  67.      * @var PHPExcel_Style_Border 
  68.      */
  69.     private $_top;
  70.     
  71.     /**
  72.      * Bottom
  73.      *
  74.      * @var PHPExcel_Style_Border 
  75.      */
  76.     private $_bottom;
  77.     
  78.     /**
  79.      * Diagonal
  80.      *
  81.      * @var PHPExcel_Style_Border 
  82.      */
  83.     private $_diagonal;
  84.     
  85.     /**
  86.      * Vertical
  87.      *
  88.      * @var PHPExcel_Style_Border 
  89.      */
  90.     private $_vertical;
  91.     
  92.     /**
  93.      * Horizontal
  94.      *
  95.      * @var PHPExcel_Style_Border 
  96.      */
  97.     private $_horizontal;
  98.     
  99.     /**
  100.      * DiagonalDirection
  101.      *
  102.      * @var int 
  103.      */
  104.     private $_diagonalDirection;
  105.     
  106.     /**
  107.      * Outline, defaults to true
  108.      *
  109.      * @var boolean 
  110.      */
  111.     private $_outline;
  112.     
  113.     /**
  114.      * Parent
  115.      *
  116.      * @var PHPExcel_Style 
  117.      */
  118.      
  119.     private $_parent;
  120.     
  121.     /**
  122.      * Parent Borders
  123.      *
  124.      * @var _parentPropertyName string
  125.      */
  126.     private $_parentPropertyName;
  127.         
  128.     /**
  129.      * Create a new PHPExcel_Style_Borders
  130.      */
  131.     public function __construct()
  132.     {
  133.         // Initialise values
  134.         
  135.         /**
  136.          * The following properties are late bound. Binding is initiated by property classes when they are modified.
  137.          *
  138.          * _left
  139.          * _right
  140.          * _top
  141.          * _bottom
  142.          * _diagonal
  143.          * _vertical
  144.          * _horizontal
  145.          *
  146.          */
  147.     
  148.         $this->_diagonalDirection    = PHPExcel_Style_Borders::DIAGONAL_NONE;
  149.         $this->_outline                = true;
  150.     }
  151.  
  152.     /**
  153.      * Property Prepare bind
  154.      *
  155.      * Configures this object for late binding as a property of a parent object
  156.      *     
  157.      * @param $parent 
  158.      * @param $parentPropertyName 
  159.      */
  160.     public function propertyPrepareBind($parent$parentPropertyName)
  161.     {
  162.         // Initialize parent PHPExcel_Style for late binding. This relationship purposely ends immediately when this object
  163.         // is bound to the PHPExcel_Style object pointed to so as to prevent circular references.
  164.         $this->_parent                 = $parent;
  165.         $this->_parentPropertyName    = $parentPropertyName;
  166.     }
  167.  
  168.     /**
  169.      * Property Get Bound
  170.      *
  171.      * Returns the PHPExcel_Style_Borders that is actual bound to PHPExcel_Style
  172.      *
  173.      * @return PHPExcel_Style_Borders 
  174.      */
  175.     private function propertyGetBound({
  176.         if(!isset($this->_parent))
  177.             return $this;                                                                // I am bound
  178.  
  179.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  180.             return $this->_parent->getBorders();                                        // Another one is bound
  181.  
  182.         return $this;                                                                    // No one is bound yet
  183.     }
  184.     
  185.     /**
  186.      * Property Begin Bind
  187.      *
  188.      * If no PHPExcel_Style_Borders has been bound to PHPExcel_Style then bind this one. Return the actual bound one.
  189.      *
  190.      * @return PHPExcel_Style_Borders 
  191.      */
  192.     private function propertyBeginBind({
  193.         if(!isset($this->_parent))
  194.             return $this;                                                                // I am already bound
  195.  
  196.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  197.             return $this->_parent->getBorders();                                        // Another one is already bound
  198.             
  199.         $this->_parent->propertyCompleteBind($this$this->_parentPropertyName);        // Bind myself
  200.         $this->_parent = null;
  201.         
  202.         return $this;
  203.     }
  204.           
  205.  
  206.     /**
  207.      * Property Complete Bind
  208.      *
  209.      * Complete the binding process a child property object started
  210.      *
  211.      * @param    $propertyObject 
  212.      * @param    $propertyName            Name of this property in the parent object
  213.      */ 
  214.     public function propertyCompleteBind($propertyObject$propertyName{
  215.         switch($propertyName{
  216.             case "_left":
  217.                 $this->propertyBeginBind()->_left $propertyObject;
  218.                 break;
  219.                 
  220.             case "_right":
  221.                 $this->propertyBeginBind()->_right $propertyObject;
  222.                 break;
  223.                 
  224.             case "_top":
  225.                 $this->propertyBeginBind()->_top $propertyObject;
  226.                 break;
  227.                 
  228.             case "_bottom":
  229.                 $this->propertyBeginBind()->_bottom $propertyObject;
  230.                 break;
  231.                 
  232.             case "_diagonal":
  233.                 $this->propertyBeginBind()->_diagonal $propertyObject;
  234.                 break;
  235.                 
  236.             case "_vertical":
  237.                 $this->propertyBeginBind()->_vertical $propertyObject;
  238.                 break;
  239.             
  240.             case "_horizontal":
  241.                 $this->propertyBeginBind()->_horizontal $propertyObject;
  242.                 break;
  243.  
  244.             default:
  245.                 throw new Exception("Invalid property passed.");
  246.         }
  247.     }
  248.  
  249.     /**
  250.      * Property Is Bound
  251.      *
  252.      * Determines if a child property is bound to this one
  253.      *
  254.      * @param    $propertyName            Name of this property in the parent object
  255.      *
  256.      * @return boolean 
  257.      */
  258.     public function propertyIsBound($propertyName{
  259.         switch($propertyName{
  260.             case "_left":
  261.                 return isset($this->propertyGetBound()->_left);
  262.  
  263.             case "_right":
  264.                 return isset($this->propertyGetBound()->_right);
  265.                 
  266.             case "_top":
  267.                 return isset($this->propertyGetBound()->_top);
  268.                 
  269.             case "_bottom":
  270.                 return isset($this->propertyGetBound()->_bottom);
  271.                 
  272.             case "_diagonal":
  273.                 return isset($this->propertyGetBound()->_diagonal);
  274.                 
  275.             case "_vertical":
  276.                 return isset($this->propertyGetBound()->_vertical);
  277.                 
  278.             case "_horizontal":
  279.                 return isset($this->propertyGetBound()->_horizontal);
  280.                 
  281.             default:
  282.                 throw new Exception("Invalid property passed.");
  283.         }
  284.     }
  285.     
  286.     /**
  287.      * Apply styles from array
  288.      * 
  289.      * <code>
  290.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
  291.      *         array(
  292.      *             'bottom'     => array(
  293.      *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
  294.      *                 'color' => array(
  295.      *                     'rgb' => '808080'
  296.      *                 )
  297.      *             ),
  298.      *             'top'     => array(
  299.      *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
  300.      *                 'color' => array(
  301.      *                     'rgb' => '808080'
  302.      *                 )
  303.      *             )
  304.      *         )
  305.      * );
  306.      * </code>
  307.      * <code>
  308.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
  309.      *         array(
  310.      *             'allborders' => array(
  311.      *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
  312.      *                 'color' => array(
  313.      *                     'rgb' => '808080'
  314.      *                 )
  315.      *             )
  316.      *         )
  317.      * );
  318.      * </code>
  319.      * 
  320.      * @param    array    $pStyles    Array containing style information
  321.      * @throws    Exception
  322.      */
  323.     public function applyFromArray($pStyles null{
  324.         if (is_array($pStyles)) {
  325.             if (array_key_exists('allborders'$pStyles)) {
  326.                 $this->getLeft()->applyFromArray($pStyles['allborders']);
  327.                 $this->getRight()->applyFromArray($pStyles['allborders']);
  328.                 $this->getTop()->applyFromArray($pStyles['allborders']);
  329.                 $this->getBottom()->applyFromArray($pStyles['allborders']);
  330.             }
  331.             if (array_key_exists('left'$pStyles)) {
  332.                 $this->getLeft()->applyFromArray($pStyles['left']);
  333.             }
  334.             if (array_key_exists('right'$pStyles)) {
  335.                 $this->getRight()->applyFromArray($pStyles['right']);
  336.             }
  337.             if (array_key_exists('top'$pStyles)) {
  338.                 $this->getTop()->applyFromArray($pStyles['top']);
  339.             }
  340.             if (array_key_exists('bottom'$pStyles)) {
  341.                 $this->getBottom()->applyFromArray($pStyles['bottom']);
  342.             }
  343.             if (array_key_exists('diagonal'$pStyles)) {
  344.                 $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
  345.             }
  346.             if (array_key_exists('vertical'$pStyles)) {
  347.                 $this->getVertical()->applyFromArray($pStyles['vertical']);
  348.             }
  349.             if (array_key_exists('horizontal'$pStyles)) {
  350.                 $this->getHorizontal()->applyFromArray($pStyles['horizontal']);
  351.             }
  352.             if (array_key_exists('diagonaldirection'$pStyles)) {
  353.                 $this->setDiagonalDirection($pStyles['diagonaldirection']);
  354.             }
  355.             if (array_key_exists('outline'$pStyles)) {
  356.                 $this->setOutline($pStyles['outline']);
  357.             }
  358.         else {
  359.             throw new Exception("Invalid style array passed.");
  360.         }
  361.     }
  362.     
  363.     /**
  364.      * Get Left
  365.      *
  366.      * @return PHPExcel_Style_Border 
  367.      */
  368.     public function getLeft({
  369.         $property $this->propertyGetBound();
  370.         if(isset($property->_left))
  371.             return $property->_left;
  372.  
  373.         $property new PHPExcel_Style_Border();
  374.         $property->propertyPrepareBind($this"_left");
  375.         return $property;
  376.     }
  377.     
  378.     /**
  379.      * Get Right
  380.      *
  381.      * @return PHPExcel_Style_Border 
  382.      */
  383.     public function getRight({
  384.         $property $this->propertyGetBound();
  385.         if(isset($property->_right))
  386.             return $property->_right;
  387.  
  388.  
  389.         $property new PHPExcel_Style_Border();
  390.         $property->propertyPrepareBind($this"_right");
  391.         return $property;
  392.     }
  393.        
  394.     /**
  395.      * Get Top
  396.      *
  397.      * @return PHPExcel_Style_Border 
  398.      */
  399.     public function getTop({
  400.         $property $this->propertyGetBound();
  401.         if(isset($property->_top))
  402.             return $property->_top;
  403.  
  404.  
  405.         $property new PHPExcel_Style_Border();
  406.         $property->propertyPrepareBind($this"_top");
  407.         return $property;
  408.     }
  409.     
  410.     /**
  411.      * Get Bottom
  412.      *
  413.      * @return PHPExcel_Style_Border 
  414.      */
  415.     public function getBottom({
  416.         $property $this->propertyGetBound();
  417.         if(isset($property->_bottom))
  418.             return $property->_bottom;
  419.  
  420.         $property new PHPExcel_Style_Border();
  421.         $property->propertyPrepareBind($this"_bottom");
  422.         return $property;
  423.     }
  424.  
  425.     /**
  426.      * Get Diagonal
  427.      *
  428.      * @return PHPExcel_Style_Border 
  429.      */
  430.     public function getDiagonal({
  431.         $property $this->propertyGetBound();
  432.         if(isset($property->_diagonal))
  433.             return $property->_diagonal;
  434.  
  435.         $property new PHPExcel_Style_Border();
  436.         $property->propertyPrepareBind($this"_diagonal");
  437.         return $property;
  438.     }
  439.     
  440.     /**
  441.      * Get Vertical
  442.      *
  443.      * @return PHPExcel_Style_Border 
  444.      */
  445.     public function getVertical({
  446.         $property $this->propertyGetBound();
  447.         if(isset($property->_vertical))
  448.             return $property->_vertical;
  449.  
  450.         $property new PHPExcel_Style_Border();
  451.         $property->propertyPrepareBind($this"_vertical");
  452.         return $property;
  453.     }
  454.     
  455.     /**
  456.      * Get Horizontal
  457.      *
  458.      * @return PHPExcel_Style_Border 
  459.      */
  460.     public function getHorizontal({
  461.         $property $this->propertyGetBound();
  462.         if(isset($property->_horizontal))
  463.             return $property->_horizontal;
  464.  
  465.         $property new PHPExcel_Style_Border();
  466.         $property->propertyPrepareBind($this"_horizontal");
  467.         return $property;
  468.     }
  469.     
  470.     /**
  471.      * Get DiagonalDirection
  472.      *
  473.      * @return int 
  474.      */
  475.     public function getDiagonalDirection({
  476.         return $this->propertyGetBound()->_diagonalDirection;
  477.     }
  478.     
  479.     /**
  480.      * Set DiagonalDirection
  481.      *
  482.      * @param int $pValue 
  483.      */
  484.     public function setDiagonalDirection($pValue PHPExcel_Style_Borders::DIAGONAL_NONE{
  485.         if ($pValue == ''{
  486.             $pValue PHPExcel_Style_Borders::DIAGONAL_NONE;
  487.         }
  488.         $this->propertyBeginBind()->_diagonalDirection $pValue;
  489.     }
  490.     
  491.     /**
  492.      * Get Outline
  493.      *
  494.      * @return boolean 
  495.      */
  496.     public function getOutline({
  497.         return $this->propertyGetBound()->_outline;
  498.     }
  499.     
  500.     /**
  501.      * Set Outline
  502.      *
  503.      * @param boolean $pValue 
  504.      */
  505.     public function setOutline($pValue true{
  506.         if ($pValue == ''{
  507.             $pValue true;
  508.         }
  509.         $this->propertyBeginBind()->_outline $pValue;
  510.     }
  511.     
  512.     /**
  513.      * Get hash code
  514.      *
  515.      * @return string    Hash code
  516.      */    
  517.     public function getHashCode({
  518.         $property $this->propertyGetBound();
  519.         return md5(
  520.               $property->getLeft()->getHashCode()
  521.             . $property->getRight()->getHashCode()
  522.             . $property->getTop()->getHashCode()
  523.             . $property->getBottom()->getHashCode()
  524.             . $property->getDiagonal()->getHashCode()
  525.             . $property->getVertical()->getHashCode()
  526.             . $property->getHorizontal()->getHashCode()
  527.             . $property->getDiagonalDirection()
  528.             . ($property->getOutline('t' 'f')
  529.             . __CLASS__
  530.         );
  531.     }
  532.     
  533.     /**
  534.      * Hash index
  535.      *
  536.      * @var string 
  537.      */
  538.     private $_hashIndex;
  539.     
  540.     /**
  541.      * Get hash index
  542.      * 
  543.      * Note that this index may vary during script execution! Only reliable moment is
  544.      * while doing a write of a workbook and when changes are not allowed.
  545.      *
  546.      * @return string    Hash index
  547.      */
  548.     public function getHashIndex({
  549.         return $this->_hashIndex;
  550.     }
  551.     
  552.     /**
  553.      * Set hash index
  554.      * 
  555.      * Note that this index may vary during script execution! Only reliable moment is
  556.      * while doing a write of a workbook and when changes are not allowed.
  557.      *
  558.      * @param string    $value    Hash index
  559.      */
  560.     public function setHashIndex($value{
  561.         $this->_hashIndex = $value;
  562.     }
  563.     
  564.     /**
  565.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  566.      */
  567.     public function __clone({
  568.         $vars get_object_vars($this);
  569.         foreach ($vars as $key => $value{
  570.             if (is_object($value)) {
  571.                 $this->$key clone $value;
  572.             else {
  573.                 $this->$key $value;
  574.             }
  575.         }
  576.     }
  577. }

Documentation generated on Mon, 05 Jan 2009 20:36:29 +0100 by phpDocumentor 1.4.1