Completed
Pull Request — develop (#178)
by
unknown
09:34
created

Rels   D

Complexity

Total Complexity 81

Size/Duplication

Total Lines 548
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 67.13%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 81
c 3
b 0
f 1
lcom 1
cbo 10
dl 0
loc 548
ccs 194
cts 289
cp 0.6713
rs 4.8717

8 Methods

Rating   Name   Duplication   Size   Complexity  
B writeRelationships() 0 29 1
B writePresentationRelationships() 0 44 4
C writeSlideMasterRelationships() 0 47 7
B writeSlideLayoutRelationships() 0 34 4
B writeThemeRelationships() 0 30 4
D writeSlideRelationships() 0 251 54
A writeChartRelationships() 0 22 2
B writeRelationship() 0 22 5

How to fix   Complexity   

Complex Class

Complex classes like Rels often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Rels, and based on these observations, apply Extract Interface, too.

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
18
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;
19
20
use PhpOffice\Common\XMLWriter;
21
use PhpOffice\PhpPresentation\PhpPresentation;
22
use PhpOffice\PhpPresentation\Shape\Chart as ShapeChart;
23
use PhpOffice\PhpPresentation\Shape\Drawing as ShapeDrawing;
24
use PhpOffice\PhpPresentation\Shape\Group;
25
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
26
use PhpOffice\PhpPresentation\Shape\RichText\Run;
27
use PhpOffice\PhpPresentation\Shape\RichText;
28
use PhpOffice\PhpPresentation\Shape\RichText\TextElement;
29
use PhpOffice\PhpPresentation\Shape\Table as ShapeTable;
30
use PhpOffice\PhpPresentation\Slide as SlideElement;
31
use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
32
33
/**
34
 * \PhpOffice\PhpPresentation\Writer\PowerPoint2007\Rels
35
 */
36
class Rels extends AbstractPart
37
{
38
    /**
39
     * Write relationships to XML format
40
     *
41
     * @return string        XML Output
42
     * @throws \Exception
43
     */
44 61
    public function writeRelationships()
45
    {
46
        // Create XML writer
47 61
        $objWriter = $this->getXMLWriter();
48
49
        // XML header
50 60
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
51
52
        // Relationships
53 60
        $objWriter->startElement('Relationships');
54 60
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
55
56
        // Relationship docProps/custom.xml
57 60
        $this->writeRelationship($objWriter, 4, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties', 'docProps/custom.xml');
58
59
        // Relationship docProps/app.xml
60 60
        $this->writeRelationship($objWriter, 3, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'docProps/app.xml');
61
62
        // Relationship docProps/core.xml
63 60
        $this->writeRelationship($objWriter, 2, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'docProps/core.xml');
64
65
        // Relationship ppt/presentation.xml
66 60
        $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'ppt/presentation.xml');
67
68 60
        $objWriter->endElement();
69
70
        // Return
71 60
        return $objWriter->getData();
72
    }
73
74
    /**
75
     * Write presentation relationships to XML format
76
     *
77
     * @param  PhpPresentation $pPhpPresentation
78
     * @return string        XML Output
79
     * @throws \Exception
80
     */
81 60
    public function writePresentationRelationships(PhpPresentation $pPhpPresentation)
82
    {
83
        // Create XML writer
84 60
        $objWriter = $this->getXMLWriter();
85
86
        // XML header
87 60
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
88
89
        // Relationships
90 60
        $objWriter->startElement('Relationships');
91 60
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
92
93
        // Relation id
94 60
        $relationId = 1;
95
96 60
        $parentWriter = $this->getParentWriter();
97 60
        if ($parentWriter instanceof PowerPoint2007) {
98
            // Add slide masters
99 60
            $masterSlides = $parentWriter->getLayoutPack()->getMasterSlides();
100 60
            foreach ($masterSlides as $masterSlide) {
101
                // Relationship slideMasters/slideMasterX.xml
102 60
                $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', 'slideMasters/slideMaster' . $masterSlide['masterid'] . '.xml');
103 60
            }
104 60
        }
105
106
        // Add slide theme (only one!)
107
        // Relationship theme/theme1.xml
108 60
        $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'theme/theme1.xml');
109
110
        // Relationships with slides
111 60
        $slideCount = $pPhpPresentation->getSlideCount();
112 60
        for ($i = 0; $i < $slideCount; ++$i) {
113 60
            $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slides/slide' . ($i + 1) . '.xml');
114 60
        }
115
116 60
        $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps', 'presProps.xml');
117 60
        $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps', 'viewProps.xml');
118 60
        $this->writeRelationship($objWriter, $relationId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles', 'tableStyles.xml');
119
120 60
        $objWriter->endElement();
121
122
        // Return
123 60
        return $objWriter->getData();
124
    }
125
126
    /**
127
     * Write slide master relationships to XML format
128
     *
129
     * @param  int       $masterId Master slide id
130
     * @return string    XML Output
131
     * @throws \Exception
132
     */
133 60
    public function writeSlideMasterRelationships($masterId = 1)
134
    {
135
        // Create XML writer
136 60
        $objWriter = $this->getXMLWriter();
137
138
        // XML header
139 60
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
140
141
        // Relationships
142 60
        $objWriter->startElement('Relationships');
143 60
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
144
145
        // Keep content id
146 60
        $contentId = 0;
147
148 60
        $parentWriter = $this->getParentWriter();
149 60
        if ($parentWriter instanceof PowerPoint2007) {
150
            // Lookup layouts
151 60
            $layouts    = array();
152 60
            $layoutPack = $parentWriter->getLayoutPack();
153 60
            foreach ($layoutPack->getLayouts() as $key => $layout) {
154 60
                if ($layout['masterid'] == $masterId) {
155 60
                    $layouts[$key] = $layout;
156 60
                }
157 60
            }
158
        
159
            // Write slideLayout relationships
160 60
            foreach ($layouts as $key => $layout) {
161 60
                $this->writeRelationship($objWriter, ++$contentId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $key . '.xml');
162 60
            }
163
    
164
            // Relationship theme/theme1.xml
165 60
            $this->writeRelationship($objWriter, ++$contentId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', '../theme/theme' . $masterId . '.xml');
166
    
167
            // Other relationships
168 60
            $otherRelations = $layoutPack->getMasterSlideRelations();
169 60
            foreach ($otherRelations as $otherRelation) {
170
                if ($otherRelation['masterid'] == $masterId) {
171
                    $this->writeRelationship($objWriter, ++$contentId, $otherRelation['type'], $otherRelation['target']);
172
                }
173 60
            }
174 60
        }
175 60
        $objWriter->endElement();
176
177
        // Return
178 60
        return $objWriter->getData();
179
    }
180
181
    /**
182
     * Write slide layout relationships to XML format
183
     *
184
     * @param  int       $slideLayoutIndex
185
     * @param  int       $masterId
186
     * @return string    XML Output
187
     * @throws \Exception
188
     */
189 60
    public function writeSlideLayoutRelationships($slideLayoutIndex, $masterId = 1)
190
    {
191
        // Create XML writer
192 60
        $objWriter = $this->getXMLWriter();
193
194 60
        $parentWriter = $this->getParentWriter();
195 60
        if ($parentWriter instanceof PowerPoint2007) {
196
            // Layout pack
197 60
            $layoutPack = $parentWriter->getLayoutPack();
198
    
199
            // XML header
200 60
            $objWriter->startDocument('1.0', 'UTF-8', 'yes');
201
    
202
            // Relationships
203 60
            $objWriter->startElement('Relationships');
204 60
            $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
205
    
206
            // Write slideMaster relationship
207 60
            $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster', '../slideMasters/slideMaster' . $masterId . '.xml');
208
    
209
            // Other relationships
210 60
            $otherRelations = $layoutPack->getLayoutRelations();
211 60
            foreach ($otherRelations as $otherRelation) {
212
                if ($otherRelation['layoutId'] == $slideLayoutIndex) {
213
                    $this->writeRelationship($objWriter, $otherRelation['id'], $otherRelation['type'], $otherRelation['target']);
214
                }
215 60
            }
216
    
217 60
            $objWriter->endElement();
218 60
        }
219
220
        // Return
221 60
        return $objWriter->getData();
222
    }
223
224
    /**
225
     * Write theme relationships to XML format
226
     *
227
     * @param  int       $masterId Master slide id
228
     * @return string    XML Output
229
     * @throws \Exception
230
     */
231 60
    public function writeThemeRelationships($masterId = 1)
232
    {
233
        // Create XML writer
234 60
        $objWriter = $this->getXMLWriter();
235
236 60
        $parentWriter = $this->getParentWriter();
237 60
        if ($parentWriter instanceof PowerPoint2007) {
238
            // Layout pack
239 60
            $layoutPack = $parentWriter->getLayoutPack();
240
    
241
            // XML header
242 60
            $objWriter->startDocument('1.0', 'UTF-8', 'yes');
243
    
244
            // Relationships
245 60
            $objWriter->startElement('Relationships');
246 60
            $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
247
    
248
            // Other relationships
249 60
            $otherRelations = $layoutPack->getThemeRelations();
250 60
            foreach ($otherRelations as $otherRelation) {
251
                if ($otherRelation['masterid'] == $masterId) {
252
                    $this->writeRelationship($objWriter, $otherRelation['id'], $otherRelation['type'], $otherRelation['target']);
253
                }
254 60
            }
255
    
256 60
            $objWriter->endElement();
257 60
        }
258
        // Return
259 60
        return $objWriter->getData();
260
    }
261
262
    /**
263
     * Write slide relationships to XML format
264
     *
265
     * @param  \PhpOffice\PhpPresentation\Slide $pSlide
266
     * @return string              XML Output
267
     * @throws \Exception
268
     */
269 60
    public function writeSlideRelationships(SlideElement $pSlide)
270
    {
271
        // Create XML writer
272 60
        $objWriter = $this->getXMLWriter();
273
274
        // XML header
275 60
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
276
277
        // Relationships
278 60
        $objWriter->startElement('Relationships');
279 60
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
280
281
        // Starting relation id
282 60
        $relId = 1;
283 60
        $idxSlide = $pSlide->getParent()->getIndex($pSlide);
284
285
        // Write slideLayout relationship
286 60
        $parentWriter = $this->getParentWriter();
287 60
        if ($parentWriter instanceof PowerPoint2007) {
288 60
            $layoutPack  = $parentWriter->getLayoutPack();
289 60
            $layoutId = $layoutPack->findlayoutId($pSlide->getSlideLayout(), $pSlide->getSlideMasterId());
290
    
291 60
            $this->writeRelationship($objWriter, $relId++, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml');
292 60
        }
293
294
        // Write drawing relationships?
295 60
        if ($pSlide->getShapeCollection()->count() > 0) {
296
            // Loop trough images and write relationships
297 53
            $iterator = $pSlide->getShapeCollection()->getIterator();
298 53
            while ($iterator->valid()) {
299 53
                if ($iterator->current() instanceof ShapeDrawing || $iterator->current() instanceof MemoryDrawing) {
300
                    // Write relationship for image drawing
301 4
                    $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . str_replace(' ', '_', $iterator->current()->getIndexedFilename()));
302
303 4
                    $iterator->current()->relationId = 'rId' . $relId;
304
305 4
                    ++$relId;
306 53
                } elseif ($iterator->current() instanceof ShapeChart) {
307
                    // Write relationship for chart drawing
308 20
                    $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename());
309
310 20
                    $iterator->current()->relationId = 'rId' . $relId;
311
312 20
                    ++$relId;
313 50
                } elseif ($iterator->current() instanceof Group) {
314
                    $iterator2 = $iterator->current()->getShapeCollection()->getIterator();
315
                    while ($iterator2->valid()) {
316
                        if ($iterator2->current() instanceof ShapeDrawing || $iterator2->current() instanceof MemoryDrawing) {
317
                            // Write relationship for image drawing
318
                            $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . str_replace(' ', '_', $iterator2->current()->getIndexedFilename()));
319
320
                            $iterator2->current()->relationId = 'rId' . $relId;
321
322
                            ++$relId;
323
                        } elseif ($iterator2->current() instanceof ShapeChart) {
324
                            // Write relationship for chart drawing
325
                            $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename());
326
327
                            $iterator2->current()->relationId = 'rId' . $relId;
328
329
                            ++$relId;
330
                        }
331
                        $iterator2->next();
332
                    }
333
                }
334
335 53
                $iterator->next();
336 53
            }
337 53
        }
338
339
        // Write background relationships?
340 60
        $oBackground = $pSlide->getBackground();
341 60
        if ($oBackground instanceof SlideElement\Background\Image) {
342
            $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($idxSlide));
343
            $oBackground->relationId = 'rId' . $relId;
344
            ++$relId;
345
        }
