Completed
Pull Request — develop (#230)
by Franck
08:28
created

PhpPresentation   B

Complexity

Total Complexity 38

Size/Duplication

Total Lines 419
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 7

Test Coverage

Coverage 95.83%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 38
c 6
b 1
f 0
lcom 4
cbo 7
dl 0
loc 419
ccs 92
cts 96
cp 0.9583
rs 8.3999

30 Methods

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