Completed
Pull Request — develop (#197)
by Franck
17:03
created

Slide::setIsVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation;
19
20
use PhpOffice\PhpPresentation\GeometryCalculator;
21
use PhpOffice\PhpPresentation\Shape\Chart;
22
use PhpOffice\PhpPresentation\Shape\Drawing;
23
use PhpOffice\PhpPresentation\Shape\Group;
24
use PhpOffice\PhpPresentation\Shape\Line;
25
use PhpOffice\PhpPresentation\Shape\RichText;
26
use PhpOffice\PhpPresentation\Shape\Table;
27
use PhpOffice\PhpPresentation\Slide\AbstractBackground;
28
use PhpOffice\PhpPresentation\Slide\Layout;
29
use PhpOffice\PhpPresentation\Slide\Note;
30
use PhpOffice\PhpPresentation\Slide\Transition;
31
32
/**
33
 * Slide class
34
 */
35
class Slide implements ComparableInterface, ShapeContainerInterface
36
{
37
    /**
38
     * The slide is shown in presentation
39
     * @var bool
40
     */
41
    protected $isVisible = true;
42
43
    /**
44
     * Parent presentation
45
     *
46
     * @var PhpPresentation
47
     */
48
    private $parent;
49
50
    /**
51
     * Collection of shapes
52
     *
53
     * @var \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
54
     */
55
    private $shapeCollection = null;
56
57
    /**
58
     * Slide identifier
59
     *
60
     * @var string
61
     */
62
    private $identifier;
63
64
    /**
65
     * Slide layout
66
     *
67
     * @var string
68
     */
69
    private $slideLayout;
70
71
    /**
72
     * Slide master id
73
     *
74
     * @var integer
75
     */
76
    private $slideMasterId = 1;
77
78
    /**
79
     *
80
     * @var \PhpOffice\PhpPresentation\Slide\Note
81
     */
82
    private $slideNote;
83
84
    /**
85
     *
86
     * @var \PhpOffice\PhpPresentation\Slide\Transition
87
     */
88
    private $slideTransition;
89
    
90
    /**
91
     * Hash index
92
     *
93
     * @var string
94
     */
95
    private $hashIndex;
96
97
    /**
98
     * Offset X
99
     *
100
     * @var int
101
     */
102
    protected $offsetX;
103
104
    /**
105
     * Offset Y
106
     *
107
     * @var int
108
     */
109
    protected $offsetY;
110
111
    /**
112
     * Extent X
113
     *
114
     * @var int
115
     */
116
    protected $extentX;
117
118
    /**
119
     * Extent Y
120
     *
121
     * @var int
122
     */
123
    protected $extentY;
124
125
    /**
126
     * Name of the title
127
     *
128
     * @var string
129
     */
130
    protected $name;
131
132
    /**
133
     * Background of the slide
134
     *
135
     * @var AbstractBackground
136
     */
137 199
    protected $background;
138
139
    /**
140 199
     * Create a new slide
141
     *
142 199
     * @param PhpPresentation $pParent
143
     */
144
    public function __construct(PhpPresentation $pParent = null)
145 199
    {
146
        // Set parent
147
        $this->parent = $pParent;
148 199
149 199
        $this->slideLayout = Slide\Layout::BLANK;
150
151
        // Shape collection
152
        $this->shapeCollection = new \ArrayObject();
153
154
        // Set identifier
155
        $this->identifier = md5(rand(0, 9999) . time());
156 169
    }
157
158 169
    /**
159
     * Get collection of shapes
160
     *
161
     * @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
162
     */
163
    public function getShapeCollection()
164
    {
165
        return $this->shapeCollection;
166
    }
167 137
168
    /**
169 137
     * Add shape to slide
170
     *
171 137
     * @param  \PhpOffice\PhpPresentation\AbstractShape $shape
172
     * @return \PhpOffice\PhpPresentation\AbstractShape
173
     */
174
    public function addShape(AbstractShape $shape)
175
    {
176
        $shape->setContainer($this);
177
178
        return $shape;
179 41
    }
180
181 41
    /**
182 41
     * Create rich text shape
183
     *
184 41
     * @return \PhpOffice\PhpPresentation\Shape\RichText
185
     */
186
    public function createRichTextShape()
187
    {
188
        $shape = new RichText();
189
        $this->addShape($shape);
190
191
        return $shape;
192
    }
193
194
    /**
195
     * Create line shape
196 2
     *
197
     * @param  int                      $fromX Starting point x offset
198 2
     * @param  int                      $fromY Starting point y offset
199 2
     * @param  int                      $toX   Ending point x offset
200
     * @param  int                      $toY   Ending point y offset
201 2
     * @return \PhpOffice\PhpPresentation\Shape\Line
202
     */
203
    public function createLineShape($fromX, $fromY, $toX, $toY)
204
    {
205
        $shape = new Line($fromX, $fromY, $toX, $toY);
206
        $this->addShape($shape);
207
208
        return $shape;
209 46
    }
210
211 46
    /**
212 46
     * Create chart shape
213
     *
214 46
     * @return \PhpOffice\PhpPresentation\Shape\Chart
215
     */
216
    public function createChartShape()
217
    {
218
        $shape = new Chart();
219
        $this->addShape($shape);
220
221
        return $shape;
222 19
    }
223
224 19
    /**
225 19
     * Create drawing shape
226
     *
227 19
     * @return \PhpOffice\PhpPresentation\Shape\Drawing
228
     */
229
    public function createDrawingShape()
230
    {
231
        $shape = new Drawing();
232
        $this->addShape($shape);
233
234
        return $shape;
235
    }
236 16
237
    /**
238 16
     * Create table shape
239 16
     *
240
     * @param  int                       $columns Number of columns
241 16
     * @return \PhpOffice\PhpPresentation\Shape\Table
242
     */
243
    public function createTableShape($columns = 1)
244
    {
245
        $shape = new Table($columns);
246
        $this->addShape($shape);
247
248
        return $shape;
249 2
    }
250
    
251 2
    /**
252 2
     * Creates a group within this slide
253
     *
254 2
     * @return \PhpOffice\PhpPresentation\Shape\Group
255
     */
256
    public function createGroup()
257
    {
258
        $shape = new Group();
259
        $this->addShape($shape);
260
        
261
        return $shape;
262 93
    }
263
264 93
    /**
265
     * Get parent
266
     *
267
     * @return PhpPresentation
268
     */
269
    public function getParent()
270
    {
271
        return $this->parent;
272
    }
273 2
274
    /**
275 2
     * Re-bind parent
276 2
     *
277
     * @param  \PhpOffice\PhpPresentation\PhpPresentation       $parent
278 2
     * @return \PhpOffice\PhpPresentation\Slide
279
     */
280
    public function rebindParent(PhpPresentation $parent)
281
    {
282
        $this->parent->removeSlideByIndex($this->parent->getIndex($this));
283
        $this->parent = $parent;
284
285
        return $this;
286 93
    }
287
288 93
    /**
289
     * Get slide layout
290
     *
291
     * @return string
292
     */
293
    public function getSlideLayout()
294
    {
295
        return $this->slideLayout;
296
    }
297 4
298
    /**
299 4
     * Set slide layout
300
     *
301 4
     * @param  string              $layout
302
     * @return \PhpOffice\PhpPresentation\Slide
303
     */
304
    public function setSlideLayout($layout = Layout::BLANK)
305
    {
306
        $this->slideLayout = $layout;
307
308
        return $this;
309 96
    }
310
311 96
    /**
312
     * Get slide master id
313
     *
314
     * @return int
315
     */
316
    public function getSlideMasterId()
317
    {
318
        return $this->slideMasterId;
319
    }
320 1
321
    /**
322 1
     * Set slide master id
323
     *
324 1
     * @param  int                 $masterId
325
     * @return \PhpOffice\PhpPresentation\Slide
326
     */
327
    public function setSlideMasterId($masterId = 1)
328
    {
329
        $this->slideMasterId = $masterId;
330
331
        return $this;
332 131
    }
333
334 131
    /**
335
     * Get hash code
336
     *
337
     * @return string Hash code
338
     */
339
    public function getHashCode()
340
    {
341
        return md5($this->identifier . __CLASS__);
342
    }
343
344
    /**
345 4
     * Get hash index
346
     *
347 4
     * Note that this index may vary during script execution! Only reliable moment is
348
     * while doing a write of a workbook and when changes are not allowed.
349
     *
350
     * @return string Hash index
351
     */
352
    public function getHashIndex()
353
    {
354
        return $this->hashIndex;
355
    }
356
357
    /**
358 4
     * Set hash index
359
     *
360 4
     * Note that this index may vary during script execution! Only reliable moment is
361 4
     * while doing a write of a workbook and when changes are not allowed.
362
     *
363
     * @param string $value Hash index
364
     */
365
    public function setHashIndex($value)
366
    {
367
        $this->hashIndex = $value;
368 1
    }
369
370 1
    /**
371
     * Copy slide (!= clone!)
372 1
     *
373
     * @return \PhpOffice\PhpPresentation\Slide
374
     */
375
    public function copy()
376
    {
377
        $copied = clone $this;
378
379
        return $copied;
380 93
    }
381
382 93
    /**
383 93
     * Get X Offset
384 93
     *
385 93
     * @return int
386
     */
387 93
    public function getOffsetX()
388
    {
389
        if ($this->offsetX === null) {
390
            $offsets = GeometryCalculator::calculateOffsets($this);
391
            $this->offsetX = $offsets[GeometryCalculator::X];
392
            $this->offsetY = $offsets[GeometryCalculator::Y];
393
        }
394
        return $this->offsetX;
395 93
    }
396
397 93
    /**
398 1
     * Get Y Offset
399 1
     *
400 1
     * @return int
401
     */
402 93
    public function getOffsetY()
403
    {
404
        if ($this->offsetY === null) {
405
            $offsets = GeometryCalculator::calculateOffsets($this);
406
            $this->offsetX = $offsets[GeometryCalculator::X];
407
            $this->offsetY = $offsets[GeometryCalculator::Y];
408
        }
409
        return $this->offsetY;
410 93
    }
411
412 93
    /**
413 93
     * Get X Extent
414 93
     *
415 93
     * @return int
416
     */
417 93
    public function getExtentX()
418
    {
419
        if ($this->extentX === null) {
420
            $extents = GeometryCalculator::calculateExtents($this);
421
            $this->extentX = $extents[GeometryCalculator::X];
422
            $this->extentY = $extents[GeometryCalculator::Y];
423
        }
424
        return $this->extentX;
425 93
    }
426
427 93
    /**
428 1
     * Get Y Extent
429 1
     *
430 1
     * @return int
431
     */
432 93
    public function getExtentY()
433
    {
434
        if ($this->extentY === null) {
435
            $extents = GeometryCalculator::calculateExtents($this);
436
            $this->extentX = $extents[GeometryCalculator::X];
437
            $this->extentY = $extents[GeometryCalculator::Y];
438
        }
439 152
        return $this->extentY;
440
    }
441 152
442 152
    /**
443
     *
444 152
     * @return \PhpOffice\PhpPresentation\Slide\Note
445
     */
446
    public function getNote()
447
    {
448
        if (is_null($this->slideNote)) {
449
            $this->setNote();
450
        }
451
        return $this->slideNote;
452 153
    }
453
454 153
    /**
455 153
     *
456
     * @param \PhpOffice\PhpPresentation\Slide\Note $note
457 153
     * @return \PhpOffice\PhpPresentation\Slide
458
     */
459
    public function setNote(Note $note = null)
460
    {
461
        $this->slideNote = (is_null($note) ? new Note() : $note);
462
        $this->slideNote->setParent($this);
463
464 150
        return $this;
465
    }
466 150
467
    /**
468
     *
469
     * @return \PhpOffice\PhpPresentation\Slide\Transition
470
     */
471
    public function getTransition()
472
    {
473
        return $this->slideTransition;
474 3
    }
475
476 3
    /**
477
     *
478 3
     * @param \PhpOffice\PhpPresentation\Slide\Transition $transition
479
     * @return \PhpOffice\PhpPresentation\Slide
480
     */
481
    public function setTransition(Transition $transition = null)
482
    {
483
        $this->slideTransition = $transition;
484
485 59
        return $this;
486
    }
487 59
488
    /**
489
     * Get the name of the slide
490
     * @return string
491
     */
492
    public function getName()
493
    {
494
        return $this->name;
495 5
    }
496
497 5
    /**
498 5
     * Set the name of the slide
499
     * @param string $name
500
     * @return $this
501
     */
502
    public function setName($name = null)
503
    {
504 150
        $this->name = $name;
505
        return $this;
506 150
    }
507
508
    /**
509
     * @return AbstractBackground
510
     */
511
    public function getBackground()
512
    {
513 5
        return $this->background;
514
    }
515 5
516 5
    /**
517
     * @param AbstractBackground $background
518
     * @return $this
519
     */
520
    public function setBackground(AbstractBackground $background = null)
521
    {
522
        $this->background = $background;
523
        return $this;
524
    }
525
526
    /**
527
     * @return boolean
528
     */
529
    public function isVisible()
530
    {
531
        return $this->isVisible;
532
    }
533
534
    /**
535
     * @param boolean $value
536
     * @return Slide
537
     */
538
    public function setIsVisible($value = true)
539
    {
540
        $this->isVisible = (bool)$value;
541
        return $this;
542
    }
543
}
544