854db8e2092d587c68a2aea9e292950fed001665.svn-base 5.2 KB

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