|
31 | 31 | use PhpOffice\PhpPresentation\Shape\RichText\Run;
|
32 | 32 | use PhpOffice\PhpPresentation\Shape\RichText\TextElement;
|
33 | 33 | use PhpOffice\PhpPresentation\Shape\Table as ShapeTable;
|
| 34 | +use PhpOffice\PhpPresentation\ShapeContainerInterface; |
34 | 35 | use PhpOffice\PhpPresentation\Slide;
|
35 | 36 | use PhpOffice\PhpPresentation\Slide\Background\Image;
|
36 | 37 | use PhpOffice\PhpPresentation\Slide\Note;
|
@@ -96,56 +97,38 @@ protected function writeSlideRelationships(Slide $pSlide): string
|
96 | 97 |
|
97 | 98 | // Write drawing relationships?
|
98 | 99 | if ($pSlide->getShapeCollection()->count() > 0) {
|
99 |
| - // Loop trough images and write relationships |
100 |
| - $iterator = $pSlide->getShapeCollection()->getIterator(); |
101 |
| - while ($iterator->valid()) { |
102 |
| - if ($iterator->current() instanceof Media) { |
103 |
| - // Write relationship for image drawing |
104 |
| - $iterator->current()->relationId = 'rId' . $relId; |
105 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename()); |
106 |
| - ++$relId; |
107 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
108 |
| - ++$relId; |
109 |
| - } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
110 |
| - // Write relationship for image drawing |
111 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator->current()->getIndexedFilename()); |
112 |
| - $iterator->current()->relationId = 'rId' . $relId; |
113 |
| - ++$relId; |
114 |
| - } elseif ($iterator->current() instanceof ShapeChart) { |
115 |
| - // Write relationship for chart drawing |
116 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename()); |
| 100 | + $collections = [$pSlide->getShapeCollection()->getIterator()]; |
117 | 101 |
|
118 |
| - $iterator->current()->relationId = 'rId' . $relId; |
119 |
| - |
120 |
| - ++$relId; |
121 |
| - } elseif ($iterator->current() instanceof Group) { |
122 |
| - $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
123 |
| - while ($iterator2->valid()) { |
124 |
| - if ($iterator2->current() instanceof Media) { |
125 |
| - // Write relationship for image drawing |
126 |
| - $iterator2->current()->relationId = 'rId' . $relId; |
127 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator2->current()->getIndexedFilename()); |
128 |
| - ++$relId; |
129 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator2->current()->getIndexedFilename()); |
130 |
| - ++$relId; |
131 |
| - } elseif ($iterator2->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
132 |
| - // Write relationship for image drawing |
133 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename()); |
134 |
| - $iterator2->current()->relationId = 'rId' . $relId; |
135 |
| - |
136 |
| - ++$relId; |
137 |
| - } elseif ($iterator2->current() instanceof ShapeChart) { |
138 |
| - // Write relationship for chart drawing |
139 |
| - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename()); |
140 |
| - $iterator2->current()->relationId = 'rId' . $relId; |
141 |
| - |
142 |
| - ++$relId; |
143 |
| - } |
144 |
| - $iterator2->next(); |
| 102 | + // Loop trough images and write relationships |
| 103 | + while (count($collections)) { |
| 104 | + $iterator = array_shift($collections); |
| 105 | + |
| 106 | + while ($iterator->valid()) { |
| 107 | + $currentShape = $iterator->current(); |
| 108 | + |
| 109 | + if ($currentShape instanceof Media) { |
| 110 | + // Write relationship for image drawing |
| 111 | + $currentShape->relationId = 'rId' . $relId; |
| 112 | + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $currentShape->getIndexedFilename()); |
| 113 | + ++$relId; |
| 114 | + $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $currentShape->getIndexedFilename()); |
| 115 | + ++$relId; |
| 116 | + } elseif ($currentShape instanceof ShapeDrawing\AbstractDrawingAdapter) { |
| 117 | + // Write relationship for image drawing |
| 118 | + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $currentShape->getIndexedFilename()); |
| 119 | + $currentShape->relationId = 'rId' . $relId; |
| 120 | + ++$relId; |
| 121 | + } elseif ($currentShape instanceof ShapeChart) { |
| 122 | + // Write relationship for chart drawing |
| 123 | + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $currentShape->getIndexedFilename()); |
| 124 | + $currentShape->relationId = 'rId' . $relId; |
| 125 | + ++$relId; |
| 126 | + } elseif ($currentShape instanceof ShapeContainerInterface) { |
| 127 | + $collections[] = $currentShape->getShapeCollection()->getIterator(); |
145 | 128 | }
|
146 |
| - } |
147 | 129 |
|
148 |
| - $iterator->next(); |
| 130 | + $iterator->next(); |
| 131 | + } |
149 | 132 | }
|
150 | 133 | }
|
151 | 134 |
|
|
0 commit comments