[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Style/ -> Protection.php (source)

   1  <?php
   2  
   3  /**
   4   * PHPExcel_Style_Protection
   5   *
   6   * Copyright (c) 2006 - 2015 PHPExcel
   7   *
   8   * This library is free software; you can redistribute it and/or
   9   * modify it under the terms of the GNU Lesser General Public
  10   * License as published by the Free Software Foundation; either
  11   * version 2.1 of the License, or (at your option) any later version.
  12   *
  13   * This library is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16   * Lesser General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU Lesser General Public
  19   * License along with this library; if not, write to the Free Software
  20   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  21   *
  22   * @category   PHPExcel
  23   * @package    PHPExcel_Style
  24   * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  25   * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  26   * @version    ##VERSION##, ##DATE##
  27   */
  28  class PHPExcel_Style_Protection extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
  29  {
  30      /** Protection styles */
  31      const PROTECTION_INHERIT      = 'inherit';
  32      const PROTECTION_PROTECTED    = 'protected';
  33      const PROTECTION_UNPROTECTED  = 'unprotected';
  34  
  35      /**
  36       * Locked
  37       *
  38       * @var string
  39       */
  40      protected $locked;
  41  
  42      /**
  43       * Hidden
  44       *
  45       * @var string
  46       */
  47      protected $hidden;
  48  
  49      /**
  50       * Create a new PHPExcel_Style_Protection
  51       *
  52       * @param    boolean    $isSupervisor    Flag indicating if this is a supervisor or not
  53       *                                    Leave this value at default unless you understand exactly what
  54       *                                        its ramifications are
  55       * @param    boolean    $isConditional    Flag indicating if this is a conditional style or not
  56       *                                    Leave this value at default unless you understand exactly what
  57       *                                        its ramifications are
  58       */
  59      public function __construct($isSupervisor = false, $isConditional = false)
  60      {
  61          // Supervisor?
  62          parent::__construct($isSupervisor);
  63  
  64          // Initialise values
  65          if (!$isConditional) {
  66              $this->locked = self::PROTECTION_INHERIT;
  67              $this->hidden = self::PROTECTION_INHERIT;
  68          }
  69      }
  70  
  71      /**
  72       * Get the shared style component for the currently active cell in currently active sheet.
  73       * Only used for style supervisor
  74       *
  75       * @return PHPExcel_Style_Protection
  76       */
  77      public function getSharedComponent()
  78      {
  79          return $this->parent->getSharedComponent()->getProtection();
  80      }
  81  
  82      /**
  83       * Build style array from subcomponents
  84       *
  85       * @param array $array
  86       * @return array
  87       */
  88      public function getStyleArray($array)
  89      {
  90          return array('protection' => $array);
  91      }
  92  
  93      /**
  94       * Apply styles from array
  95       *
  96       * <code>
  97       * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray(
  98       *        array(
  99       *            'locked' => TRUE,
 100       *            'hidden' => FALSE
 101       *        )
 102       * );
 103       * </code>
 104       *
 105       * @param    array    $pStyles    Array containing style information
 106       * @throws    PHPExcel_Exception
 107       * @return PHPExcel_Style_Protection
 108       */
 109      public function applyFromArray($pStyles = null)
 110      {
 111          if (is_array($pStyles)) {
 112              if ($this->isSupervisor) {
 113                  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
 114              } else {
 115                  if (isset($pStyles['locked'])) {
 116                      $this->setLocked($pStyles['locked']);
 117                  }
 118                  if (isset($pStyles['hidden'])) {
 119                      $this->setHidden($pStyles['hidden']);
 120                  }
 121              }
 122          } else {
 123              throw new PHPExcel_Exception("Invalid style array passed.");
 124          }
 125          return $this;
 126      }
 127  
 128      /**
 129       * Get locked
 130       *
 131       * @return string
 132       */
 133      public function getLocked()
 134      {
 135          if ($this->isSupervisor) {
 136              return $this->getSharedComponent()->getLocked();
 137          }
 138          return $this->locked;
 139      }
 140  
 141      /**
 142       * Set locked
 143       *
 144       * @param string $pValue
 145       * @return PHPExcel_Style_Protection
 146       */
 147      public function setLocked($pValue = self::PROTECTION_INHERIT)
 148      {
 149          if ($this->isSupervisor) {
 150              $styleArray = $this->getStyleArray(array('locked' => $pValue));
 151              $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
 152          } else {
 153              $this->locked = $pValue;
 154          }
 155          return $this;
 156      }
 157  
 158      /**
 159       * Get hidden
 160       *
 161       * @return string
 162       */
 163      public function getHidden()
 164      {
 165          if ($this->isSupervisor) {
 166              return $this->getSharedComponent()->getHidden();
 167          }
 168          return $this->hidden;
 169      }
 170  
 171      /**
 172       * Set hidden
 173       *
 174       * @param string $pValue
 175       * @return PHPExcel_Style_Protection
 176       */
 177      public function setHidden($pValue = self::PROTECTION_INHERIT)
 178      {
 179          if ($this->isSupervisor) {
 180              $styleArray = $this->getStyleArray(array('hidden' => $pValue));
 181              $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
 182          } else {
 183              $this->hidden = $pValue;
 184          }
 185          return $this;
 186      }
 187  
 188      /**
 189       * Get hash code
 190       *
 191       * @return string    Hash code
 192       */
 193      public function getHashCode()
 194      {
 195          if ($this->isSupervisor) {
 196              return $this->getSharedComponent()->getHashCode();
 197          }
 198          return md5(
 199              $this->locked .
 200              $this->hidden .
 201              __CLASS__
 202          );
 203      }
 204  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1