diff --git a/samples/Sample_20_ExternalSlide.php b/samples/Sample_20_ExternalSlide.php new file mode 100644 index 000000000..316855be1 --- /dev/null +++ b/samples/Sample_20_ExternalSlide.php @@ -0,0 +1,23 @@ +removeSlideByIndex(0); + +$oReader = \PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007'); +$oPresentation04 = $oReader->load(__DIR__ . '/results/Sample_04_Table.pptx'); + +foreach ($oPresentation04->getAllSlides() as $oSlide) { + $objPHPPresentation->addExternalSlide($oSlide); +} + +// Save file +echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers); +if (!CLI) { + include_once 'Sample_Footer.php'; +} \ No newline at end of file diff --git a/src/PhpPresentation/PhpPresentation.php b/src/PhpPresentation/PhpPresentation.php index 0753924d7..580334289 100644 --- a/src/PhpPresentation/PhpPresentation.php +++ b/src/PhpPresentation/PhpPresentation.php @@ -324,6 +324,8 @@ public function addExternalSlide(Slide $slide) { $slide->rebindParent($this); + $this->addMasterSlide($slide->getSlideLayout()->getSlideMaster()); + return $this->addSlide($slide); } @@ -353,8 +355,8 @@ public function createMasterSlide() * Add masterslide * * @param \PhpOffice\PhpPresentation\Slide\SlideMaster $slide + * @return \PhpOffice\PhpPresentation\Slide\SlideMaster * @throws \Exception - * @retun \PhpOffice\PhpPresentation\Slide\SlideMaster */ public function addMasterSlide(SlideMaster $slide = null) { diff --git a/src/PhpPresentation/Slide/SlideLayout.php b/src/PhpPresentation/Slide/SlideLayout.php index 0b11b9695..72f42b8e5 100644 --- a/src/PhpPresentation/Slide/SlideLayout.php +++ b/src/PhpPresentation/Slide/SlideLayout.php @@ -88,4 +88,12 @@ public function setLayoutName($layoutName) $this->layoutName = $layoutName; return $this; } + + /** + * @return SlideMaster + */ + public function getSlideMaster() + { + return $this->slideMaster; + } } diff --git a/tests/PhpPresentation/Tests/Slide/SlideLayoutTest.php b/tests/PhpPresentation/Tests/Slide/SlideLayoutTest.php index eab73ea48..aa01d46ff 100644 --- a/tests/PhpPresentation/Tests/Slide/SlideLayoutTest.php +++ b/tests/PhpPresentation/Tests/Slide/SlideLayoutTest.php @@ -50,4 +50,14 @@ public function testLayoutName() $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideLayout', $object->setLayoutName($expectedLayoutName)); $this->assertEquals($expectedLayoutName, $object->getLayoutName()); } + + public function testSlideMaster() + { + // Mocks + $mockSlideMaster = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Slide\SlideMaster'); + + $object = new SlideLayout($mockSlideMaster); + + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideMaster', $object->getSlideMaster()); + } }