PageRenderTime 24ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/includes/phpexcel/PHPExcel/Style/Protection.php

http://github.com/Dolibarr/dolibarr
PHP | 281 lines | 114 code | 23 blank | 144 comment | 17 complexity | f5d7467e102714d3ef8aa13731e4c9a9 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2011 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 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Style_Protection 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. private $_locked;
  46. /**
  47. * Hidden
  48. *
  49. * @var string
  50. */
  51. private $_hidden;
  52. /**
  53. * Parent Borders
  54. *
  55. * @var _parentPropertyName string
  56. */
  57. private $_parentPropertyName;
  58. /**
  59. * Supervisor?
  60. *
  61. * @var boolean
  62. */
  63. private $_isSupervisor;
  64. /**
  65. * Parent. Only used for supervisor
  66. *
  67. * @var PHPExcel_Style
  68. */
  69. private $_parent;
  70. /**
  71. * Create a new PHPExcel_Style_Protection
  72. */
  73. public function __construct($isSupervisor = false)
  74. {
  75. // Supervisor?
  76. $this->_isSupervisor = $isSupervisor;
  77. // Initialise values
  78. $this->_locked = self::PROTECTION_INHERIT;
  79. $this->_hidden = self::PROTECTION_INHERIT;
  80. }
  81. /**
  82. * Bind parent. Only used for supervisor
  83. *
  84. * @param PHPExcel_Style $parent
  85. * @return PHPExcel_Style_Protection
  86. */
  87. public function bindParent($parent)
  88. {
  89. $this->_parent = $parent;
  90. return $this;
  91. }
  92. /**
  93. * Is this a supervisor or a real style component?
  94. *
  95. * @return boolean
  96. */
  97. public function getIsSupervisor()
  98. {
  99. return $this->_isSupervisor;
  100. }
  101. /**
  102. * Get the shared style component for the currently active cell in currently active sheet.
  103. * Only used for style supervisor
  104. *
  105. * @return PHPExcel_Style_Protection
  106. */
  107. public function getSharedComponent()
  108. {
  109. return $this->_parent->getSharedComponent()->getProtection();
  110. }
  111. /**
  112. * Get the currently active sheet. Only used for supervisor
  113. *
  114. * @return PHPExcel_Worksheet
  115. */
  116. public function getActiveSheet()
  117. {
  118. return $this->_parent->getActiveSheet();
  119. }
  120. /**
  121. * Get the currently active cell coordinate in currently active sheet.
  122. * Only used for supervisor
  123. *
  124. * @return string E.g. 'A1'
  125. */
  126. public function getSelectedCells()
  127. {
  128. return $this->getActiveSheet()->getSelectedCells();
  129. }
  130. /**
  131. * Get the currently active cell coordinate in currently active sheet.
  132. * Only used for supervisor
  133. *
  134. * @return string E.g. 'A1'
  135. */
  136. public function getActiveCell()
  137. {
  138. return $this->getActiveSheet()->getActiveCell();
  139. }
  140. /**
  141. * Build style array from subcomponents
  142. *
  143. * @param array $array
  144. * @return array
  145. */
  146. public function getStyleArray($array)
  147. {
  148. return array('protection' => $array);
  149. }
  150. /**
  151. * Apply styles from array
  152. *
  153. * <code>
  154. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( array('locked' => true, 'hidden' => false) );
  155. * </code>
  156. *
  157. * @param array $pStyles Array containing style information
  158. * @throws Exception
  159. * @return PHPExcel_Style_Protection
  160. */
  161. public function applyFromArray($pStyles = null) {
  162. if (is_array($pStyles)) {
  163. if ($this->_isSupervisor) {
  164. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
  165. } else {
  166. if (array_key_exists('locked', $pStyles)) {
  167. $this->setLocked($pStyles['locked']);
  168. }
  169. if (array_key_exists('hidden', $pStyles)) {
  170. $this->setHidden($pStyles['hidden']);
  171. }
  172. }
  173. } else {
  174. throw new Exception("Invalid style array passed.");
  175. }
  176. return $this;
  177. }
  178. /**
  179. * Get locked
  180. *
  181. * @return string
  182. */
  183. public function getLocked() {
  184. if ($this->_isSupervisor) {
  185. return $this->getSharedComponent()->getLocked();
  186. }
  187. return $this->_locked;
  188. }
  189. /**
  190. * Set locked
  191. *
  192. * @param string $pValue
  193. * @return PHPExcel_Style_Protection
  194. */
  195. public function setLocked($pValue = self::PROTECTION_INHERIT) {
  196. if ($this->_isSupervisor) {
  197. $styleArray = $this->getStyleArray(array('locked' => $pValue));
  198. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  199. } else {
  200. $this->_locked = $pValue;
  201. }
  202. return $this;
  203. }
  204. /**
  205. * Get hidden
  206. *
  207. * @return string
  208. */
  209. public function getHidden() {
  210. if ($this->_isSupervisor) {
  211. return $this->getSharedComponent()->getHidden();
  212. }
  213. return $this->_hidden;
  214. }
  215. /**
  216. * Set hidden
  217. *
  218. * @param string $pValue
  219. * @return PHPExcel_Style_Protection
  220. */
  221. public function setHidden($pValue = self::PROTECTION_INHERIT) {
  222. if ($this->_isSupervisor) {
  223. $styleArray = $this->getStyleArray(array('hidden' => $pValue));
  224. $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
  225. } else {
  226. $this->_hidden = $pValue;
  227. }
  228. return $this;
  229. }
  230. /**
  231. * Get hash code
  232. *
  233. * @return string Hash code
  234. */
  235. public function getHashCode() {
  236. if ($this->_isSupervisor) {
  237. return $this->getSharedComponent()->getHashCode();
  238. }
  239. return md5(
  240. $this->_locked
  241. . $this->_hidden
  242. . __CLASS__
  243. );
  244. }
  245. /**
  246. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  247. */
  248. public function __clone() {
  249. $vars = get_object_vars($this);
  250. foreach ($vars as $key => $value) {
  251. if ((is_object($value)) && ($key != '_parent')) {
  252. $this->$key = clone $value;
  253. } else {
  254. $this->$key = $value;
  255. }
  256. }
  257. }
  258. }