Completed
Push — develop ( 30aa22...03661d )
by Franck
13s
created

PhpPresentation::markAsFinal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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