Completed
Push — develop ( d9e4d8...cd1d80 )
by Franck
23s
created

PhpPresentation::getProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 222
    public function __construct()
74
    {
75
        // Set empty Master & SlideLayout
76 222
        $this->createMasterSlide()->createSlideLayout();
77
78
        // Initialise slide collection and add one slide
79 222
        $this->createSlide();
80 222
        $this->setActiveSlideIndex();
81
82
        // Set initial document properties & layout
83 222
        $this->setDocumentProperties(new DocumentProperties());
84 222
        $this->setPresentationProperties(new PresentationProperties());
85 222
        $this->setLayout(new DocumentLayout());
86 222
    }
87
88
    /**
89
     * Get properties
90
     *
91
     * @return \PhpOffice\PhpPresentation\DocumentProperties
92
     * @deprecated for getDocumentProperties
93
     */
94 1
    public function getProperties()
95
    {
96 1
        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 186
    public function getDocumentProperties()
117
    {
118 186
        return $this->documentProperties;
119
    }
120
121
    /**
122
     * Set properties
123
     *
124
     * @param  \PhpOffice\PhpPresentation\DocumentProperties $value
125
     * @return PhpPresentation
126
     */
127 222
    public function setDocumentProperties(DocumentProperties $value)
128
    {
129 222
        $this->documentProperties = $value;
130
131 222
        return $this;
132
    }
133
134
    /**
135
     * Get presentation properties
136
     *
137
     * @return \PhpOffice\PhpPresentation\PresentationProperties
138
     */
139 183
    public function getPresentationProperties()
140
    {
141 183
        return $this->presentationProps;
142
    }
143
144
    /**
145
     * Set presentation properties
146
     *
147
     * @param  \PhpOffice\PhpPresentation\PresentationProperties $value
148
     * @return PhpPresentation
149
     */
150 222
    public function setPresentationProperties(PresentationProperties $value)
151
    {
152 222
        $this->presentationProps = $value;
153 222
        return $this;
154
    }
155
156
    /**
157
     * Get layout
158
     *
159
     * @return \PhpOffice\PhpPresentation\DocumentLayout
160
     */
161 179
    public function getLayout()
162
    {
163 179
        return $this->layout;
164
    }
165
166
    /**
167
     * Set layout
168
     *
169
     * @param  \PhpOffice\PhpPresentation\DocumentLayout $value
170
     * @return PhpPresentation
171
     */
172 222
    public function setLayout(DocumentLayout $value)
173
    {
174 222
        $this->layout = $value;
175
176 222
        return $this;
177
    }
178
179
    /**
180
     * Get active slide
181
     *
182
     * @return \PhpOffice\PhpPresentation\Slide
183
     */
184 222
    public function getActiveSlide()
185
    {
186 222
        return $this->slideCollection[$this->activeSlideIndex];
187
    }
188
189
    /**
190
     * Create slide and add it to this presentation
191
     *
192
     * @return \PhpOffice\PhpPresentation\Slide
193
     * @throws \Exception
194
     */
195 222
    public function createSlide()
196
    {
197 222
        $newSlide = new Slide($this);
198 222
        $this->addSlide($newSlide);
199 222
        return $newSlide;
200
    }
201
202
    /**
203
     * Add slide
204
     *
205
     * @param  \PhpOffice\PhpPresentation\Slide $slide
206
     * @throws \Exception
207
     * @return \PhpOffice\PhpPresentation\Slide
208
     */
209 222
    public function addSlide(Slide $slide = null)
210
    {
211 222
        $this->slideCollection[] = $slide;
212
213 222
        return $slide;
214
    }
215
216
    /**
217
     * Remove slide by index
218
     *
219
     * @param  int $index Slide index
220
     * @throws \Exception
221
     * @return PhpPresentation
222
     */
223 16
    public function removeSlideByIndex($index = 0)
224
    {
225 16
        if ($index > count($this->slideCollection) - 1) {
226 1
            throw new \Exception("Slide index is out of bounds.");
227
        }
228 15
        array_splice($this->slideCollection, $index, 1);
229
230 15
        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 193
    public function getSlide($index = 0)
241
    {
242 193
        if ($index > count($this->slideCollection) - 1) {
243 1
            throw new \Exception("Slide index is out of bounds.");
244
        }
245 192
        return $this->slideCollection[$index];
246
    }
247
248
    /**
249
     * Get all slides
250
     *
251
     * @return \PhpOffice\PhpPresentation\Slide[]
252
     */
253 184
    public function getAllSlides()
254
    {
255 184
        return $this->slideCollection;
256
    }
257
258
    /**
259
     * Get index for slide
260
     *
261
     * @param  \PhpOffice\PhpPresentation\Slide\AbstractSlide $slide
262
     * @return int
263
     * @throws \Exception
264
     */
265 115
    public function getIndex(Slide\AbstractSlide $slide)
266
    {
267 115
        $index = null;
268 115
        foreach ($this->slideCollection as $key => $value) {
269 115
            if ($value->getHashCode() == $slide->getHashCode()) {
270 115
                $index = $key;
271 115
                break;
272
            }
273
        }
274 115
        return $index;
275
    }
276
277
    /**
278
     * Get slide count
279
     *
280
     * @return int
281
     */
282 196
    public function getSlideCount()
283
    {
284 196
        return count($this->slideCollection);
285
    }
286
287
    /**
288
     * Get active slide index
289
     *
290
     * @return int Active slide index
291
     */
292 1
    public function getActiveSlideIndex()
293
    {
294 1
        return $this->activeSlideIndex;
295
    }
296
297
    /**
298
     * Set active slide index
299
     *
300
     * @param  int $index Active slide index
301
     * @throws \Exception
302
     * @return \PhpOffice\PhpPresentation\Slide
303
     */
304 222
    public function setActiveSlideIndex($index = 0)
305
    {
306 222
        if ($index > count($this->slideCollection) - 1) {
307 1
            throw new \Exception("Active slide index is out of bounds.");
308
        }
309 222
        $this->activeSlideIndex = $index;
310
311 222
        return $this->getActiveSlide();
312
    }
313
314
    /**
315
     * Add external slide
316
     *
317
     * @param  \PhpOffice\PhpPresentation\Slide $slide External slide to add
318
     * @throws \Exception
319
     * @return \PhpOffice\PhpPresentation\Slide
320
     */
321 1
    public function addExternalSlide(Slide $slide)
322
    {
323 1
        $slide->rebindParent($this);
324
325 1
        $this->addMasterSlide($slide->getSlideLayout()->getSlideMaster());
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
     * @throws \Exception
345
     */
346 222
    public function createMasterSlide()
347
    {
348 222
        $newMasterSlide = new SlideMaster($this);
349 222
        $this->addMasterSlide($newMasterSlide);
350 222
        return $newMasterSlide;
351
    }
352
353
    /**
354
     * Add masterslide
355
     *
356
     * @param  \PhpOffice\PhpPresentation\Slide\SlideMaster $slide
357
     * @return \PhpOffice\PhpPresentation\Slide\SlideMaster
358
     * @throws \Exception
359
     */
360 222
    public function addMasterSlide(SlideMaster $slide = null)
361
    {
362 222
        $this->slideMasters[] = $slide;
363
364 222
        return $slide;
365
    }
366
367
    /**
368
     * Copy presentation (!= clone!)
369
     *
370
     * @return PhpPresentation
371
     * @throws \Exception
372
     */
373 1
    public function copy()
374
    {
375 1
        $copied = clone $this;
376
377 1
        $slideCount = count($this->slideCollection);
378 1
        for ($i = 0; $i < $slideCount; ++$i) {
379 1
            $this->slideCollection[$i] = $this->slideCollection[$i]->copy();
380 1
            $this->slideCollection[$i]->rebindParent($this);
381
        }
382
383 1
        return $copied;
384
    }
385
386
    /**
387
     * Mark a document as final
388
     * @param bool $state
389
     * @return PresentationProperties
390
     * @deprecated for getPresentationProperties()->markAsFinal()
391
     */
392 1
    public function markAsFinal($state = true)
393
    {
394 1
        return $this->getPresentationProperties()->markAsFinal($state);
395
    }
396
397
    /**
398
     * Return if this document is marked as final
399
     * @return bool
400
     * @deprecated for getPresentationProperties()->isMarkedAsFinal()
401
     */
402 1
    public function isMarkedAsFinal()
403
    {
404 1
        return $this->getPresentationProperties()->isMarkedAsFinal();
405
    }
406
407
    /**
408
     * Set the zoom of the document (in percentage)
409
     * @param float $zoom
410
     * @return PresentationProperties
411
     * @deprecated for getPresentationProperties()->setZoom()
412
     */
413 1
    public function setZoom($zoom = 1.0)
414
    {
415 1
        return $this->getPresentationProperties()->setZoom($zoom);
416
    }
417
418
    /**
419
     * Return the zoom (in percentage)
420
     * @return float
421
     * @deprecated for getPresentationProperties()->getZoom()
422
     */
423 1
    public function getZoom()
424
    {
425 1
        return $this->getPresentationProperties()->getZoom();
426
    }
427
428
    /**
429
     * @return \ArrayObject|Slide\SlideMaster[]
430
     */
431 222
    public function getAllMasterSlides()
432
    {
433 222
        return $this->slideMasters;
434
    }
435
436
    /**
437
     * @param \ArrayObject|Slide\SlideMaster[] $slideMasters
438
     * @return $this
439
     */
440 4
    public function setAllMasterSlides($slideMasters = array())
441
    {
442 4
        if ($slideMasters instanceof \ArrayObject || is_array($slideMasters)) {
443 4
            $this->slideMasters = $slideMasters;
444
        }
445 4
        return $this;
446
    }
447
}
448