Completed
Pull Request — develop (#435)
by
unknown
08:49 queued 01:27
created

AbstractSlide::createRoundRect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 5
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
namespace PhpOffice\PhpPresentation\Slide;
18
19
use PhpOffice\PhpPresentation\AbstractShape;
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
use PhpOffice\PhpPresentation\GeometryCalculator;
22
use PhpOffice\PhpPresentation\PhpPresentation;
23
use PhpOffice\PhpPresentation\Shape\ArrowPointer;
24
use PhpOffice\PhpPresentation\Shape\Chart;
25
use PhpOffice\PhpPresentation\Shape\Drawing\File;
26
use PhpOffice\PhpPresentation\Shape\Ellipse;
27
use PhpOffice\PhpPresentation\Shape\Group;
28
use PhpOffice\PhpPresentation\Shape\Line;
29
use PhpOffice\PhpPresentation\Shape\Rectangle;
30
use PhpOffice\PhpPresentation\Shape\RichText;
31
use PhpOffice\PhpPresentation\Shape\RoundRectangle;
32
use PhpOffice\PhpPresentation\Shape\Table;
33
use PhpOffice\PhpPresentation\Shape\Triangle;
34
use PhpOffice\PhpPresentation\ShapeContainerInterface;
35
use PhpOffice\PhpPresentation\Slide;
36
37
abstract class AbstractSlide implements ComparableInterface, ShapeContainerInterface
38
{
39
    /**
40
     * @var string
41
     */
42
    protected $relsIndex;
43
    /**
44
     *
45
     * @var \PhpOffice\PhpPresentation\Slide\Transition
46
     */
47
    protected $slideTransition;
48
49
    /**
50
     * Collection of shapes
51
     *
52
     * @var \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
53
     */
54
    protected $shapeCollection = null;
55
    /**
56
     * Extent Y
57
     *
58
     * @var int
59
     */
60
    protected $extentY;
61
    /**
62
     * Extent X
63
     *
64
     * @var int
65
     */
66
    protected $extentX;
67
    /**
68
     * Offset X
69
     *
70
     * @var int
71
     */
72
    protected $offsetX;
73
    /**
74
     * Offset Y
75
     *
76
     * @var int
77
     */
78
    protected $offsetY;
79
    /**
80
     * Slide identifier
81
     *
82
     * @var string
83
     */
84
    protected $identifier;
85
    /**
86
     * Hash index
87
     *
88
     * @var string
89
     */
90
    protected $hashIndex;
91
    /**
92
     * Parent presentation
93
     *
94
     * @var PhpPresentation
95
     */
96
    protected $parent;
97
    /**
98
     * Background of the slide
99
     *
100
     * @var AbstractBackground
101
     */
102
    protected $background;
103
104
    /**
105
     * Get collection of shapes
106
     *
107
     * @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
108
     */
109 203
    public function getShapeCollection()
110
    {
111 203
        return $this->shapeCollection;
112
    }
113
114
    /**
115
     * Get collection of shapes
116
     *
117
     * @return AbstractSlide
118
     */
119 1
    public function setShapeCollection($shapeCollection = array())
120
    {
121 1
        $this->shapeCollection = $shapeCollection;
122 1
        return $this;
123
    }
124
125
    /**
126
     * Add shape to slide
127
     *
128
     * @param  \PhpOffice\PhpPresentation\AbstractShape $shape
129
     * @return \PhpOffice\PhpPresentation\AbstractShape
130
     */
131 160
    public function addShape(AbstractShape $shape)
132
    {
133 160
        $shape->setContainer($this);
134 160
        return $shape;
135
    }
136
137
    /**
138
     * Get X Offset
139
     *
140
     * @return int
141
     */
142 114
    public function getOffsetX()
143
    {
144 114
        if ($this->offsetX === null) {
145 114
            $offsets = GeometryCalculator::calculateOffsets($this);
146 114
            $this->offsetX = $offsets[GeometryCalculator::X];
147 114
            $this->offsetY = $offsets[GeometryCalculator::Y];
148 114
        }
149 114
        return $this->offsetX;
150
    }
151
152
    /**
153
     * Get Y Offset
154
     *
155
     * @return int
156
     */
157 114
    public function getOffsetY()
158
    {
159 114
        if ($this->offsetY === null) {
160 1
            $offsets = GeometryCalculator::calculateOffsets($this);
161 1
            $this->offsetX = $offsets[GeometryCalculator::X];
162 1
            $this->offsetY = $offsets[GeometryCalculator::Y];
163 1
        }
164 114
        return $this->offsetY;
165
    }
166
167
    /**
168
     * Get X Extent
169
     *
170
     * @return int
171
     */
172 114
    public function getExtentX()
173
    {
174 114
        if ($this->extentX === null) {
175 114
            $extents = GeometryCalculator::calculateExtents($this);
176 114
            $this->extentX = $extents[GeometryCalculator::X];
177 114
            $this->extentY = $extents[GeometryCalculator::Y];
178 114
        }
179 114
        return $this->extentX;
180
    }
181
182
    /**
183
     * Get Y Extent
184
     *
185
     * @return int
186
     */
187 114
    public function getExtentY()
188
    {
189 114
        if ($this->extentY === null) {
190 1
            $extents = GeometryCalculator::calculateExtents($this);
191 1
            $this->extentX = $extents[GeometryCalculator::X];
192 1
            $this->extentY = $extents[GeometryCalculator::Y];
193 1
        }
194 114
        return $this->extentY;
195
    }
196
197
    /**
198
     * Get hash code
199
     *
200
     * @return string Hash code
201
     */
202 158
    public function getHashCode()
203
    {
204 158
        return md5($this->identifier . __CLASS__);
205
    }
206
207
    /**
208
     * Get hash index
209
     *
210
     * Note that this index may vary during script execution! Only reliable moment is
211
     * while doing a write of a workbook and when changes are not allowed.
212
     *
213
     * @return string Hash index
214
     */
215 4
    public function getHashIndex()
216
    {
217 4
        return $this->hashIndex;
218
    }
219
220
    /**
221
     * Set hash index
222
     *
223
     * Note that this index may vary during script execution! Only reliable moment is
224
     * while doing a write of a workbook and when changes are not allowed.
225
     *
226
     * @param string $value Hash index
227
     */
228 4
    public function setHashIndex($value)
229
    {
230 4
        $this->hashIndex = $value;
231 4
    }
232
233
    /**
234
     * Create rich text shape
235
     *
236
     * @return \PhpOffice\PhpPresentation\Shape\RichText
237
     */
238 45
    public function createRichTextShape()
239
    {
240 45
        $shape = new RichText();
241 45
        $this->addShape($shape);
242 45
        return $shape;
243
    }
244
245
    /**
246
     * Create line shape
247
     *
248
     * @param  int $fromX Starting point x offset
249
     * @param  int $fromY Starting point y offset
250
     * @param  int $toX Ending point x offset
251
     * @param  int $toY Ending point y offset
252
     * @return \PhpOffice\PhpPresentation\Shape\Line
253
     */
254 2
    public function createLineShape($fromX, $fromY, $toX, $toY)
255
    {
256 2
        $shape = new Line($fromX, $fromY, $toX, $toY);
257 2
        $this->addShape($shape);
258 2
        return $shape;
259
    }
260
261
    /**
262
     * Create a Triangle.
263
     *
264
     * @param  int $fromX Starting point x offset
265
     * @param  int $fromY Starting point y offset
266
     * @param  int $toX Ending point x offset
267
     * @param  int $toY Ending point y offset
268
     * @param  int $rotation Used for the rotation clockwise or anti-clockwise
269
     * @return \PhpOffice\PhpPresentation\Shape\Triangle
270
     */
271
    public function createTriangle($fromX, $fromY, $toX, $toY, $rotation)
272
    {
273
        $shape = new Triangle($fromX, $fromY, $toX, $toY, $rotation);
274
        $this->addShape($shape);
275
        return $shape;
276
    }
277
278
    /**
279
     * Create an Ellipse.
280
     *
281
     * @param  int $fromX Starting point x offset
282
     * @param  int $fromY Starting point y offset
283
     * @param  int $toX Ending point x offset
284
     * @param  int $toY Ending point y offset
285
     * @param  int $rotation Used for the rotation clockwise or anti-clockwise
286
     * @return \PhpOffice\PhpPresentation\Shape\Ellipse
287
     */
288
    public function createEllipse($fromX, $fromY, $toX, $toY, $rotation)
289
    {
290
        $shape = new Ellipse($fromX, $fromY, $toX, $toY, $rotation);
291
        $this->addShape($shape);
292
        return $shape;
293
    }
294
295
    /**
296
     * Create a Rectangle.
297
     *
298
     * @param  int $fromX Starting point x offset
299
     * @param  int $fromY Starting point y offset
300
     * @param  int $toX Ending point x offset
301
     * @param  int $toY Ending point y offset
302
     * @param  int $rotation Used for the rotation clockwise or anti-clockwise
303
     * @return \PhpOffice\PhpPresentation\Shape\Rectangle
304
     */
305
    public function createRectangle($fromX, $fromY, $toX, $toY, $rotation)
306
    {
307
        $shape = new Rectangle($fromX, $fromY, $toX, $toY, $rotation);
308
        $this->addShape($shape);
309
        return $shape;
310
    }
311
312
313
    /**
314
     * Create a Round Rectangle.
315
     *
316
     * @param  int $fromX Starting point x offset
317
     * @param  int $fromY Starting point y offset
318
     * @param  int $toX Ending point x offset
319
     * @param  int $toY Ending point y offset
320
     * @param  int $rotation Used for the rotation clockwise or anti-clockwise
321
     * @return \PhpOffice\PhpPresentation\Shape\RoundRectangle
322
     */
323
    public function createRoundRect($fromX, $fromY, $toX, $toY, $rotation)
324
    {
325
        $shape = new RoundRectangle($fromX, $fromY, $toX, $toY, $rotation);
326
        $this->addShape($shape);
327
        return $shape;
328
    }
329
330
    /**
331
     * Create an arrow pointer
332
     *
333
     * @param  int $fromX Starting point x offset
334
     * @param  int $fromY Starting point y offset
335
     * @param  int $toX Ending point x offset
336
     * @param  int $toY Ending point y offset
337
     * @return \PhpOffice\PhpPresentation\Shape\ArrowPointer
338
     */
339
    public function createArrowPointer($fromX, $fromY, $toX, $toY)
340
    {
341
        $shape = new ArrowPointer($fromX, $fromY, $toX, $toY);
342
        $this->addShape($shape);
343
        return $shape;
344
    }
345
346
    /**
347
     * Create chart shape
348
     *
349
     * @return \PhpOffice\PhpPresentation\Shape\Chart
350
     */
351 58
    public function createChartShape()
352
    {
353 58
        $shape = new Chart();
354 58
        $this->addShape($shape);
355 58
        return $shape;
356
    }
357
358
    /**
359
     * Create drawing shape
360
     *
361
     * @return \PhpOffice\PhpPresentation\Shape\Drawing\File
362
     */
363 16
    public function createDrawingShape()
364
    {
365 16
        $shape = new File();
366 16
        $this->addShape($shape);
367 16
        return $shape;
368
    }
369
370
    /**
371
     * Create table shape
372
     *
373
     * @param  int $columns Number of columns
374
     * @return \PhpOffice\PhpPresentation\Shape\Table
375
     */
376 17
    public function createTableShape($columns = 1)
377
    {
378 17
        $shape = new Table($columns);
379 17
        $this->addShape($shape);
380 17
        return $shape;
381
    }
382
383
    /**
384
     * Creates a group within this slide
385
     *
386
     * @return \PhpOffice\PhpPresentation\Shape\Group
387
     */
388 2
    public function createGroup()
389
    {
390 2
        $shape = new Group();
391 2
        $this->addShape($shape);
392 2
        return $shape;
393
    }
394
395
    /**
396
     * Get parent
397
     *
398
     * @return PhpPresentation
399
     */
400 115
    public function getParent()
401
    {
402 115
        return $this->parent;
403
    }
404
405
    /**
406
     * Re-bind parent
407
     *
408
     * @param  \PhpOffice\PhpPresentation\PhpPresentation $parent
409
     * @return \PhpOffice\PhpPresentation\Slide
410
     */
411 2
    public function rebindParent(PhpPresentation $parent)
412
    {
413 2
        $this->parent->removeSlideByIndex($this->parent->getIndex($this));
414 2
        $this->parent = $parent;
415 2
        return $this;
416
    }
417
418
    /**
419
     * @return AbstractBackground
420
     */
421 179
    public function getBackground()
422
    {
423 179
        return $this->background;
424
    }
425
426
    /**
427
     * @param AbstractBackground $background
428
     * @return Slide
429
     */
430 9
    public function setBackground(AbstractBackground $background = null)
431
    {
432 9
        $this->background = $background;
433 9
        return $this;
434
    }
435
436
    /**
437
     *
438
     * @return \PhpOffice\PhpPresentation\Slide\Transition
439
     */
440 177
    public function getTransition()
441
    {
442 177
        return $this->slideTransition;
443
    }
444
445
    /**
446
     *
447
     * @param \PhpOffice\PhpPresentation\Slide\Transition $transition
448
     * @return \PhpOffice\PhpPresentation\Slide
449
     */
450 3
    public function setTransition(Transition $transition = null)
451
    {
452 3
        $this->slideTransition = $transition;
453 3
        return $this;
454
    }
455
456
    /**
457
     * @return string
458
     */
459 120
    public function getRelsIndex()
460
    {
461 120
        return $this->relsIndex;
462
    }
463
464
    /**
465
     * @param string $indexName
466
     */
467 120
    public function setRelsIndex($indexName)
468
    {
469 120
        $this->relsIndex = $indexName;
470 120
    }
471
}
472