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

AbstractSlide::rebindParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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 174
    public function getShapeCollection()
105
    {
106 174
        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 140
    public function addShape(AbstractShape $shape)
116
    {
117 140
        $shape->setContainer($this);
118 140
        return $shape;
119
    }
120
121
    /**
122
     * Get X Offset
123
     *
124
     * @return int
125
     */
126 96
    public function getOffsetX()
127
    {
128 96
        if ($this->offsetX === null) {
129 96
            $offsets = GeometryCalculator::calculateOffsets($this);
130 96
            $this->offsetX = $offsets[GeometryCalculator::X];
131 96
            $this->offsetY = $offsets[GeometryCalculator::Y];
132 96
        }
133 96
        return $this->offsetX;
134
    }
135
136
    /**
137
     * Get Y Offset
138
     *
139
     * @return int
140
     */
141 96
    public function getOffsetY()
142
    {
143 96
        if ($this->offsetY === null) {
144 1
            $offsets = GeometryCalculator::calculateOffsets($this);
145 1
            $this->offsetX = $offsets[GeometryCalculator::X];
146 1
            $this->offsetY = $offsets[GeometryCalculator::Y];
147 1
        }
148 96
        return $this->offsetY;
149
    }
150
151
    /**
152
     * Get X Extent
153
     *
154
     * @return int
155
     */
156 96
    public function getExtentX()
157
    {
158 96
        if ($this->extentX === null) {
159 96
            $extents = GeometryCalculator::calculateExtents($this);
160 96
            $this->extentX = $extents[GeometryCalculator::X];
161 96
            $this->extentY = $extents[GeometryCalculator::Y];
162 96
        }
163 96
        return $this->extentX;
164
    }
165
166
    /**
167
     * Get Y Extent
168
     *
169
     * @return int
170
     */
171 96
    public function getExtentY()
172
    {
173 96
        if ($this->extentY === null) {
174 1
            $extents = GeometryCalculator::calculateExtents($this);
175 1
            $this->extentX = $extents[GeometryCalculator::X];
176 1
            $this->extentY = $extents[GeometryCalculator::Y];
177 1
        }
178 96
        return $this->extentY;
179
    }
180
181
    /**
182
     * Get hash code
183
     *
184
     * @return string Hash code
185
     */
186 135
    public function getHashCode()
187
    {
188 135
        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 4
    public function getHashIndex()
200
    {
201 4
        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 4
    public function setHashIndex($value)
213
    {
214 4
        $this->hashIndex = $value;
215 4
    }
216
217
    /**
218
     * Create rich text shape
219
     *
220
     * @return \PhpOffice\PhpPresentation\Shape\RichText
221
     */
222 42
    public function createRichTextShape()
223
    {
224 42
        $shape = new RichText();
225 42
        $this->addShape($shape);
226 42
        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 2
    public function createLineShape($fromX, $fromY, $toX, $toY)
239
    {
240 2
        $shape = new Line($fromX, $fromY, $toX, $toY);
241 2
        $this->addShape($shape);
242 2
        return $shape;
243
    }
244
245
    /**
246
     * Create chart shape
247
     *
248
     * @return \PhpOffice\PhpPresentation\Shape\Chart
249
     */
250 46
    public function createChartShape()
251
    {
252 46
        $shape = new Chart();
253 46
        $this->addShape($shape);
254 46
        return $shape;
255
    }
256
257
    /**
258
     * Create drawing shape
259
     *
260
     * @return \PhpOffice\PhpPresentation\Shape\Drawing\File
261
     */
262 13
    public function createDrawingShape()
263
    {
264 13
        $shape = new File();
265 13
        $this->addShape($shape);
266 13
        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 16
    public function createTableShape($columns = 1)
276
    {
277 16
        $shape = new Table($columns);
278 16
        $this->addShape($shape);
279 16
        return $shape;
280
    }
281
282
    /**
283
     * Creates a group within this slide
284
     *
285
     * @return \PhpOffice\PhpPresentation\Shape\Group
286
     */
287 2
    public function createGroup()
288
    {
289 2
        $shape = new Group();
290 2
        $this->addShape($shape);
291 2
        return $shape;
292
    }
293
294
    /**
295
     * Get parent
296
     *
297
     * @return PhpPresentation
298
     */
299 96
    public function getParent()
300
    {
301 96
        return $this->parent;
302
    }
303
304
    /**
305
     * Re-bind parent
306
     *
307
     * @param  \PhpOffice\PhpPresentation\PhpPresentation $parent
308
     * @return \PhpOffice\PhpPresentation\Slide
309
     */
310 2
    public function rebindParent(PhpPresentation $parent)
311
    {
312 2
        $this->parent->removeSlideByIndex($this->parent->getIndex($this));
313 2
        $this->parent = $parent;
314 2
        return $this;
315
    }
316
317
    /**
318
     * @return AbstractBackground
319
     */
320 155
    public function getBackground()
321
    {
322 155
        return $this->background;
323
    }
324
325
    /**
326
     * @param AbstractBackground $background
327
     * @return Slide
328
     */
329 8
    public function setBackground(AbstractBackground $background = null)
330
    {
331 8
        $this->background = $background;
332 8
        return $this;
333
    }
334
335
    /**
336
     *
337
     * @return \PhpOffice\PhpPresentation\Slide\Transition
338
     */
339 155
    public function getTransition()
340
    {
341 155
        return $this->slideTransition;
342
    }
343
344
    /**
345
     *
346
     * @param \PhpOffice\PhpPresentation\Slide\Transition $transition
347
     * @return \PhpOffice\PhpPresentation\Slide
348
     */
349 3
    public function setTransition(Transition $transition = null)
350
    {
351 3
        $this->slideTransition = $transition;
352 3
        return $this;
353
    }
354
355
    /**
356
     * @return string
357
     */
358 101
    public function getRelsIndex()
359
    {
360 101
        return $this->relsIndex;
361
    }
362
363
    /**
364
     * @param string $indexName
365
     */
366 101
    public function setRelsIndex($indexName)
367
    {
368 101
        $this->relsIndex = $indexName;
369 101
    }
370
}
371