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 - 2011 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 - 2011 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. /**
  30.  * PHPExcel_Style_Protection
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Style
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. class PHPExcel_Style_Protection implements PHPExcel_IComparable
  37. {
  38.     /** Protection styles */
  39.     const PROTECTION_INHERIT        'inherit';
  40.     const PROTECTION_PROTECTED        'protected';
  41.     const PROTECTION_UNPROTECTED    'unprotected';
  42.  
  43.     /**
  44.      * Locked
  45.      *
  46.      * @var string 
  47.      */
  48.     private $_locked;
  49.  
  50.     /**
  51.      * Hidden
  52.      *
  53.      * @var string 
  54.      */
  55.     private $_hidden;
  56.  
  57.     /**
  58.      * Parent Borders
  59.      *
  60.      * @var _parentPropertyName string
  61.      */
  62.     private $_parentPropertyName;
  63.  
  64.     /**
  65.      * Supervisor?
  66.      *
  67.      * @var boolean 
  68.      */
  69.     private $_isSupervisor;
  70.  
  71.     /**
  72.      * Parent. Only used for supervisor
  73.      *
  74.      * @var PHPExcel_Style 
  75.      */
  76.     private $_parent;
  77.  
  78.     /**
  79.      * Create a new PHPExcel_Style_Protection
  80.      */
  81.     public function __construct($isSupervisor false)
  82.     {
  83.         // Supervisor?
  84.         $this->_isSupervisor $isSupervisor;
  85.  
  86.         // Initialise values
  87.         $this->_locked            self::PROTECTION_INHERIT;
  88.         $this->_hidden            self::PROTECTION_INHERIT;
  89.     }
  90.  
  91.     /**
  92.      * Bind parent. Only used for supervisor
  93.      *
  94.      * @param PHPExcel_Style $parent 
  95.      * @return PHPExcel_Style_Protection 
  96.      */
  97.     public function bindParent($parent)
  98.     {
  99.         $this->_parent $parent;
  100.         return $this;
  101.     }
  102.  
  103.     /**
  104.      * Is this a supervisor or a real style component?
  105.      *
  106.      * @return boolean 
  107.      */
  108.     public function getIsSupervisor()
  109.     {
  110.         return $this->_isSupervisor;
  111.     }
  112.  
  113.     /**
  114.      * Get the shared style component for the currently active cell in currently active sheet.
  115.      * Only used for style supervisor
  116.      *
  117.      * @return PHPExcel_Style_Protection 
  118.      */
  119.     public function getSharedComponent()
  120.     {
  121.         return $this->_parent->getSharedComponent()->getProtection();
  122.     }
  123.  
  124.     /**
  125.      * Get the currently active sheet. Only used for supervisor
  126.      *
  127.      * @return PHPExcel_Worksheet 
  128.      */
  129.     public function getActiveSheet()
  130.     {
  131.         return $this->_parent->getActiveSheet();
  132.     }
  133.  
  134.     /**
  135.      * Get the currently active cell coordinate in currently active sheet.
  136.      * Only used for supervisor
  137.      *
  138.      * @return string E.g. 'A1'
  139.      */
  140.     public function getSelectedCells()
  141.     {
  142.         return $this->getActiveSheet()->getSelectedCells();
  143.     }
  144.  
  145.     /**
  146.      * Get the currently active cell coordinate in currently active sheet.
  147.      * Only used for supervisor
  148.      *
  149.      * @return string E.g. 'A1'
  150.      */
  151.     public function getActiveCell()
  152.     {
  153.         return $this->getActiveSheet()->getActiveCell();
  154.     }
  155.  
  156.     /**
  157.      * Build style array from subcomponents
  158.      *
  159.      * @param array $array 
  160.      * @return array 
  161.      */
  162.     public function getStyleArray($array)
  163.     {
  164.         return array('protection' => $array);
  165.     }
  166.  
  167.     /**
  168.      * Apply styles from array
  169.      *
  170.      * <code>
  171.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( array('locked' => true, 'hidden' => false) );
  172.      * </code>
  173.      *
  174.      * @param    array    $pStyles    Array containing style information
  175.      * @throws    Exception
  176.      * @return PHPExcel_Style_Protection 
  177.      */
  178.     public function applyFromArray($pStyles null{
  179.         if (is_array($pStyles)) {
  180.             if ($this->_isSupervisor{
  181.                 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
  182.             else {
  183.                 if (array_key_exists('locked'$pStyles)) {
  184.                     $this->setLocked($pStyles['locked']);
  185.                 }
  186.                 if (array_key_exists('hidden'$pStyles)) {
  187.                     $this->setHidden($pStyles['hidden']);
  188.                 }
  189.             }
  190.         else {
  191.             throw new Exception("Invalid style array passed.");
  192.         }
  193.         return $this;
  194.     }
  195.  
  196.     /**
  197.      * Get locked
  198.      *
  199.      * @return string 
  200.      */
  201.     public function getLocked({
  202.         if ($this->_isSupervisor{
  203.             return $this->getSharedComponent()->getLocked();
  204.         }
  205.         return $this->_locked;
  206.     }
  207.  
  208.     /**
  209.      * Set locked
  210.      *
  211.      * @param string $pValue 
  212.      * @return PHPExcel_Style_Protection 
  213.      */
  214.     public function setLocked($pValue self::PROTECTION_INHERIT{
  215.         if ($this->_isSupervisor{
  216.             $styleArray $this->getStyleArray(array('locked' => $pValue));
  217.             $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  218.         else {
  219.             $this->_locked $pValue;
  220.         }
  221.         return $this;
  222.     }
  223.  
  224.     /**
  225.      * Get hidden
  226.      *
  227.      * @return string 
  228.      */
  229.     public function getHidden({
  230.         if ($this->_isSupervisor{
  231.             return $this->getSharedComponent()->getHidden();
  232.         }
  233.         return $this->_hidden;
  234.     }
  235.  
  236.     /**
  237.      * Set hidden
  238.      *
  239.      * @param string $pValue 
  240.      * @return PHPExcel_Style_Protection 
  241.      */
  242.     public function setHidden($pValue self::PROTECTION_INHERIT{
  243.         if ($this->_isSupervisor{
  244.             $styleArray $this->getStyleArray(array('hidden' => $pValue));
  245.             $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  246.         else {
  247.             $this->_hidden $pValue;
  248.         }
  249.         return $this;
  250.     }
  251.  
  252.     /**
  253.      * Get hash code
  254.      *
  255.      * @return string    Hash code
  256.      */
  257.     public function getHashCode({
  258.         if ($this->_isSupervisor{
  259.             return $this->getSharedComponent()->getHashCode();
  260.         }
  261.         return md5(
  262.               $this->_locked
  263.             . $this->_hidden
  264.             . __CLASS__
  265.         );
  266.     }
  267.  
  268.     /**
  269.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  270.      */
  271.     public function __clone({
  272.         $vars get_object_vars($this);
  273.         foreach ($vars as $key => $value{
  274.             if ((is_object($value)) && ($key != '_parent')) {
  275.                 $this->$key clone $value;
  276.             else {
  277.                 $this->$key $value;
  278.             }
  279.         }
  280.     }
  281. }

Documentation generated on Sun, 27 Feb 2011 16:33:30 -0800 by phpDocumentor 1.4.3