ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Fill.php
Go to the documentation of this file.
1<?php
2
4
5class Fill extends Supervisor
6{
7 // Fill types
8 const FILL_NONE = 'none';
9 const FILL_SOLID = 'solid';
10 const FILL_GRADIENT_LINEAR = 'linear';
11 const FILL_GRADIENT_PATH = 'path';
12 const FILL_PATTERN_DARKDOWN = 'darkDown';
13 const FILL_PATTERN_DARKGRAY = 'darkGray';
14 const FILL_PATTERN_DARKGRID = 'darkGrid';
15 const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
16 const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
17 const FILL_PATTERN_DARKUP = 'darkUp';
18 const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
19 const FILL_PATTERN_GRAY0625 = 'gray0625';
20 const FILL_PATTERN_GRAY125 = 'gray125';
21 const FILL_PATTERN_LIGHTDOWN = 'lightDown';
22 const FILL_PATTERN_LIGHTGRAY = 'lightGray';
23 const FILL_PATTERN_LIGHTGRID = 'lightGrid';
24 const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
25 const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
26 const FILL_PATTERN_LIGHTUP = 'lightUp';
27 const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
28 const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
29
34
39
46
52 protected $rotation = 0;
53
59 protected $startColor;
60
66 protected $endColor;
67
78 public function __construct($isSupervisor = false, $isConditional = false)
79 {
80 // Supervisor?
81 parent::__construct($isSupervisor);
82
83 // Initialise values
84 if ($isConditional) {
85 $this->fillType = null;
86 }
87 $this->startColor = new Color(Color::COLOR_WHITE, $isSupervisor, $isConditional);
88 $this->endColor = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional);
89
90 // bind parent if we are a supervisor
91 if ($isSupervisor) {
92 $this->startColor->bindParent($this, 'startColor');
93 $this->endColor->bindParent($this, 'endColor');
94 }
95 }
96
103 public function getSharedComponent()
104 {
105 return $this->parent->getSharedComponent()->getFill();
106 }
107
115 public function getStyleArray($array)
116 {
117 return ['fill' => $array];
118 }
119
142 public function applyFromArray(array $pStyles)
143 {
144 if ($this->isSupervisor) {
145 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
146 } else {
147 if (isset($pStyles['fillType'])) {
148 $this->setFillType($pStyles['fillType']);
149 }
150 if (isset($pStyles['rotation'])) {
151 $this->setRotation($pStyles['rotation']);
152 }
153 if (isset($pStyles['startColor'])) {
154 $this->getStartColor()->applyFromArray($pStyles['startColor']);
155 }
156 if (isset($pStyles['endColor'])) {
157 $this->getEndColor()->applyFromArray($pStyles['endColor']);
158 }
159 if (isset($pStyles['color'])) {
160 $this->getStartColor()->applyFromArray($pStyles['color']);
161 $this->getEndColor()->applyFromArray($pStyles['color']);
162 }
163 }
164
165 return $this;
166 }
167
173 public function getFillType()
174 {
175 if ($this->isSupervisor) {
176 return $this->getSharedComponent()->getFillType();
177 }
178
179 return $this->fillType;
180 }
181
189 public function setFillType($pValue)
190 {
191 if ($this->isSupervisor) {
192 $styleArray = $this->getStyleArray(['fillType' => $pValue]);
193 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
194 } else {
195 $this->fillType = $pValue;
196 }
197
198 return $this;
199 }
200
206 public function getRotation()
207 {
208 if ($this->isSupervisor) {
209 return $this->getSharedComponent()->getRotation();
210 }
211
212 return $this->rotation;
213 }
214
222 public function setRotation($pValue)
223 {
224 if ($this->isSupervisor) {
225 $styleArray = $this->getStyleArray(['rotation' => $pValue]);
226 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
227 } else {
228 $this->rotation = $pValue;
229 }
230
231 return $this;
232 }
233
239 public function getStartColor()
240 {
241 return $this->startColor;
242 }
243
249 public function setStartColor(Color $pValue)
250 {
251 // make sure parameter is a real color and not a supervisor
252 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
253
254 if ($this->isSupervisor) {
255 $styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]);
256 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
257 } else {
258 $this->startColor = $color;
259 }
260
261 return $this;
262 }
263
269 public function getEndColor()
270 {
271 return $this->endColor;
272 }
273
279 public function setEndColor(Color $pValue)
280 {
281 // make sure parameter is a real color and not a supervisor
282 $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
283
284 if ($this->isSupervisor) {
285 $styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]);
286 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
287 } else {
288 $this->endColor = $color;
289 }
290
291 return $this;
292 }
293
299 public function getHashCode()
300 {
301 if ($this->isSupervisor) {
302 return $this->getSharedComponent()->getHashCode();
303 }
304 // Note that we don't care about colours for fill type NONE, but could have duplicate NONEs with
305 // different hashes if we don't explicitly prevent this
306 return md5(
307 $this->getFillType() .
308 $this->getRotation() .
309 ($this->getFillType() !== self::FILL_NONE ? $this->getStartColor()->getHashCode() : '') .
310 ($this->getFillType() !== self::FILL_NONE ? $this->getEndColor()->getHashCode() : '') .
311 __CLASS__
312 );
313 }
314
315 protected function exportArray1(): array
316 {
317 $exportedArray = [];
318 $this->exportArray2($exportedArray, 'endColor', $this->getEndColor());
319 $this->exportArray2($exportedArray, 'fillType', $this->getFillType());
320 $this->exportArray2($exportedArray, 'rotation', $this->getRotation());
321 $this->exportArray2($exportedArray, 'startColor', $this->getStartColor());
322
323 return $exportedArray;
324 }
325}
An exception for terminatinating execution or to throw for unit testing.
setFillType($pValue)
Set Fill Type.
Definition: Fill.php:189
setStartColor(Color $pValue)
Set Start Color.
Definition: Fill.php:249
setEndColor(Color $pValue)
Set End Color.
Definition: Fill.php:279
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
Definition: Fill.php:103
getStartColor()
Get Start Color.
Definition: Fill.php:239
setRotation($pValue)
Set Rotation.
Definition: Fill.php:222
exportArray1()
Abstract method to be implemented in anything which extends this class.
Definition: Fill.php:315
__construct($isSupervisor=false, $isConditional=false)
Create a new Fill.
Definition: Fill.php:78
getStyleArray($array)
Build style array from subcomponents.
Definition: Fill.php:115
applyFromArray(array $pStyles)
Apply styles from array.
Definition: Fill.php:142
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
getIsSupervisor()
Is this a supervisor or a cell style component?
Definition: Supervisor.php:66
exportArray2(array &$exportedArray, string $index, $objOrValue)
Populate array from exportArray1.
Definition: Supervisor.php:150