diff --git a/docs/changes/1.1.0.md b/docs/changes/1.1.0.md index 189abd6ce..40b49b0db 100644 --- a/docs/changes/1.1.0.md +++ b/docs/changes/1.1.0.md @@ -33,6 +33,7 @@ - PowerPoint2007 Reader : Fixed reading of RichText shape in Note - [@aelliott1485](https://github.com/aelliott1485) in [#782](https://github.com/PHPOffice/PHPPresentation/pull/782) - PowerPoint2007 Writer : Fixed broken animation for first shape - [@shannan1989](https://github.com/shannan1989) in [#783](https://github.com/PHPOffice/PHPPresentation/pull/783) - Samples : Allow to run without composer - [@pal-software](https://github.com/pal-software) in [#784](https://github.com/PHPOffice/PHPPresentation/pull/784) +- PowerPoint2007 Writer: Extract relations from nested ShapeContainerInterface objects - [@DennisBirkholz](https://github.com/DennisBirkholz) in [#785](https://github.com/PHPOffice/PHPPresentation/pull/785) ## Miscellaneous diff --git a/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php b/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php index 7e29fc0da..00da6cbf8 100644 --- a/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php +++ b/src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php @@ -31,6 +31,7 @@ use PhpOffice\PhpPresentation\Shape\RichText\Run; use PhpOffice\PhpPresentation\Shape\RichText\TextElement; use PhpOffice\PhpPresentation\Shape\Table as ShapeTable; +use PhpOffice\PhpPresentation\ShapeContainerInterface; use PhpOffice\PhpPresentation\Slide; use PhpOffice\PhpPresentation\Slide\Background\Image; use PhpOffice\PhpPresentation\Slide\Note; @@ -96,56 +97,38 @@ protected function writeSlideRelationships(Slide $pSlide): string // Write drawing relationships? if ($pSlide->getShapeCollection()->count() > 0) { - // Loop trough images and write relationships - $iterator = $pSlide->getShapeCollection()->getIterator(); - while ($iterator->valid()) { - if ($iterator->current() instanceof Media) { - // Write relationship for image drawing - $iterator->current()->relationId = 'rId' . $relId; - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename()); - ++$relId; - $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); - ++$relId; - } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { - // Write relationship for image drawing - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator->current()->getIndexedFilename()); - $iterator->current()->relationId = 'rId' . $relId; - ++$relId; - } elseif ($iterator->current() instanceof ShapeChart) { - // Write relationship for chart drawing - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename()); + $collections = [$pSlide->getShapeCollection()->getIterator()]; - $iterator->current()->relationId = 'rId' . $relId; - - ++$relId; - } elseif ($iterator->current() instanceof Group) { - $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); - while ($iterator2->valid()) { - if ($iterator2->current() instanceof Media) { - // Write relationship for image drawing - $iterator2->current()->relationId = 'rId' . $relId; - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator2->current()->getIndexedFilename()); - ++$relId; - $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator2->current()->getIndexedFilename()); - ++$relId; - } elseif ($iterator2->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { - // Write relationship for image drawing - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename()); - $iterator2->current()->relationId = 'rId' . $relId; - - ++$relId; - } elseif ($iterator2->current() instanceof ShapeChart) { - // Write relationship for chart drawing - $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename()); - $iterator2->current()->relationId = 'rId' . $relId; - - ++$relId; - } - $iterator2->next(); + // Loop trough images and write relationships + while (count($collections)) { + $iterator = array_shift($collections); + + while ($iterator->valid()) { + $currentShape = $iterator->current(); + + if ($currentShape instanceof Media) { + // Write relationship for image drawing + $currentShape->relationId = 'rId' . $relId; + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $currentShape->getIndexedFilename()); + ++$relId; + $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $currentShape->getIndexedFilename()); + ++$relId; + } elseif ($currentShape instanceof ShapeDrawing\AbstractDrawingAdapter) { + // Write relationship for image drawing + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $currentShape->getIndexedFilename()); + $currentShape->relationId = 'rId' . $relId; + ++$relId; + } elseif ($currentShape instanceof ShapeChart) { + // Write relationship for chart drawing + $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $currentShape->getIndexedFilename()); + $currentShape->relationId = 'rId' . $relId; + ++$relId; + } elseif ($currentShape instanceof ShapeContainerInterface) { + $collections[] = $currentShape->getShapeCollection()->getIterator(); } - } - $iterator->next(); + $iterator->next(); + } } }