Skip to content

Commit f5141e0

Browse files
committed
Merge pull request #197 from Progi1984/featSlideVisible
Support for Visibility for slides
2 parents 5764b5c + 0441e2e commit f5141e0

File tree

10 files changed

+107
-22
lines changed

10 files changed

+107
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- ODPresentation & PowerPoint2007 Writer : language property to TextElement - @skrajewski & @Progi1984 GH-180
2525
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
2626
- ODPresentation & PowerPoint2007 Writer : Support for video - @Progi1984 GH-123
27+
- ODPresentation & PowerPoint2007 Writer : Support for Visibility for slides - @Progi1984
2728
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120
2829

2930
## 0.6.0 - 2016-01-24

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
@@ -1120,6 +1120,7 @@ public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
11201120
$objWriter->writeAttribute('style:name', 'stylePage'.$incPage);
11211121
// style:style/style:drawing-page-properties
11221122
$objWriter->startElement('style:drawing-page-properties');
1123+
$objWriter->writeAttributeIf(!$slide->isVisible(), 'presentation:visibility', 'hidden');
11231124
if (!is_null($oTransition = $slide->getTransition())) {
11241125
$objWriter->writeAttribute('presentation:duration', 'PT'.number_format($oTransition->getAdvanceTimeTrigger() / 1000, 6, '.', '').'S');
11251126
if ($oTransition->hasManualTrigger()) {

src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php

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

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

370371
// 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
@@ -852,4 +852,21 @@ public function testTransition()
852852
$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
853853
$this->assertContains('manual', $pres->getElementAttribute($element, 'presentation:transition-type', 'content.xml'));
854854
}
855+
856+
public function testVisibility()
857+
{
858+
$expectedElement = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';
859+
860+
$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
861+
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
862+
$this->assertFalse($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));
863+
864+
$oSlide = $this->oPresentation->getActiveSlide();
865+
$oSlide->setIsVisible(false);
866+
867+
$pres = TestHelperDOCX::getDocument($this->oPresentation, 'ODPresentation');
868+
$this->assertTrue($pres->elementExists($expectedElement, 'content.xml'));
869+
$this->assertTrue($pres->attributeElementExists($expectedElement, 'presentation:visibility', 'content.xml'));
870+
$this->assertEquals('hidden', $pres->getElementAttribute($expectedElement, 'presentation:visibility', 'content.xml'));
871+
}
855872
}

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ class ObjectsChartTest extends \PHPUnit_Framework_TestCase
4747
*/
4848
public function tearDown()
4949
{
50-
parent::tearDown();
5150
TestHelperDOCX::clear();
5251
}
5352

5453
public function testAxisFont()
5554
{
56-
57-
$phpPresentation = new PhpPresentation();
58-
$oSlide = $phpPresentation->getActiveSlide();
55+
$oPhpPresentation = new PhpPresentation();
56+
$oSlide = $oPhpPresentation->getActiveSlide();
5957
$oShape = $oSlide->createChartShape();
6058
$oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2));
6159
$oBar = new Bar();
@@ -68,25 +66,26 @@ public function testAxisFont()
6866
$oShape->getPlotArea()->getAxisY()->getFont()->setSize(16);
6967
$oShape->getPlotArea()->getAxisY()->getFont()->setName('Arial');
7068

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

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

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

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

9190
}
9291

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,4 +1007,23 @@ public function testTransition()
10071007
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
10081008
$this->assertContains('1', $pres->getElementAttribute($element, 'advClick', 'ppt/slides/slide1.xml'));
10091009
}
1010+
1011+
public function testVisibility()
1012+
{
1013+
$expectedElement = '/p:sld';
1014+
1015+
$oPhpPresentation = new PhpPresentation();
1016+
1017+
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
1018+
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
1019+
$this->assertFalse($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));
1020+
1021+
$oSlide = $oPhpPresentation->getActiveSlide();
1022+
$oSlide->setIsVisible(false);
1023+
1024+
$pres = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
1025+
$this->assertTrue($pres->elementExists($expectedElement, 'ppt/slides/slide1.xml'));
1026+
$this->assertTrue($pres->attributeElementExists($expectedElement, 'show', 'ppt/slides/slide1.xml'));
1027+
$this->assertEquals(0, $pres->getElementAttribute($expectedElement, 'show', 'ppt/slides/slide1.xml'));
1028+
}
10101029
}

tests/PhpPresentation/Tests/_includes/TestHelperDOCX.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class TestHelperDOCX
3535
/**
3636
* Get document content
3737
*
38-
* @param \PhpOffice\PhpPresentation\PhpPresentation $PhpPresentation
38+
* @param \PhpOffice\PhpPresentation\PhpPresentation $phpPresentation
3939
* @param string $writerName
4040
* @return \PhpOffice\PhpPresentation\Tests\XmlDocument
4141
*/
42-
public static function getDocument(PhpPresentation $phpPresentation, $writerName = 'PowerPoint2007')
42+
public static function getDocument(PhpPresentation $phpPresentation, $writerName)
4343
{
4444
self::$file = tempnam(sys_get_temp_dir(), 'PhpPresentation');
4545
if (!is_dir(sys_get_temp_dir() . '/PhpPresentation_Unit_Test/')) {

0 commit comments

Comments
 (0)