Protection.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Style_Protection extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
  8. {
  9. /** Protection styles */
  10. const PROTECTION_INHERIT = 'inherit';
  11. const PROTECTION_PROTECTED = 'protected';
  12. const PROTECTION_UNPROTECTED = 'unprotected';
  13. /**
  14. * Locked
  15. *
  16. * @var string
  17. */
  18. protected $locked;
  19. /**
  20. * Hidden
  21. *
  22. * @var string
  23. */
  24. protected $hidden;
  25. /**
  26. * Create a new PHPExcel_Style_Protection
  27. *
  28. * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
  29. * Leave this value at default unless you understand exactly what
  30. * its ramifications are
  31. * @param boolean $isConditional Flag indicating if this is a conditional style or not
  32. * Leave this value at default unless you understand exactly what
  33. * its ramifications are
  34. */
  35. public function __construct($isSupervisor = false, $isConditional = false)
  36. {
  37. // Supervisor?
  38. parent::__construct($isSupervisor);
  39. // Initialise values
  40. if (!$isConditional) {
  41. $this->locked = self::PROTECTION_INHERIT;
  42. $this->hidden = self::PROTECTION_INHERIT;
  43. }
  44. }
  45. /**
  46. * Get the shared style component for the currently active cell in currently active sheet.
  47. * Only used for style supervisor
  48. *
  49. * @return PHPExcel_Style_Protection
  50. */
  51. public function getSharedComponent()
  52. {
  53. return $this->parent->getSharedComponent()->getProtection();
  54. }
  55. /**
  56. * Build style array from subcomponents
  57. *
  58. * @param array $array
  59. * @return array
  60. */
  61. public function getStyleArray($array)
  62. {
  63. return array('protection' => $array);
  64. }
  65. /**
  66. * Apply styles from array
  67. *
  68. * <code>
  69. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray(
  70. * array(
  71. * 'locked' => TRUE,
  72. * 'hidden' => FALSE
  73. * )
  74. * );
  75. * </code>
  76. *
  77. * @param array $pStyles Array containing style information
  78. * @throws PHPExcel_Exception
  79. * @return PHPExcel_Style_Protection
  80. */
  81. public function applyFromArray($pStyles = null)
  82. {
  83. if (is_array($pStyles)) {
  84. if ($this->isSupervisor) {
  85. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
  86. } else {
  87. if (isset($pStyles['locked'])) {
  88. $this->setLocked($pStyles['locked']);
  89. }
  90. if (isset($pStyles['hidden'])) {
  91. $this->setHidden($pStyles['hidden']);
  92. }
  93. }
  94. } else {
  95. throw new PHPExcel_Exception("Invalid style array passed.");
  96. }
  97. return $this;
  98. }
  99. /**
  100. * Get locked
  101. *
  102. * @return string
  103. */
  104. public function getLocked()
  105. {
  106. if ($this->isSupervisor) {
  107. return $this->getSharedComponent()->getLocked();
  108. }
  109. return $this->locked;
  110. }
  111. /**
  112. * Set locked
  113. *
  114. * @param string $pValue
  115. * @return PHPExcel_Style_Protection
  116. */
  117. public function setLocked($pValue = self::PROTECTION_INHERIT)
  118. {
  119. if ($this->isSupervisor) {
  120. $styleArray = $this->getStyleArray(array('locked' => $pValue));
  121. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  122. } else {
  123. $this->locked = $pValue;
  124. }
  125. return $this;
  126. }
  127. /**
  128. * Get hidden
  129. *
  130. * @return string
  131. */
  132. public function getHidden()
  133. {
  134. if ($this->isSupervisor) {
  135. return $this->getSharedComponent()->getHidden();
  136. }
  137. return $this->hidden;
  138. }
  139. /**
  140. * Set hidden
  141. *
  142. * @param string $pValue
  143. * @return PHPExcel_Style_Protection
  144. */
  145. public function setHidden($pValue = self::PROTECTION_INHERIT)
  146. {
  147. if ($this->isSupervisor) {
  148. $styleArray = $this->getStyleArray(array('hidden' => $pValue));
  149. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  150. } else {
  151. $this->hidden = $pValue;
  152. }
  153. return $this;
  154. }
  155. /**
  156. * Get hash code
  157. *
  158. * @return string Hash code
  159. */
  160. public function getHashCode()
  161. {
  162. if ($this->isSupervisor) {
  163. return $this->getSharedComponent()->getHashCode();
  164. }
  165. return md5(
  166. $this->locked .
  167. $this->hidden .
  168. __CLASS__
  169. );
  170. }
  171. }