Skip to content

Commit

Permalink
Merge pull request #197 from Progi1984/featSlideVisible
Browse files Browse the repository at this point in the history
Support for Visibility for slides
  • Loading branch information
Progi1984 committed Mar 31, 2016
2 parents 5764b5c + 0441e2e commit f5141e0
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- ODPresentation & PowerPoint2007 Writer : language property to TextElement - @skrajewski & @Progi1984 GH-180
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
- ODPresentation & PowerPoint2007 Writer : Support for video - @Progi1984 GH-123
- ODPresentation & PowerPoint2007 Writer : Support for Visibility for slides - @Progi1984
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120

## 0.6.0 - 2016-01-24
Expand Down
16 changes: 14 additions & 2 deletions docs/slides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ Slides
Slides are pages in a presentation. Slides are stored as a zero based array in ``PHPPresentation`` object. Use ``createSlide`` to create a new slide and retrieve the slide for other operation such as creating shapes for that slide.

Name
-------
----

By default, a slide has not a name.
You can define it with the method ``setName``.

.. code-block:: php
$oSlide = $oPHPPresentation->createSlide();
$oSlide->setName('Title of the slide');
$oSlide->setName('Title of the slide');
Visibility
----------

By default, a slide is visible.
You can define it with the method ``setIsVisible``.

.. code-block:: php
$oSlide = $oPHPPresentation->createSlide();
$oSlide->setIsVisible(false);
var_dump($oSlide->isVisible());
25 changes: 25 additions & 0 deletions src/PhpPresentation/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
*/
class Slide implements ComparableInterface, ShapeContainerInterface
{
/**
* The slide is shown in presentation
* @var bool
*/
protected $isVisible = true;

/**
* Parent presentation
*
Expand Down Expand Up @@ -74,6 +80,7 @@ class Slide implements ComparableInterface, ShapeContainerInterface
* @var \PhpOffice\PhpPresentation\Slide\Note
*/
private $slideNote;

/**
*
* @var \PhpOffice\PhpPresentation\Slide\Transition
Expand Down Expand Up @@ -515,4 +522,22 @@ public function setBackground(AbstractBackground $background = null)
$this->background = $background;
return $this;
}

/**
* @return boolean
*/
public function isVisible()
{
return $this->isVisible;
}

/**
* @param boolean $value
* @return Slide
*/
public function setIsVisible($value = true)
{
$this->isVisible = (bool)$value;
return $this;
}
}
1 change: 1 addition & 0 deletions src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
$objWriter->writeAttribute('style:name', 'stylePage'.$incPage);
// style:style/style:drawing-page-properties
$objWriter->startElement('style:drawing-page-properties');
$objWriter->writeAttributeIf(!$slide->isVisible(), 'presentation:visibility', 'hidden');
if (!is_null($oTransition = $slide->getTransition())) {
$objWriter->writeAttribute('presentation:duration', 'PT'.number_format($oTransition->getAdvanceTimeTrigger() / 1000, 6, '.', '').'S');
if ($oTransition->hasManualTrigger()) {
Expand Down
3 changes: 2 additions & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ public function writeSlide(Slide $pSlide)
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
$objWriter->writeAttributeIf(!$pSlide->isVisible(), 'show', 0);

// p:cSld
// p:sld\p:cSld
$objWriter->startElement('p:cSld');

// Background
Expand Down
10 changes: 10 additions & 0 deletions tests/PhpPresentation/Tests/SlideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ public function testTransition()
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setTransition(null));
$this->assertNull($object->getTransition());
}

public function testVisible()
{
$object = new Slide();
$this->assertTrue($object->isVisible());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setIsVisible(false));
$this->assertFalse($object->isVisible());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setIsVisible());
$this->assertTrue($object->isVisible());
}
}
17 changes: 17 additions & 0 deletions tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,21 @@ public function testTransition()
$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$this->assertContains('manual', $pres->getElementAttribute($element, 'presentation:transition-type', 'content.xml'));
}

public function testVisibility()
{
$expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';

$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
$this->assertFalse($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));

$oSlide = $this->oPresentation->getActiveSlide();
$oSlide->setIsVisible(false);

