Completed
Pull Request — develop (#435)
by
unknown
07:04
created

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