Skip to content

Commit

Permalink
PHPOffice#240 : Fixed the corruption when an addExternalSlide is called
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Mar 3, 2017
1 parent 89b566d commit fb9791a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions samples/Sample_20_ExternalSlide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include_once 'Sample_Header.php';

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\RichText;

// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();
$objPHPPresentation->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';
}
4 changes: 3 additions & 1 deletion src/PhpPresentation/PhpPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ public function addExternalSlide(Slide $slide)
{
$slide->rebindParent($this);

$this->addMasterSlide($slide->getSlideLayout()->getSlideMaster());

return $this->addSlide($slide);
}

Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions src/PhpPresentation/Slide/SlideLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ public function setLayoutName($layoutName)
$this->layoutName = $layoutName;
return $this;
}

/**
* @return SlideMaster
*/
public function getSlideMaster()
{
return $this->slideMaster;
}
}
10 changes: 10 additions & 0 deletions tests/PhpPresentation/Tests/Slide/SlideLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit fb9791a

Please sign in to comment.