ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Borders.php
Go to the documentation of this file.
1<?php
2
4
5use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
6
7class Borders extends Supervisor
8{
9 // Diagonal directions
10 const DIAGONAL_NONE = 0;
11 const DIAGONAL_UP = 1;
12 const DIAGONAL_DOWN = 2;
13 const DIAGONAL_BOTH = 3;
14
20 protected $left;
21
27 protected $right;
28
34 protected $top;
35
41 protected $bottom;
42
48 protected $diagonal;
49
56
62 protected $allBorders;
63
69 protected $outline;
70
76 protected $inside;
77
83 protected $vertical;
84
90 protected $horizontal;
91
99 public function __construct($isSupervisor = false)
100 {
101 // Supervisor?
102 parent::__construct($isSupervisor);
103
104 // Initialise values
105 $this->left = new Border($isSupervisor);
106 $this->right = new Border($isSupervisor);
107 $this->top = new Border($isSupervisor);
108 $this->bottom = new Border($isSupervisor);
109 $this->diagonal = new Border($isSupervisor);
110 $this->diagonalDirection = self::DIAGONAL_NONE;
111
112 // Specially for supervisor
113 if ($isSupervisor) {
114 // Initialize pseudo-borders
115 $this->allBorders = new Border(true);
116 $this->outline = new Border(true);
117 $this->inside = new Border(true);
118 $this->vertical = new Border(true);
119 $this->horizontal = new Border(true);
120
121 // bind parent if we are a supervisor
122 $this->left->bindParent($this, 'left');
123 $this->right->bindParent($this, 'right');
124 $this->top->bindParent($this, 'top');
125 $this->bottom->bindParent($this, 'bottom');
126 $this->diagonal->bindParent($this, 'diagonal');
127 $this->allBorders->bindParent($this, 'allBorders');
128 $this->outline->bindParent($this, 'outline');
129 $this->inside->bindParent($this, 'inside');
130 $this->vertical->bindParent($this, 'vertical');
131 $this->horizontal->bindParent($this, 'horizontal');
132 }
133 }
134
141 public function getSharedComponent()
142 {
143 return $this->parent->getSharedComponent()->getBorders();
144 }
145
153 public function getStyleArray($array)
154 {
155 return ['borders' => $array];
156 }
157
197 public function applyFromArray(array $pStyles)
198 {
199 if ($this->isSupervisor) {
200 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
201 } else {
202 if (isset($pStyles['left'])) {
203 $this->getLeft()->applyFromArray($pStyles['left']);
204 }
205 if (isset($pStyles['right'])) {
206 $this->getRight()->applyFromArray($pStyles['right']);
207 }
208 if (isset($pStyles['top'])) {
209 $this->getTop()->applyFromArray($pStyles['top']);
210 }
211 if (isset($pStyles['bottom'])) {
212 $this->getBottom()->applyFromArray($pStyles['bottom']);
213 }
214 if (isset($pStyles['diagonal'])) {
215 $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
216 }
217 if (isset($pStyles['diagonalDirection'])) {
218 $this->setDiagonalDirection($pStyles['diagonalDirection']);
219 }
220 if (isset($pStyles['allBorders'])) {
221 $this->getLeft()->applyFromArray($pStyles['allBorders']);
222 $this->getRight()->applyFromArray($pStyles['allBorders']);
223 $this->getTop()->applyFromArray($pStyles['allBorders']);
224 $this->getBottom()->applyFromArray($pStyles['allBorders']);
225 }
226 }
227
228 return $this;
229 }
230
236 public function getLeft()
237 {
238 return $this->left;
239 }
240
246 public function getRight()
247 {
248 return $this->right;
249 }
250
256 public function getTop()
257 {
258 return $this->top;
259 }
260
266 public function getBottom()
267 {
268 return $this->bottom;
269 }
270
276 public function getDiagonal()
277 {
278 return $this->diagonal;
279 }
280
286 public function getAllBorders()
287 {
288 if (!$this->isSupervisor) {
289 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
290 }
291
292 return $this->allBorders;
293 }
294
300 public function getOutline()
301 {
302 if (!$this->isSupervisor) {
303 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
304 }
305
306 return $this->outline;
307 }
308
314 public function getInside()
315 {
316 if (!$this->isSupervisor) {
317 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
318 }
319
320 return $this->inside;
321 }
322
328 public function getVertical()
329 {
330 if (!$this->isSupervisor) {
331 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
332 }
333
334 return $this->vertical;
335 }
336
342 public function getHorizontal()
343 {
344 if (!$this->isSupervisor) {
345 throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
346 }
347
348 return $this->horizontal;
349 }
350
356 public function getDiagonalDirection()
357 {
358 if ($this->isSupervisor) {
359 return $this->getSharedComponent()->getDiagonalDirection();
360 }
361
363 }
364
372 public function setDiagonalDirection($pValue)
373 {
374 if ($pValue == '') {
375 $pValue = self::DIAGONAL_NONE;
376 }
377 if ($this->isSupervisor) {
378 $styleArray = $this->getStyleArray(['diagonalDirection' => $pValue]);
379 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
380 } else {
381 $this->diagonalDirection = $pValue;
382 }
383
384 return $this;
385 }
386
392 public function getHashCode()
393 {
394 if ($this->isSupervisor) {
395 return $this->getSharedComponent()->getHashcode();
396 }
397
398 return md5(
399 $this->getLeft()->getHashCode() .
400 $this->getRight()->getHashCode() .
401 $this->getTop()->getHashCode() .
402 $this->getBottom()->getHashCode() .
403 $this->getDiagonal()->getHashCode() .
404 $this->getDiagonalDirection() .
405 __CLASS__
406 );
407 }
408
409 protected function exportArray1(): array
410 {
411 $exportedArray = [];
412 $this->exportArray2($exportedArray, 'bottom', $this->getBottom());
413 $this->exportArray2($exportedArray, 'diagonal', $this->getDiagonal());
414 $this->exportArray2($exportedArray, 'diagonalDirection', $this->getDiagonalDirection());
415 $this->exportArray2($exportedArray, 'left', $this->getLeft());
416 $this->exportArray2($exportedArray, 'right', $this->getRight());
417 $this->exportArray2($exportedArray, 'top', $this->getTop());
418
419 return $exportedArray;
420 }
421}
An exception for terminatinating execution or to throw for unit testing.
exportArray1()
Abstract method to be implemented in anything which extends this class.
Definition: Borders.php:409
getHorizontal()
Get Horizontal (pseudo-border).
Definition: Borders.php:342
__construct($isSupervisor=false)
Create a new Borders.
Definition: Borders.php:99
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
Definition: Borders.php:141
getStyleArray($array)
Build style array from subcomponents.
Definition: Borders.php:153
getVertical()
Get Vertical (pseudo-border).
Definition: Borders.php:328
setDiagonalDirection($pValue)
Set DiagonalDirection.
Definition: Borders.php:372
applyFromArray(array $pStyles)
Apply styles from array.
Definition: Borders.php:197
getDiagonalDirection()
Get DiagonalDirection.
Definition: Borders.php:356
getOutline()
Get Outline (pseudo-border).
Definition: Borders.php:300
getInside()
Get Inside (pseudo-border).
Definition: Borders.php:314
getAllBorders()
Get AllBorders (pseudo-border).
Definition: Borders.php:286
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
margin left
Definition: langcheck.php:164