For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.8 KiB

  1. <?php
  2. /**
  3. * PHPExcel_Style_Protection
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Style_Protection extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
  28. {
  29. /** Protection styles */
  30. const PROTECTION_INHERIT = 'inherit';
  31. const PROTECTION_PROTECTED = 'protected';
  32. const PROTECTION_UNPROTECTED = 'unprotected';
  33. /**
  34. * Locked
  35. *
  36. * @var string
  37. */
  38. protected $locked;
  39. /**
  40. * Hidden
  41. *
  42. * @var string
  43. */
  44. protected $hidden;
  45. /**
  46. * Create a new PHPExcel_Style_Protection
  47. *
  48. * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
  49. * Leave this value at default unless you understand exactly what
  50. * its ramifications are
  51. * @param boolean $isConditional Flag indicating if this is a conditional style or not
  52. * Leave this value at default unless you understand exactly what
  53. * its ramifications are
  54. */
  55. public function __construct($isSupervisor = false, $isConditional = false)
  56. {
  57. // Supervisor?
  58. parent::__construct($isSupervisor);
  59. // Initialise values
  60. if (!$isConditional) {
  61. $this->locked = self::PROTECTION_INHERIT;
  62. $this->hidden = self::PROTECTION_INHERIT;
  63. }
  64. }
  65. /**
  66. * Get the shared style component for the currently active cell in currently active sheet.
  67. * Only used for style supervisor
  68. *
  69. * @return PHPExcel_Style_Protection
  70. */
  71. public function getSharedComponent()
  72. {
  73. return $this->parent->getSharedComponent()->getProtection();
  74. }
  75. /**
  76. * Build style array from subcomponents
  77. *
  78. * @param array $array
  79. * @return array
  80. */
  81. public function getStyleArray($array)
  82. {
  83. return array('protection' => $array);
  84. }
  85. /**
  86. * Apply styles from array
  87. *
  88. * <code>
  89. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray(
  90. * array(
  91. * 'locked' => TRUE,
  92. * 'hidden' => FALSE
  93. * )
  94. * );
  95. * </code>
  96. *
  97. * @param array $pStyles Array containing style information
  98. * @throws PHPExcel_Exception
  99. * @return PHPExcel_Style_Protection
  100. */
  101. public function applyFromArray($pStyles = null)
  102. {
  103. if (is_array($pStyles)) {
  104. if ($this->isSupervisor) {
  105. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
  106. } else {
  107. if (isset($pStyles['locked'])) {
  108. $this->setLocked($pStyles['locked']);
  109. }
  110. if (isset($pStyles['hidden'])) {
  111. $this->setHidden($pStyles['hidden']);
  112. }
  113. }
  114. } else {
  115. throw new PHPExcel_Exception("Invalid style array passed.");
  116. }
  117. return $this;
  118. }
  119. /**
  120. * Get locked
  121. *
  122. * @return string
  123. */
  124. public function getLocked()
  125. {
  126. if ($this->isSupervisor) {
  127. return $this->getSharedComponent()->getLocked();
  128. }
  129. return $this->locked;
  130. }
  131. /**
  132. * Set locked
  133. *
  134. * @param string $pValue
  135. * @return PHPExcel_Style_Protection
  136. */
  137. public function setLocked($pValue = self::PROTECTION_INHERIT)
  138. {
  139. if ($this->isSupervisor) {
  140. $styleArray = $this->getStyleArray(array('locked' => $pValue));
  141. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  142. } else {
  143. $this->locked = $pValue;
  144. }
  145. return $this;
  146. }
  147. /**
  148. * Get hidden
  149. *
  150. * @return string
  151. */
  152. public function getHidden()
  153. {
  154. if ($this->isSupervisor) {
  155. return $this->getSharedComponent()->getHidden();
  156. }
  157. return $this->hidden;
  158. }
  159. /**
  160. * Set hidden
  161. *
  162. * @param string $pValue
  163. * @return PHPExcel_Style_Protection
  164. */
  165. public function setHidden($pValue = self::PROTECTION_INHERIT)
  166. {
  167. if ($this->isSupervisor) {
  168. $styleArray = $this->getStyleArray(array('hidden' => $pValue));
  169. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  170. } else {
  171. $this->hidden = $pValue;
  172. }
  173. return $this;
  174. }
  175. /**
  176. * Get hash code
  177. *
  178. * @return string Hash code
  179. */
  180. public function getHashCode()
  181. {
  182. if ($this->isSupervisor) {
  183. return $this->getSharedComponent()->getHashCode();
  184. }
  185. return md5(
  186. $this->locked .
  187. $this->hidden .
  188. __CLASS__
  189. );
  190. }
  191. }