Skip to content

Commit e63d716

Browse files
committed
Support for Visibility for slides
1 parent def4684 commit e63d716

File tree

8 files changed

+89
-3
lines changed

8 files changed

+89
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- ODPresentation & PowerPoint2007 & Serialized Writer : Support for Zip Adapter - @Progi1984 GH-176
2323
- ODPresentation & PowerPoint2007 Writer : language property to TextElement - @skrajewski & @Progi1984 GH-180
2424
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
25+
- ODPresentation & PowerPoint2007 Writer : Support for Visibility for slides - @Progi1984
2526

2627
## 0.6.0 - 2016-01-24
2728

docs/slides.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ Slides
66
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.
77

88
Name
9-
-------
9+
----
1010

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

1414
.. code-block:: php
1515
1616
$oSlide = $oPHPPresentation->createSlide();
17-
$oSlide->setName('Title of the slide');
17+
$oSlide->setName('Title of the slide');
18+
19+
Visibility
20+
----------
21+
22+
By default, a slide is visible.
23+
You can define it with the method ``setIsVisible``.
24+
25+
.. code-block:: php
26+
27+
$oSlide = $oPHPPresentation->createSlide();
28+
$oSlide->setIsVisible(false);
29+
var_dump($oSlide->isVisible());

src/PhpPresentation/Slide.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
*/
3535
class Slide implements ComparableInterface, ShapeContainerInterface
3636
{
37+
/**
38+
* The slide is shown in presentation
39+
* @var bool
40+
*/
41+
protected $isVisible = true;
42+
3743
/**
3844
* Parent presentation
3945
*
@@ -74,6 +80,7 @@ class Slide implements ComparableInterface, ShapeContainerInterface
7480
* @var \PhpOffice\PhpPresentation\Slide\Note
7581
*/
7682
private $slideNote;
83+
7784
/**
7885
*
7986
* @var \PhpOffice\PhpPresentation\Slide\Transition
@@ -515,4 +522,22 @@ public function setBackground(AbstractBackground $background = null)
515522
$this->background = $background;
516523
return $this;
517524
}
525+
526+
/**
527+
* @return boolean
528+
*/
529+
public function isVisible()
530+
{
531+
return $this->isVisible;
532+
}
533+
534+
/**
535+
* @param boolean $value
536+
* @return Slide
537+
*/
538+
public function setIsVisible($value = true)
539+
{
540+
$this->isVisible = (bool)$value;
541+
return $this;
542+
}
518543
}

src/PhpPresentation/Writer/ODPresentation/Content.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
10691069
$objWriter->writeAttribute('style:name', 'stylePage'.$incPage);
10701070
// style:style/style:drawing-page-properties
10711071
$objWriter->startElement('style:drawing-page-properties');
1072+
$objWriter->writeAttributeIf(!$slide->isVisible(), 'presentation:visibility', 'hidden');
10721073
if (!is_null($oTransition = $slide->getTransition())) {
10731074
$objWriter->writeAttribute('presentation:duration', 'PT'.number_format($oTransition->getAdvanceTimeTrigger() / 1000, 6, '.', '').'S');
10741075
if ($oTransition->hasManualTrigger()) {

src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ public function writeSlide(Slide $pSlide)
362362
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
363363
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
364364
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
365+
$objWriter->writeAttributeIf(!$pSlide->isVisible(), 'show', 0);
365366

366-
// p:cSld
367+
// p:sld\p:cSld
367368
$objWriter->startElement('p:cSld');
368369

369370
// Background

tests/PhpPresentation/Tests/SlideTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,14 @@ public function testTransition()
118118
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setTransition(null));
119119
$this->assertNull($object->getTransition());
120120
}
121+
122+
public function testVisible()
123+
{
124+
$object = new Slide();
125+
$this->assertTrue($object->isVisible());
126+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setIsVisible(false));
127+
$this->assertFalse($object->isVisible());
128+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setIsVisible());
129+
$this->assertTrue($object->isVisible());
130+
}
121131
}

tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,4 +809,21 @@ public function testTransition()
809809
$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
810810
$this->assertContains('manual', $pres->getElementAttribute($element, 'presentation:transition-type', 'content.xml'));
811811
}
812+
813+
public function testVisibility()
814+
{
815+
$expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';
816+
817+
$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
818+
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
819+
$this->assertFalse($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));
820+
821+
$oSlide = $this->oPresentation->getActiveSlide();
822+
$oSlide->setIsVisible(false);
823+
824+
$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
825+
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
826+
$this->assertTrue($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));
827+
$this->assertEquals('hidden', $pres->getElementAttribute($expectedElement, 'presentation:visibility', 'content.xml'));
828+
}
812829
}

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,23 @@ public function testTransition()
946946
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
947947
$this->assertContains('1', $pres->getElementAttribute($element, 'advClick', 'ppt/slides/slide1.xml'));
948948
}
949+
950+
public function testVisibility()
951+
{
952+
$expectedElement = '/p:sld';
953+
954+
$oPhpPresentation = new PhpPresentation();
955+
956+
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
957+
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
958+
$this->assertFalse($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));
959+
960+
$oSlide = $oPhpPresentation->getActiveSlide();
961+
$oSlide->setIsVisible(false);
962+
963+
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
964+
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
965+
$this->assertTrue($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));
966+
$this->assertEquals(0, $pres->getElementAttribute($expectedElement, 'show', 'ppt/slides/slide1.xml'));
967+
}
949968
}

0 commit comments

Comments
 (0)