Skip to content

Commit 85c7821

Browse files
authored
Merge pull request #785 from Progi1984/pr692
PowerPoint2007 Writer: Extract relations from nested ShapeContainerInterface objects
2 parents 21efd17 + 92adcaa commit 85c7821

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

docs/changes/1.1.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- PowerPoint2007 Reader : Fixed reading of RichText shape in Note - [@aelliott1485](https://github.com/aelliott1485) in [#782](https://github.com/PHPOffice/PHPPresentation/pull/782)
3434
- PowerPoint2007 Writer : Fixed broken animation for first shape - [@shannan1989](https://github.com/shannan1989) in [#783](https://github.com/PHPOffice/PHPPresentation/pull/783)
3535
- Samples : Allow to run without composer - [@pal-software](https://github.com/pal-software) in [#784](https://github.com/PHPOffice/PHPPresentation/pull/784)
36+
- PowerPoint2007 Writer: Extract relations from nested ShapeContainerInterface objects - [@DennisBirkholz](https://github.com/DennisBirkholz) in [#785](https://github.com/PHPOffice/PHPPresentation/pull/785)
3637

3738
## Miscellaneous
3839

src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use PhpOffice\PhpPresentation\Shape\RichText\Run;
3232
use PhpOffice\PhpPresentation\Shape\RichText\TextElement;
3333
use PhpOffice\PhpPresentation\Shape\Table as ShapeTable;
34+
use PhpOffice\PhpPresentation\ShapeContainerInterface;
3435
use PhpOffice\PhpPresentation\Slide;
3536
use PhpOffice\PhpPresentation\Slide\Background\Image;
3637
use PhpOffice\PhpPresentation\Slide\Note;
@@ -96,56 +97,38 @@ protected function writeSlideRelationships(Slide $pSlide): string
9697

9798
// Write drawing relationships?
9899
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()];
117101

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();
145128
}
146-
}
147129

148-
$iterator->next();
130+
$iterator->next();
131+
}
149132
}
150133
}
151134

0 commit comments

Comments
 (0)