Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.74% covered (success)
94.74%
36 / 38
93.75% covered (success)
93.75%
15 / 16
CRAP
0.00% covered (danger)
0.00%
0 / 1
Slide
94.74% covered (success)
94.74%
36 / 38
93.75% covered (success)
93.75%
15 / 16
20.06
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 getSlideLayout
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSlideLayout
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSlideMasterId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSlideMasterId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 __clone
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
3.33
 copy
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getNote
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNote
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 isVisible
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIsVisible
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addAnimation
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getAnimations
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAnimations
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
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 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation;
21
22use PhpOffice\PhpPresentation\Slide\AbstractSlide;
23use PhpOffice\PhpPresentation\Slide\Note;
24use PhpOffice\PhpPresentation\Slide\SlideLayout;
25
26/**
27 * Slide class.
28 */
29class Slide extends AbstractSlide implements ComparableInterface, ShapeContainerInterface
30{
31    /**
32     * The slide is shown in presentation.
33     *
34     * @var bool
35     */
36    protected $isVisible = true;
37
38    /**
39     * Slide layout.
40     *
41     * @var null|SlideLayout
42     */
43    private $slideLayout;
44
45    /**
46     * Slide master id.
47     *
48     * @var int
49     */
50    private $slideMasterId = 1;
51
52    /**
53     * @var Note
54     */
55    private $slideNote;
56
57    /**
58     * @var \PhpOffice\PhpPresentation\Slide\Animation[]
59     */
60    protected $animations = [];
61
62    /**
63     * Name of the title.
64     *
65     * @var null|string
66     */
67    protected $name;
68
69    /**
70     * Create a new slide.
71     */
72    public function __construct(?PhpPresentation $pParent = null)
73    {
74        // Set parent
75        $this->parent = $pParent;
76        // Set identifier
77        $this->identifier = md5(mt_rand(0, mt_getrandmax()) . time());
78        // Set Slide Layout
79        if ($this->parent instanceof PhpPresentation) {
80            $arrayMasterSlides = $this->parent->getAllMasterSlides();
81            $oMasterSlide = reset($arrayMasterSlides);
82            $arraySlideLayouts = $oMasterSlide->getAllSlideLayouts();
83            $oSlideLayout = reset($arraySlideLayouts);
84            $this->setSlideLayout($oSlideLayout);
85        }
86        // Set note
87        $this->setNote(new Note());
88    }
89
90    /**
91     * Get slide layout.
92     */
93    public function getSlideLayout(): ?SlideLayout
94    {
95        return $this->slideLayout;
96    }
97
98    /**
99     * Set slide layout.
100     */
101    public function setSlideLayout(SlideLayout $layout): self
102    {
103        $this->slideLayout = $layout;
104
105        return $this;
106    }
107
108    /**
109     * Get slide master id.
110     *
111     * @return int
112     */
113    public function getSlideMasterId()
114    {
115        return $this->slideMasterId;
116    }
117
118    /**
119     * Set slide master id.
120     *
121     * @param int $masterId
122     *
123     * @return Slide
124     */
125    public function setSlideMasterId($masterId = 1)
126    {
127        $this->slideMasterId = $masterId;
128
129        return $this;
130    }
131
132    public function __clone()
133    {
134        // Set parent
135        $this->parent = clone $this->parent;
136        // Shape collection
137        foreach ($this->shapeCollection as &$shape) {
138            $shape = clone $shape;
139        }
140        // Transition
141        if (isset($this->slideTransition)) {
142            $this->slideTransition = clone $this->slideTransition;
143        }
144        // Note
145        $this->slideNote = clone $this->slideNote;
146    }
147
148    /**
149     * Copy slide (!= clone!).
150     *
151     * @return Slide
152     */
153    public function copy()
154    {
155        $copied = clone $this;
156
157        return $copied;
158    }
159
160    public function getNote(): Note
161    {
162        return $this->slideNote;
163    }
164
165    public function setNote(?Note $note = null): self
166    {
167        $this->slideNote = (null === $note ? new Note() : $note);
168        $this->slideNote->setParent($this);
169
170        return $this;
171    }
172
173    /**
174     * Get the name of the slide.
175     */
176    public function getName(): ?string
177    {
178        return $this->name;
179    }
180
181    /**
182     * Set the name of the slide.
183     */
184    public function setName(?string $name = null): self
185    {
186        $this->name = $name;
187
188        return $this;
189    }
190
191    /**
192     * @return bool
193     */
194    public function isVisible()
195    {
196        return $this->isVisible;
197    }
198
199    /**
200     * @param bool $value
201     *
202     * @return Slide
203     */
204    public function setIsVisible($value = true)
205    {
206        $this->isVisible = (bool) $value;
207
208        return $this;
209    }
210
211    /**
212     * Add an animation to the slide.
213     *
214     * @param Slide\Animation $animation
215     *
216     * @return Slide
217     */
218    public function addAnimation($animation)
219    {
220        $this->animations[] = $animation;
221
222        return $this;
223    }
224
225    /**
226     * Get collection of animations.
227     *
228     * @return \PhpOffice\PhpPresentation\Slide\Animation[]
229     */
230    public function getAnimations()
231    {
232        return $this->animations;
233    }
234
235    /**
236     * Set collection of animations.
237     *
238     * @param \PhpOffice\PhpPresentation\Slide\Animation[] $array
239     *
240     * @return Slide
241     */
242    public function setAnimations(array $array = [])
243    {
244        $this->animations = $array;
245
246        return $this;
247    }
248}