$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
$this->assertTrue($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));
$this->assertEquals('hidden', $pres->getElementAttribute($expectedElement, 'presentation:visibility', 'content.xml'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ class ObjectsChartTest extends \PHPUnit_Framework_TestCase
*/
public function tearDown()
{
parent::tearDown();
TestHelperDOCX::clear();
}

public function testAxisFont()
{

$phpPresentation = new PhpPresentation();
$oSlide = $phpPresentation->getActiveSlide();
$oPhpPresentation = new PhpPresentation();
$oSlide = $oPhpPresentation->getActiveSlide();
$oShape = $oSlide->createChartShape();
$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
$oBar = new Bar();
Expand All @@ -68,25 +66,26 @@ public function testAxisFont()
$oShape->getPlotArea()->getAxisY()->getFont()->setSize(16);
$oShape->getPlotArea()->getAxisY()->getFont()->setName('Arial');

$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
$this->assertTrue($oXMLDoc->fileExists('Object 1/content.xml'));

$element = '/office:document-content/office:body/office:chart/chart:chart';
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('chart:bar', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));
$this->assertTrue($oXMLDoc->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('chart:bar', $oXMLDoc->getElementAttribute($element, 'chart:class', 'Object 1/content.xml'));

$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisX\']/style:text-properties';
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('#AABBCC', $pres->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color XAxis
$this->assertEquals('italic', $pres->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic XAxis
$this->assertEquals('10pt', $pres->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size XAxis
$this->assertEquals('Calibri', $pres->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size XAxis
$this->assertTrue($oXMLDoc->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('#AABBCC', $oXMLDoc->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color XAxis
$this->assertEquals('italic', $oXMLDoc->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic XAxis
$this->assertEquals('10pt', $oXMLDoc->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size XAxis
$this->assertEquals('Calibri', $oXMLDoc->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size XAxis

$element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisY\']/style:text-properties';
$this->assertTrue($pres->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('#00FF00', $pres->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color YAxis
$this->assertEquals('normal', $pres->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic YAxis
$this->assertEquals('16pt', $pres->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size YAxis
$this->assertEquals('Arial', $pres->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size YAxis
$this->assertTrue($oXMLDoc->elementExists($element, 'Object 1/content.xml'));
$this->assertEquals('#00FF00', $oXMLDoc->getElementAttribute($element, 'fo:color', 'Object 1/content.xml'));//Color YAxis
$this->assertEquals('normal', $oXMLDoc->getElementAttribute($element, 'fo:font-style', 'Object 1/content.xml'));//Italic YAxis
$this->assertEquals('16pt', $oXMLDoc->getElementAttribute($element, 'fo:font-size', 'Object 1/content.xml'));//Size YAxis
$this->assertEquals('Arial', $oXMLDoc->getElementAttribute($element, 'fo:font-family', 'Object 1/content.xml'));//Size YAxis

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,4 +1007,23 @@ public function testTransition()
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
$this->assertContains('1', $pres->getElementAttribute($element, 'advClick', 'ppt/slides/slide1.xml'));
}

public function testVisibility()
{
$expectedElement = '/p:sld';

$oPhpPresentation = new PhpPresentation();

$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
$this->assertFalse($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));

$oSlide = $oPhpPresentation->getActiveSlide();
$oSlide->setIsVisible(false);

$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
$this->assertTrue($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));
$this->assertEquals(0, $pres->getElementAttribute($expectedElement, 'show', 'ppt/slides/slide1.xml'));
}
}
4 changes: 2 additions & 2 deletions tests/PhpPresentation/Tests/_includes/TestHelperDOCX.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class TestHelperDOCX
/**
* Get document content
*
* @param \PhpOffice\PhpPresentation\PhpPresentation $PhpPresentation
* @param \PhpOffice\PhpPresentation\PhpPresentation $phpPresentation
* @param string $writerName
* @return \PhpOffice\PhpPresentation\Tests\XmlDocument
*/
public static function getDocument(PhpPresentation $phpPresentation, $writerName = 'PowerPoint2007')
public static function getDocument(PhpPresentation $phpPresentation, $writerName)
{
self::$file = tempnam(sys_get_temp_dir(), 'PhpPresentation');
if (!is_dir(sys_get_temp_dir() . '/PhpPresentation_Unit_Test/')) {
Expand Down

0 comments on commit f5141e0

Please sign in to comment.