346
347
        // Write hyperlink relationships?
348 60
        if ($pSlide->getShapeCollection()->count() > 0) {
349
            // Loop trough hyperlinks and write relationships
350 53
            $iterator = $pSlide->getShapeCollection()->getIterator();
351 53
            while ($iterator->valid()) {
352
                // Hyperlink on shape
353 53
                if ($iterator->current()->hasHyperlink()) {
354
                    // Write relationship for hyperlink
355 2
                    $hyperlink               = $iterator->current()->getHyperlink();
356 2
                    $hyperlink->relationId = 'rId' . $relId;
357
358 2
                    if (!$hyperlink->isInternal()) {
359 2
                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
360 2
                    } else {
361
                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
362
                    }
363
364 2
                    ++$relId;
365 2
                }
366
367
                // Hyperlink on rich text run
368 53
                if ($iterator->current() instanceof RichText) {
369 21
                    foreach ($iterator->current()->getParagraphs() as $paragraph) {
370 21
                        foreach ($paragraph->getRichTextElements() as $element) {
371 16
                            if ($element instanceof Run || $element instanceof TextElement) {
372 15
                                if ($element->hasHyperlink()) {
373
                                    // Write relationship for hyperlink
374 2
                                    $hyperlink               = $element->getHyperlink();
375 2
                                    $hyperlink->relationId = 'rId' . $relId;
376
377 2
                                    if (!$hyperlink->isInternal()) {
378 1
                                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
379 1
                                    } else {
380 1
                                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
381
                                    }
382
383 2
                                    ++$relId;
384 2
                                }
385 15
                            }
386 21
                        }
387 21
                    }
388 21
                }
389
                
390
                // Hyperlink in table
391 53
                if ($iterator->current() instanceof ShapeTable) {
392
                    // Rows
393 10
                    $countRows = count($iterator->current()->getRows());
394 10
                    for ($row = 0; $row < $countRows; $row++) {
395
                        // Cells in rows
396 10
                        $countCells = count($iterator->current()->getRow($row)->getCells());
397 10
                        for ($cell = 0; $cell < $countCells; $cell++) {
398 10
                            $currentCell = $iterator->current()->getRow($row)->getCell($cell);
399
                            // Paragraphs in cell
400 10
                            foreach ($currentCell->getParagraphs() as $paragraph) {
401
                                // RichText in paragraph
402 10
                                foreach ($paragraph->getRichTextElements() as $element) {
403
                                    // Run or Text in RichText
404 9
                                    if ($element instanceof Run || $element instanceof TextElement) {
405 9
                                        if ($element->hasHyperlink()) {
406
                                            // Write relationship for hyperlink
407 1
                                            $hyperlink               = $element->getHyperlink();
408 1
                                            $hyperlink->relationId = 'rId' . $relId;
409
                            
410 1
                                            if (!$hyperlink->isInternal()) {
411 1
                                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
412 1
                                            } else {
413
                                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
414
                                            }
415
                            
416 1
                                            ++$relId;
417 1
                                        }
418 9
                                    }
419 10
                                }
420 10
                            }
421 10
                        }
422 10
                    }
423 10
                }
424
425 53
                if ($iterator->current() instanceof Group) {
426
                    $iterator2 = $pSlide->getShapeCollection()->getIterator();
427
                    while ($iterator2->valid()) {
428
                        // Hyperlink on shape
429
                        if ($iterator2->current()->hasHyperlink()) {
430
                            // Write relationship for hyperlink
431
                            $hyperlink             = $iterator2->current()->getHyperlink();
432
                            $hyperlink->relationId = 'rId' . $relId;
433
434
                            if (!$hyperlink->isInternal()) {
435
                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
436
                            } else {
437
                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
438
                            }
439
440
                            ++$relId;
441
                        }
442
443
                        // Hyperlink on rich text run
444
                        if ($iterator2->current() instanceof RichText) {
445
                            foreach ($iterator2->current()->getParagraphs() as $paragraph) {
446
                                foreach ($paragraph->getRichTextElements() as $element) {
447
                                    if ($element instanceof Run || $element instanceof TextElement) {
448
                                        if ($element->hasHyperlink()) {
449
                                            // Write relationship for hyperlink
450
                                            $hyperlink              = $element->getHyperlink();
451
                                            $hyperlink->relationId = 'rId' . $relId;
452
453
                                            if (!$hyperlink->isInternal()) {
454
                                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
455
                                            } else {
456
                                                $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
457
                                            }
458
459
                                            ++$relId;
460
                                        }
461
                                    }
462
                                }
463
                            }
464
                        }
465
                        
466
                        // Hyperlink in table
467
                        if ($iterator2->current() instanceof ShapeTable) {
468
                            // Rows
469
                            $countRows = count($iterator2->current()->getRows());
470
                            for ($row = 0; $row < $countRows; $row++) {
471
                                // Cells in rows
472
                                $countCells = count($iterator2->current()->getRow($row)->getCells());
473
                                for ($cell = 0; $cell < $countCells; $cell++) {
474
                                    $currentCell = $iterator2->current()->getRow($row)->getCell($cell);
475
                                    // Paragraphs in cell
476
                                    foreach ($currentCell->getParagraphs() as $paragraph) {
477
                                        // RichText in paragraph
478
                                        foreach ($paragraph->getRichTextElements() as $element) {
479
                                            // Run or Text in RichText
480
                                            if ($element instanceof Run || $element instanceof TextElement) {
481
                                                if ($element->hasHyperlink()) {
482
                                                    // Write relationship for hyperlink
483
                                                    $hyperlink               = $element->getHyperlink();
484
                                                    $hyperlink->relationId = 'rId' . $relId;
485
                            
486
                                                    if (!$hyperlink->isInternal()) {
487
                                                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External');
488
                                                    } else {
489
                                                        $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml');
490
                                                    }
491
                            
492
                                                    ++$relId;
493
                                                }
494
                                            }
495
                                        }
496
                                    }
497
                                }
498
                            }
499
                        }
500
                        
501
                        $iterator2->next();
502
                    }
503
                    
504
                }
505
506 53
                $iterator->next();
507 53
            }
508 53
        }
