Completed
Pull Request — develop (#435)
by
unknown
19:30 queued 15:48
created

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