Completed
Pull Request — develop (#208)
by Franck
13:33
created

PhpPresentation   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 364
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Test Coverage

Coverage 90.48%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 32
c 6
b 1
f 0
lcom 3
cbo 5
dl 0
loc 364
ccs 76
cts 84
cp 0.9048
rs 9.6

26 Methods

Rating   Name   Duplication   Size   Complexity  
A getDocumentProperties() 0 4 1
A setDocumentProperties() 0 6 1
A getPresentationProperties() 0 4 1
A setPresentationProperties() 0 5 1
A markAsFinal() 0 4 1
A isMarkedAsFinal() 0 4 1
A setZoom() 0 4 1
A getZoom() 0 4 1
A __construct() 0 11 1
A getProperties() 0 4 1
A setProperties() 0 4 1
A getLayout() 0 4 1
A setLayout() 0 6 1
A getActiveSlide() 0 4 1
A createSlide() 0 6 1
A addSlide() 0 6 1
A removeSlideByIndex() 0 10 2
A getSlide() 0 8 2
A getAllSlides() 0 4 1
A getIndex() 0 11 3
A getSlideCount() 0 4 1
A getActiveSlideIndex() 0 4 1
A setActiveSlideIndex() 0 10 2
A addExternalSlide() 0 6 1
A getSlideIterator() 0 4 1
A copy() 0 12 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\Slide;
21
use PhpOffice\PhpPresentation\Slide\Iterator;
22
23
/**
24
 * PhpPresentation
25
 */
26
class PhpPresentation
27
{
28
    /**
29
     * Document properties
30
     *
31
     * @var \PhpOffice\PhpPresentation\DocumentProperties
32
     */
33
    protected $documentProperties;
34
35
    /**
36
     * Presentation properties
37
     *
38
     * @var \PhpOffice\PhpPresentation\PresentationProperties
39
     */
40
    protected $presentationProps;
41
42
    /**
43
     * Document layout
44
     *
45
     * @var \PhpOffice\PhpPresentation\DocumentLayout
46
     */
47
    protected $layout;
48
49
    /**
50
     * Collection of Slide objects
51
     *
52
     * @var \PhpOffice\PhpPresentation\Slide[]
53
     */
54
    protected $slideCollection = array();
55
56
    /**
57
     * Active slide index
58
     *
59
     * @var int
60
     */
61
    protected $activeSlideIndex = 0;
62
63
    /**
64
     * Create a new PhpPresentation with one Slide
65
     */
66 192
    public function __construct()
67
    {
68
        // Initialise slide collection and add one slide
69 192
        $this->createSlide();
70 192
        $this->setActiveSlideIndex();
71
72
        // Set initial document properties & layout
73 192
        $this->setDocumentProperties(new DocumentProperties());
74 192
        $this->setPresentationProperties(new PresentationProperties());
75 192
        $this->setLayout(new DocumentLayout());
76 192
    }
77
78
    /**
79
     * Get properties
80
     *
81
     * @return \PhpOffice\PhpPresentation\DocumentProperties
82
     * @deprecated for getDocumentProperties
83
     */
84 1
    public function getProperties()
85
    {
86 1
        return $this->getDocumentProperties();
87
    }
88
89
    /**
90
     * Set properties
91
     *
92
     * @param  \PhpOffice\PhpPresentation\DocumentProperties $value
93
     * @deprecated for setDocumentProperties
94
     * @return PhpPresentation
95
     */
96 1
    public function setProperties(DocumentProperties $value)
97
    {
98 1
        return $this->setDocumentProperties($value);
99
    }
100
    
101
    /**
102
     * Get properties
103
     *
104
     * @return \PhpOffice\PhpPresentation\DocumentProperties
105
     */
106 160
    public function getDocumentProperties()
107
    {
108 160
        return $this->documentProperties;
109
    }
110
111
    /**
112
     * Set properties
113
     *
114
     * @param  \PhpOffice\PhpPresentation\DocumentProperties $value
115
     * @return PhpPresentation
116
     */
117 192
    public function setDocumentProperties(DocumentProperties $value)
118
    {
119 192
        $this->documentProperties = $value;
120
121 192
        return $this;
122
    }
123
124
    /**
125
     * Get presentation properties
126
     *
127
     * @return \PhpOffice\PhpPresentation\PresentationProperties
128
     */
129 156
    public function getPresentationProperties()
130
    {
131 156
        return $this->presentationProps;
132
    }
133
134
    /**
135
     * Set presentation properties
136
     *
137
     * @param  \PhpOffice\PhpPresentation\PresentationProperties $value
138
     * @return PhpPresentation
139
     */
140 192
    public function setPresentationProperties(PresentationProperties $value)
141
    {
142 192
        $this->presentationProps = $value;
143 192
        return $this;
144
    }
145
146
    /**
147
     * Get layout
148
     *
149
     * @return \PhpOffice\PhpPresentation\DocumentLayout
150
     */
151 153
    public function getLayout()
152
    {
153 153
        return $this->layout;
154
    }
155
156
    /**
157
     * Set layout
158
     *
159
     * @param  \PhpOffice\PhpPresentation\DocumentLayout $value
160
     * @return PhpPresentation
161
     */
162 192
    public function setLayout(DocumentLayout $value)
163
    {
164 192
        $this->layout = $value;
165
166 192
        return $this;
167
    }
168
169
    /**
170
     * Get active slide
171
     *
172
     * @return \PhpOffice\PhpPresentation\Slide
173
     */
174 192
    public function getActiveSlide()
175
    {
176 192
        return $this->slideCollection[$this->activeSlideIndex];
177
    }
178
179
    /**
180
     * Create slide and add it to this presentation
181
     *
182
     * @return \PhpOffice\PhpPresentation\Slide
183
     */
184 192
    public function createSlide()
185
    {
186 192
        $newSlide = new Slide($this);
187 192
        $this->addSlide($newSlide);
188 192
        return $newSlide;
189
    }
190
191
    /**
192
     * Add slide
193
     *
194
     * @param  \PhpOffice\PhpPresentation\Slide $slide
195
     * @throws \Exception
196
     * @return \PhpOffice\PhpPresentation\Slide
197
     */
198 192
    public function addSlide(Slide $slide = null)
199
    {
200 192
        $this->slideCollection[] = $slide;
201
202 192
        return $slide;
203
    }
204
205
    /**
206
     * Remove slide by index
207
     *
208
     * @param  int           $index Slide index
209
     * @throws \Exception
210
     * @return PhpPresentation
211
     */
212 14
    public function removeSlideByIndex($index = 0)
213
    {
214 14
        if ($index > count($this->slideCollection) - 1) {
215 1
            throw new \Exception("Slide index is out of bounds.");
216
        } else {
217 13
            array_splice($this->slideCollection, $index, 1);
218
        }
219
220 13
        return $this;
221
    }
222
223
    /**
224
     * Get slide by index
225
     *
226
     * @param  int                 $index Slide index
227
     * @return \PhpOffice\PhpPresentation\Slide
228
     * @throws \Exception
229
     */
230 170
    public function getSlide($index = 0)
231
    {
232 170
        if ($index > count($this->slideCollection) - 1) {
233 1
            throw new \Exception("Slide index is out of bounds.");
234
        } else {
235 169
            return $this->slideCollection[$index];
236
        }
237
    }
238
239
    /**
240
     * Get all slides
241
     *
242
     * @return \PhpOffice\PhpPresentation\Slide[]
243
     */
244 160
    public function getAllSlides()
245
    {
246 160
        return $this->slideCollection;
247
    }
248
249
    /**
250
     * Get index for slide
251
     *
252
     * @param  \PhpOffice\PhpPresentation\Slide $slide
253
     * @return int
254
     * @throws \Exception
255
     */
256 98
    public function getIndex(Slide $slide)
257
    {
258 98
        $index = null;
259 98
        foreach ($this->slideCollection as $key => $value) {
260 98
            if ($value->getHashCode() == $slide->getHashCode()) {
261 98
                $index = $key;
262 98
                break;
263
            }
264 98
        }
265 98
        return $index;
266
    }
267
268
    /**
269
     * Get slide count
270
     *
271
     * @return int
272
     */
273 170
    public function getSlideCount()
274
    {
275 170
        return count($this->slideCollection);
276
    }
277
278
    /**
279
     * Get active slide index
280
     *
281
     * @return int Active slide index
282
     */
283 1
    public function getActiveSlideIndex()
284
    {
285 1
        return $this->activeSlideIndex;
286
    }
287
288
    /**
289
     * Set active slide index
290
     *
291
     * @param  int                 $index Active slide index
292
     * @throws \Exception
293
     * @return \PhpOffice\PhpPresentation\Slide
294
     */
295 192
    public function setActiveSlideIndex($index = 0)
296
    {
297 192
        if ($index > count($this->slideCollection) - 1) {
298 1
            throw new \Exception("Active slide index is out of bounds.");
299
        } else {
300 192
            $this->activeSlideIndex = $index;
301
        }
302
303 192
        return $this->getActiveSlide();
304
    }
305
306
    /**
307
     * Add external slide
308
     *
309
     * @param  \PhpOffice\PhpPresentation\Slide $slide External slide to add
310
     * @throws \Exception
311
     * @return \PhpOffice\PhpPresentation\Slide
312
     */
313 1
    public function addExternalSlide(Slide $slide)
314
    {
315 1
        $slide->rebindParent($this);
316
317 1
        return $this->addSlide($slide);
318
    }
319
320
    /**
321
     * Get slide iterator
322
     *
323
     * @return \PhpOffice\PhpPresentation\Slide\Iterator
324
     */
325 1
    public function getSlideIterator()
326
    {
327 1
        return new Iterator($this);
328
    }
329
330
    /**
331
     * Copy presentation (!= clone!)
332
     *
333
     * @return PhpPresentation
334
     */
335 1
    public function copy()
336
    {
337 1
        $copied = clone $this;
338
339 1
        $slideCount = count($this->slideCollection);
340 1
        for ($i = 0; $i < $slideCount; ++$i) {
341 1
            $this->slideCollection[$i] = $this->slideCollection[$i]->copy();
342 1
            $this->slideCollection[$i]->rebindParent($this);
343 1
        }
344
345 1
        return $copied;
346
    }
347
348
    /**
349
     * Mark a document as final
350
     * @param bool $state
351
     * @return PhpPresentation
352
     * @deprecated for getPresentationProperties()->markAsFinal()
353
     */
354
    public function markAsFinal($state = true)
355
    {
356
        return $this->getPresentationProperties()->markAsFinal($state);
357
    }
358
359
    /**
360
     * Return if this document is marked as final
361
     * @return bool
362
     * @deprecated for getPresentationProperties()->isMarkedAsFinal()
363
     */
364
    public function isMarkedAsFinal()
365
    {
366
        return $this->getPresentationProperties()->isMarkedAsFinal();
367
    }
368
369
    /**
370
     * Set the zoom of the document (in percentage)
371
     * @param float $zoom
372
     * @return PhpPresentation
373
     * @deprecated for getPresentationProperties()->setZoom()
374
     */
375
    public function setZoom($zoom = 1)
376
    {
377
        return $this->getPresentationProperties()->setZoom($zoom);
378
    }
379
380
    /**
381
     * Return the zoom (in percentage)
382
     * @return float
383
     * @deprecated for getPresentationProperties()->getZoom()
384
     */
385
    public function getZoom()
386
    {
387
        return $this->getPresentationProperties()->getZoom();
388
    }
389
}
390