updated a couple packages (#1567)
[openemr.git] / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Style / Protection.php
blobb5feb53486e550a67581f35773ec0c0246702df5
1 <?php
3 namespace PhpOffice\PhpSpreadsheet\Style;
5 use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
7 class Protection extends Supervisor
9 /** Protection styles */
10 const PROTECTION_INHERIT = 'inherit';
11 const PROTECTION_PROTECTED = 'protected';
12 const PROTECTION_UNPROTECTED = 'unprotected';
14 /**
15 * Locked.
17 * @var string
19 protected $locked;
21 /**
22 * Hidden.
24 * @var string
26 protected $hidden;
28 /**
29 * Create a new Protection.
31 * @param bool $isSupervisor Flag indicating if this is a supervisor or not
32 * Leave this value at default unless you understand exactly what
33 * its ramifications are
34 * @param bool $isConditional Flag indicating if this is a conditional style or not
35 * Leave this value at default unless you understand exactly what
36 * its ramifications are
38 public function __construct($isSupervisor = false, $isConditional = false)
40 // Supervisor?
41 parent::__construct($isSupervisor);
43 // Initialise values
44 if (!$isConditional) {
45 $this->locked = self::PROTECTION_INHERIT;
46 $this->hidden = self::PROTECTION_INHERIT;
50 /**
51 * Get the shared style component for the currently active cell in currently active sheet.
52 * Only used for style supervisor.
54 * @return Protection
56 public function getSharedComponent()
58 return $this->parent->getSharedComponent()->getProtection();
61 /**
62 * Build style array from subcomponents.
64 * @param array $array
66 * @return array
68 public function getStyleArray($array)
70 return ['protection' => $array];
73 /**
74 * Apply styles from array.
76 * <code>
77 * $spreadsheet->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray(
78 * [
79 * 'locked' => TRUE,
80 * 'hidden' => FALSE
81 * ]
82 * );
83 * </code>
85 * @param array $pStyles Array containing style information
87 * @throws PhpSpreadsheetException
89 * @return Protection
91 public function applyFromArray(array $pStyles)
93 if ($this->isSupervisor) {
94 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
95 } else {
96 if (isset($pStyles['locked'])) {
97 $this->setLocked($pStyles['locked']);
99 if (isset($pStyles['hidden'])) {
100 $this->setHidden($pStyles['hidden']);
104 return $this;
108 * Get locked.
110 * @return string
112 public function getLocked()
114 if ($this->isSupervisor) {
115 return $this->getSharedComponent()->getLocked();
118 return $this->locked;
122 * Set locked.
124 * @param string $pValue see self::PROTECTION_*
126 * @return Protection
128 public function setLocked($pValue)
130 if ($this->isSupervisor) {
131 $styleArray = $this->getStyleArray(['locked' => $pValue]);
132 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
133 } else {
134 $this->locked = $pValue;
137 return $this;
141 * Get hidden.
143 * @return string
145 public function getHidden()
147 if ($this->isSupervisor) {
148 return $this->getSharedComponent()->getHidden();
151 return $this->hidden;
155 * Set hidden.
157 * @param string $pValue see self::PROTECTION_*
159 * @return Protection
161 public function setHidden($pValue)
163 if ($this->isSupervisor) {
164 $styleArray = $this->getStyleArray(['hidden' => $pValue]);
165 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
166 } else {
167 $this->hidden = $pValue;
170 return $this;
174 * Get hash code.
176 * @return string Hash code
178 public function getHashCode()
180 if ($this->isSupervisor) {
181 return $this->getSharedComponent()->getHashCode();
184 return md5(
185 $this->locked .
186 $this->hidden .
187 __CLASS__