1 | <?php |
||
30 | class Borders extends Supervisor implements IComparable |
||
31 | { |
||
32 | /* Diagonal directions */ |
||
33 | const DIAGONAL_NONE = 0; |
||
34 | const DIAGONAL_UP = 1; |
||
35 | const DIAGONAL_DOWN = 2; |
||
36 | const DIAGONAL_BOTH = 3; |
||
37 | |||
38 | /** |
||
39 | * Left. |
||
40 | * |
||
41 | * @var Border |
||
42 | */ |
||
43 | protected $left; |
||
44 | |||
45 | /** |
||
46 | * Right. |
||
47 | * |
||
48 | * @var Border |
||
49 | */ |
||
50 | protected $right; |
||
51 | |||
52 | /** |
||
53 | * Top. |
||
54 | * |
||
55 | * @var Border |
||
56 | */ |
||
57 | protected $top; |
||
58 | |||
59 | /** |
||
60 | * Bottom. |
||
61 | * |
||
62 | * @var Border |
||
63 | */ |
||
64 | protected $bottom; |
||
65 | |||
66 | /** |
||
67 | * Diagonal. |
||
68 | * |
||
69 | * @var Border |
||
70 | */ |
||
71 | protected $diagonal; |
||
72 | |||
73 | /** |
||
74 | * DiagonalDirection. |
||
75 | * |
||
76 | * @var int |
||
77 | */ |
||
78 | protected $diagonalDirection; |
||
79 | |||
80 | /** |
||
81 | * All borders pseudo-border. Only applies to supervisor. |
||
82 | * |
||
83 | * @var Border |
||
84 | */ |
||
85 | protected $allBorders; |
||
86 | |||
87 | /** |
||
88 | * Outline pseudo-border. Only applies to supervisor. |
||
89 | * |
||
90 | * @var Border |
||
91 | */ |
||
92 | protected $outline; |
||
93 | |||
94 | /** |
||
95 | * Inside pseudo-border. Only applies to supervisor. |
||
96 | * |
||
97 | * @var Border |
||
98 | */ |
||
99 | protected $inside; |
||
100 | |||
101 | /** |
||
102 | * Vertical pseudo-border. Only applies to supervisor. |
||
103 | * |
||
104 | * @var Border |
||
105 | */ |
||
106 | protected $vertical; |
||
107 | |||
108 | /** |
||
109 | * Horizontal pseudo-border. Only applies to supervisor. |
||
110 | * |
||
111 | * @var Border |
||
112 | */ |
||
113 | protected $horizontal; |
||
114 | |||
115 | /** |
||
116 | * Create a new Borders. |
||
117 | * |
||
118 | * @param bool $isSupervisor Flag indicating if this is a supervisor or not |
||
119 | * Leave this value at default unless you understand exactly what |
||
120 | * its ramifications are |
||
121 | * @param bool $isConditional Flag indicating if this is a conditional style or not |
||
122 | * Leave this value at default unless you understand exactly what |
||
123 | * its ramifications are |
||
124 | */ |
||
125 | 80 | public function __construct($isSupervisor = false, $isConditional = false) |
|
126 | { |
||
127 | // Supervisor? |
||
128 | 80 | parent::__construct($isSupervisor); |
|
129 | |||
130 | // Initialise values |
||
131 | 80 | $this->left = new Border($isSupervisor, $isConditional); |
|
132 | 80 | $this->right = new Border($isSupervisor, $isConditional); |
|
133 | 80 | $this->top = new Border($isSupervisor, $isConditional); |
|
134 | 80 | $this->bottom = new Border($isSupervisor, $isConditional); |
|
135 | 80 | $this->diagonal = new Border($isSupervisor, $isConditional); |
|
136 | 80 | $this->diagonalDirection = self::DIAGONAL_NONE; |
|
137 | |||
138 | // Specially for supervisor |
||
139 | 80 | if ($isSupervisor) { |
|
140 | // Initialize pseudo-borders |
||
141 | 80 | $this->allBorders = new Border(true); |
|
142 | 80 | $this->outline = new Border(true); |
|
143 | 80 | $this->inside = new Border(true); |
|
144 | 80 | $this->vertical = new Border(true); |
|
145 | 80 | $this->horizontal = new Border(true); |
|
146 | |||
147 | // bind parent if we are a supervisor |
||
148 | 80 | $this->left->bindParent($this, 'left'); |
|
149 | 80 | $this->right->bindParent($this, 'right'); |
|
150 | 80 | $this->top->bindParent($this, 'top'); |
|
151 | 80 | $this->bottom->bindParent($this, 'bottom'); |
|
152 | 80 | $this->diagonal->bindParent($this, 'diagonal'); |
|
153 | 80 | $this->allBorders->bindParent($this, 'allBorders'); |
|
154 | 80 | $this->outline->bindParent($this, 'outline'); |
|
155 | 80 | $this->inside->bindParent($this, 'inside'); |
|
156 | 80 | $this->vertical->bindParent($this, 'vertical'); |
|
157 | 80 | $this->horizontal->bindParent($this, 'horizontal'); |
|
158 | } |
||
159 | 80 | } |
|
160 | |||
161 | /** |
||
162 | * Get the shared style component for the currently active cell in currently active sheet. |
||
163 | * Only used for style supervisor. |
||
164 | * |
||
165 | * @return Borders |
||
166 | */ |
||
167 | 1 | public function getSharedComponent() |
|
168 | { |
||
169 | 1 | return $this->parent->getSharedComponent()->getBorders(); |
|
170 | } |
||
171 | |||
172 | /** |
||
173 | * Build style array from subcomponents. |
||
174 | * |
||
175 | * @param array $array |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | 1 | public function getStyleArray($array) |
|
180 | { |
||
181 | 1 | return ['borders' => $array]; |
|
182 | } |
||
183 | |||
184 | /** |
||
185 | * Apply styles from array. |
||
186 | * <code> |
||
187 | * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( |
||
188 | * array( |
||
189 | * 'bottom' => array( |
||
190 | * 'borderStyle' => Border::BORDER_DASHDOT, |
||
191 | * 'color' => array( |
||
192 | * 'rgb' => '808080' |
||
193 | * ) |
||
194 | * ), |
||
195 | * 'top' => array( |
||
196 | * 'borderStyle' => Border::BORDER_DASHDOT, |
||
197 | * 'color' => array( |
||
198 | * 'rgb' => '808080' |
||
199 | * ) |
||
200 | * ) |
||
201 | * ) |
||
202 | * ); |
||
203 | * </code> |
||
204 | * <code> |
||
205 | * $spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray( |
||
206 | * array( |
||
207 | * 'allBorders' => array( |
||
208 | * 'borderStyle' => Border::BORDER_DASHDOT, |
||
209 | * 'color' => array( |
||
210 | * 'rgb' => '808080' |
||
211 | * ) |
||
212 | * ) |
||
213 | * ) |
||
214 | * ); |
||
215 | * </code>. |
||
216 | * |
||
217 | * @param array $pStyles Array containing style information |
||
218 | * |
||
219 | * @throws PhpSpreadsheetException |
||
220 | * |
||
221 | * @return Borders |
||
222 | */ |
||
223 | 18 | public function applyFromArray(array $pStyles) |
|
256 | |||
257 | /** |
||
258 | * Get Left. |
||
259 | * |
||
260 | * @return Border |
||
261 | */ |
||
262 | 71 | public function getLeft() |
|
266 | |||
267 | /** |
||
268 | * Get Right. |
||
269 | * |
||
270 | * @return Border |
||
271 | */ |
||
272 | 71 | public function getRight() |
|
276 | |||
277 | /** |
||
278 | * Get Top. |
||
279 | * |
||
280 | * @return Border |
||
281 | */ |
||
282 | 71 | public function getTop() |
|
286 | |||
287 | /** |
||
288 | * Get Bottom. |
||
289 | * |
||
290 | * @return Border |
||
291 | */ |
||
292 | 71 | public function getBottom() |
|
296 | |||
297 | /** |
||
298 | * Get Diagonal. |
||
299 | * |
||
300 | * @return Border |
||
301 | */ |
||
302 | 71 | public function getDiagonal() |
|
306 | |||
307 | /** |
||
308 | * Get AllBorders (pseudo-border). Only applies to supervisor. |
||
309 | * |
||
310 | * @throws PhpSpreadsheetException |
||
311 | * |
||
312 | * @return Border |
||
313 | */ |
||
314 | 1 | public function getAllBorders() |
|
315 | { |
||
316 | 1 | if (!$this->isSupervisor) { |
|
317 | throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.'); |
||
318 | } |
||
319 | |||
320 | 1 | return $this->allBorders; |
|
321 | } |
||
322 | |||
323 | /** |
||
324 | * Get Outline (pseudo-border). Only applies to supervisor. |
||
325 | * |
||
326 | * @throws PhpSpreadsheetException |
||
327 | * |
||
328 | * @return Border |
||
329 | */ |
||
330 | public function getOutline() |
||
338 | |||
339 | /** |
||
340 | * Get Inside (pseudo-border). Only applies to supervisor. |
||
341 | * |
||
342 | * @throws PhpSpreadsheetException |
||
343 | * |
||
344 | * @return Border |
||
345 | */ |
||
346 | public function getInside() |
||
354 | |||
355 | /** |
||
356 | * Get Vertical (pseudo-border). Only applies to supervisor. |
||
357 | * |
||
358 | * @throws PhpSpreadsheetException |
||
359 | * |
||
360 | * @return Border |
||
361 | */ |
||
362 | public function getVertical() |
||
370 | |||
371 | /** |
||
372 | * Get Horizontal (pseudo-border). Only applies to supervisor. |
||
373 | * |
||
374 | * @throws PhpSpreadsheetException |
||
375 | * |
||
376 | * @return Border |
||
377 | */ |
||
378 | public function getHorizontal() |
||
386 | |||
387 | /** |
||
388 | * Get DiagonalDirection. |
||
389 | * |
||
390 | * @return int |
||
391 | */ |
||
392 | 71 | public function getDiagonalDirection() |
|
400 | |||
401 | /** |
||
402 | * Set DiagonalDirection. |
||
403 | * |
||
404 | * @param int $pValue see self::DIAGONAL_* |
||
405 | * |
||
406 | * @return Borders |
||
407 | */ |
||
408 | 13 | public function setDiagonalDirection($pValue) |
|
422 | |||
423 | /** |
||
424 | * Get hash code. |
||
425 | * |
||
426 | * @return string Hash code |
||
427 | */ |
||
428 | 70 | public function getHashCode() |
|
444 | } |
||
445 |