ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Protection.php
Go to the documentation of this file.
1<?php
2
4
5class Protection extends Supervisor
6{
8 const PROTECTION_INHERIT = 'inherit';
9 const PROTECTION_PROTECTED = 'protected';
10 const PROTECTION_UNPROTECTED = 'unprotected';
11
17 protected $locked;
18
24 protected $hidden;
25
36 public function __construct($isSupervisor = false, $isConditional = false)
37 {
38 // Supervisor?
39 parent::__construct($isSupervisor);
40
41 // Initialise values
42 if (!$isConditional) {
43 $this->locked = self::PROTECTION_INHERIT;
44 $this->hidden = self::PROTECTION_INHERIT;
45 }
46 }
47
54 public function getSharedComponent()
55 {
56 return $this->parent->getSharedComponent()->getProtection();
57 }
58
66 public function getStyleArray($array)
67 {
68 return ['protection' => $array];
69 }
70
87 public function applyFromArray(array $pStyles)
88 {
89 if ($this->isSupervisor) {
90 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
91 } else {
92 if (isset($pStyles['locked'])) {
93 $this->setLocked($pStyles['locked']);
94 }
95 if (isset($pStyles['hidden'])) {
96 $this->setHidden($pStyles['hidden']);
97 }
98 }
99
100 return $this;
101 }
102
108 public function getLocked()
109 {
110 if ($this->isSupervisor) {
111 return $this->getSharedComponent()->getLocked();
112 }
113
114 return $this->locked;
115 }
116
124 public function setLocked($pValue)
125 {
126 if ($this->isSupervisor) {
127 $styleArray = $this->getStyleArray(['locked' => $pValue]);
128 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
129 } else {
130 $this->locked = $pValue;
131 }
132
133 return $this;
134 }
135
141 public function getHidden()
142 {
143 if ($this->isSupervisor) {
144 return $this->getSharedComponent()->getHidden();
145 }
146
147 return $this->hidden;
148 }
149
157 public function setHidden($pValue)
158 {
159 if ($this->isSupervisor) {
160 $styleArray = $this->getStyleArray(['hidden' => $pValue]);
161 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
162 } else {
163 $this->hidden = $pValue;
164 }
165
166 return $this;
167 }
168
174 public function getHashCode()
175 {
176 if ($this->isSupervisor) {
177 return $this->getSharedComponent()->getHashCode();
178 }
179
180 return md5(
181 $this->locked .
182 $this->hidden .
183 __CLASS__
184 );
185 }
186
187 protected function exportArray1(): array
188 {
189 $exportedArray = [];
190 $this->exportArray2($exportedArray, 'locked', $this->getLocked());
191 $this->exportArray2($exportedArray, 'hidden', $this->getHidden());
192
193 return $exportedArray;
194 }
195}
An exception for terminatinating execution or to throw for unit testing.
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
Definition: Protection.php:54
const PROTECTION_INHERIT
Protection styles.
Definition: Protection.php:8
getStyleArray($array)
Build style array from subcomponents.
Definition: Protection.php:66
exportArray1()
Abstract method to be implemented in anything which extends this class.
Definition: Protection.php:187
__construct($isSupervisor=false, $isConditional=false)
Create a new Protection.
Definition: Protection.php:36
applyFromArray(array $pStyles)
Apply styles from array.
Definition: Protection.php:87
getActiveSheet()
Get the currently active sheet.
Definition: Supervisor.php:76
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
Definition: Supervisor.php:87
exportArray2(array &$exportedArray, string $index, $objOrValue)
Populate array from exportArray1.
Definition: Supervisor.php:150