509
        
510 60
        if ($pSlide->getNote()->getShapeCollection()->count() > 0) {
511 1
            $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide', '../notesSlides/notesSlide'.($idxSlide + 1).'.xml');
512 1
            ++$relId;
513 1
        }
514
515 60
        $objWriter->endElement();
516
517
        // Return
518 60
        return $objWriter->getData();
519
    }
520
521
    /**
522
     * Write chart relationships to XML format
523
     *
524
     * @param  \PhpOffice\PhpPresentation\Shape\Chart $pChart
525
     * @return string                    XML Output
526
     * @throws \Exception
527
     */
528
    public function writeChartRelationships(ShapeChart $pChart)
529
    {
530
        // Create XML writer
531
        $objWriter = $this->getXMLWriter();
532
533
        // XML header
534
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
535
536
        // Relationships
537
        $objWriter->startElement('Relationships');
538
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
539
540
        // Write spreadsheet relationship?
541
        if ($pChart->hasIncludedSpreadsheet()) {
542
            $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package', '../embeddings/' . $pChart->getIndexedFilename() . '.xlsx');
543
        }
544
545
        $objWriter->endElement();
546
547
        // Return
548
        return $objWriter->getData();
549
    }
550
551
    /**
552
     * Write relationship
553
     *
554
     * @param  \PhpOffice\Common\XMLWriter $objWriter   XML Writer
555
     * @param  int                            $pId         Relationship ID. rId will be prepended!
556
     * @param  string                         $pType       Relationship type
557
     * @param  string                         $pTarget     Relationship target
558
     * @param  string                         $pTargetMode Relationship target mode
559
     * @throws \Exception
560
     */
561 60
    private function writeRelationship(XMLWriter $objWriter, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '')
562
    {
563 60
        if ($pType != '' && $pTarget != '') {
564 60
            if (strpos($pId, 'rId') === false) {
565 60
                $pId = 'rId' . $pId;
566 60
            }
567
568
            // Write relationship
569 60
            $objWriter->startElement('Relationship');
570 60
            $objWriter->writeAttribute('Id', $pId);
571 60
            $objWriter->writeAttribute('Type', $pType);
572 60
            $objWriter->writeAttribute('Target', $pTarget);
573
574 60
            if ($pTargetMode != '') {
575 4
                $objWriter->writeAttribute('TargetMode', $pTargetMode);
576 4
            }
577
578 60
            $objWriter->endElement();
579 60
        } else {
580
            throw new \Exception("Invalid parameters passed.");
581
        }
582 60
    }
583
}
584