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

Source for file Protection.php

Documentation is available at Protection.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.4.5, 2007-08-23
  26.  */
  27.  
  28.  
  29. /** PHPExcel_IComparable */
  30. require_once 'PHPExcel/IComparable.php';
  31.  
  32.  
  33. /**
  34.  * PHPExcel_Style_Protection
  35.  *
  36.  * @category   PHPExcel
  37.  * @package    PHPExcel_Style
  38.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  39.  */
  40. class PHPExcel_Style_Protection implements PHPExcel_IComparable
  41. {
  42.     /** Protection styles */
  43.     const PROTECTION_INHERIT        'inherit';
  44.     const PROTECTION_PROTECTED        'protected';
  45.     const PROTECTION_UNPROTECTED    'unprotected';
  46.  
  47.     /**
  48.      * Locked
  49.      *
  50.      * @var string 
  51.      */
  52.     private $_locked;
  53.  
  54.     /**
  55.      * Hidden
  56.      *
  57.      * @var string 
  58.      */
  59.     private $_hidden;
  60.  
  61.     /**
  62.      * Parent Style
  63.      *
  64.      * @var PHPExcel_Style 
  65.      */
  66.  
  67.     private $_parent;
  68.  
  69.     /**
  70.      * Parent Borders
  71.      *
  72.      * @var _parentPropertyName string
  73.      */
  74.     private $_parentPropertyName;
  75.  
  76.     /**
  77.      * Create a new PHPExcel_Style_Protection
  78.      */
  79.     public function __construct()
  80.     {
  81.         // Initialise values
  82.         $this->_locked            = self::PROTECTION_INHERIT;
  83.         $this->_hidden            = self::PROTECTION_INHERIT;
  84.     }
  85.  
  86.     /**
  87.      * Property Prepare bind
  88.      *
  89.      * Configures this object for late binding as a property of a parent object
  90.      *
  91.      * @param $parent 
  92.      * @param $parentPropertyName 
  93.      */
  94.     public function propertyPrepareBind($parent$parentPropertyName)
  95.     {
  96.         // Initialize parent PHPExcel_Style for late binding. This relationship purposely ends immediately when this object
  97.         // is bound to the PHPExcel_Style object pointed to so as to prevent circular references.
  98.         $this->_parent                 = $parent;
  99.         $this->_parentPropertyName    = $parentPropertyName;
  100.     }
  101.  
  102.     /**
  103.      * Property Get Bound
  104.      *
  105.      * Returns the PHPExcel_Style_Protection that is actual bound to PHPExcel_Style
  106.      *
  107.      * @return PHPExcel_Style_Protection 
  108.      */
  109.     private function propertyGetBound({
  110.         if(!isset($this->_parent))
  111.             return $this;                                                                // I am bound
  112.  
  113.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  114.             return $this->_parent->getProtection();                                        // Another one is bound
  115.  
  116.         return $this;                                                                    // No one is bound yet
  117.     }
  118.  
  119.     /**
  120.      * Property Begin Bind
  121.      *
  122.      * If no PHPExcel_Style_Protection has been bound to PHPExcel_Style then bind this one. Return the actual bound one.
  123.      *
  124.      * @return PHPExcel_Style_Protection 
  125.      */
  126.     private function propertyBeginBind({
  127.         if(!isset($this->_parent))
  128.             return $this;                                                                // I am already bound
  129.  
  130.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  131.             return $this->_parent->getProtection();                                        // Another one is already bound
  132.  
  133.         $this->_parent->propertyCompleteBind($this$this->_parentPropertyName);        // Bind myself
  134.         $this->_parent = null;
  135.  
  136.         return $this;
  137.     }
  138.  
  139.     /**
  140.      * Apply styles from array
  141.      *
  142.      * <code>
  143.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( array('locked' => true, 'hidden' => false) );
  144.      * </code>
  145.      *
  146.      * @param    array    $pStyles    Array containing style information
  147.      * @throws    Exception
  148.      */
  149.     public function applyFromArray($pStyles null{
  150.         if (is_array($pStyles)) {
  151.             if (array_key_exists('locked'$pStyles)) {
  152.                 $this->setLocked($pStyles['locked']);
  153.             }
  154.             if (array_key_exists('hidden'$pStyles)) {
  155.                 $this->setHidden($pStyles['hidden']);
  156.             }
  157.         else {
  158.             throw new Exception("Invalid style array passed.");
  159.         }
  160.     }
  161.  
  162.     /**
  163.      * Get locked
  164.      *
  165.      * @return string 
  166.      */
  167.     public function getLocked({
  168.         return $this->propertyGetBound()->_locked;
  169.     }
  170.  
  171.     /**
  172.      * Set locked
  173.      *
  174.      * @param string $pValue 
  175.      */
  176.     public function setLocked($pValue self::PROTECTION_INHERIT{
  177.         $this->propertyBeginBind()->_locked $pValue;
  178.     }
  179.  
  180.     /**
  181.      * Get hidden
  182.      *
  183.      * @return string 
  184.      */
  185.     public function getHidden({
  186.         return $this->propertyGetBound()->_hidden;
  187.     }
  188.  
  189.     /**
  190.      * Set hidden
  191.      *
  192.      * @param string $pValue 
  193.      */
  194.     public function setHidden($pValue self::PROTECTION_INHERIT{
  195.         $this->propertyBeginBind()->_hidden $pValue;
  196.     }
  197.  
  198.     /**
  199.      * Get hash code
  200.      *
  201.      * @return string    Hash code
  202.      */
  203.     public function getHashCode({
  204.         $property $this->propertyGetBound();
  205.         return md5(
  206.               $property->_locked
  207.             . $property->_hidden
  208.             . __CLASS__
  209.         );
  210.     }
  211.     
  212.     /**
  213.      * Hash index
  214.      *
  215.      * @var string 
  216.      */
  217.     private $_hashIndex;
  218.     
  219.     /**
  220.      * Get hash index
  221.      * 
  222.      * Note that this index may vary during script execution! Only reliable moment is
  223.      * while doing a write of a workbook and when changes are not allowed.
  224.      *
  225.      * @return string    Hash index
  226.      */
  227.     public function getHashIndex({
  228.         return $this->_hashIndex;
  229.     }
  230.     
  231.     /**
  232.      * Set hash index
  233.      * 
  234.      * Note that this index may vary during script execution! Only reliable moment is
  235.      * while doing a write of a workbook and when changes are not allowed.
  236.      *
  237.      * @param string    $value    Hash index
  238.      */
  239.     public function setHashIndex($value{
  240.         $this->_hashIndex = $value;
  241.     }
  242.  
  243.     /**
  244.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  245.      */
  246.     public function __clone({
  247.         $vars get_object_vars($this);
  248.         foreach ($vars as $key => $value{
  249.             if (is_object($value)) {
  250.                 $this->$key clone $value;
  251.             else {
  252.                 $this->$key $value;
  253.             }
  254.         }
  255.     }
  256. }

Documentation generated on Mon, 05 Jan 2009 20:38:23 +0100 by phpDocumentor 1.4.1