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

Documentation generated on Mon, 11 Jan 2010 08:13:04 +0100 by phpDocumentor 1.4.1