Skip to content

Commit

Permalink
PowerPoint2007 Writer: Extract relations from nested ShapeContainerIn…
Browse files Browse the repository at this point in the history
…terface objects
  • Loading branch information
DennisBirkholz authored and Progi1984 committed Dec 12, 2023
1 parent 21efd17 commit 46d30e5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 47 deletions.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
77 changes: 30 additions & 47 deletions src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit 46d30e5

Please sign in to comment.