Completed
Pull Request — develop (#230)
by Franck
09:07
created

AbstractSlide::createDrawingShape()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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