Skip to content

Commit bd75454

Browse files
committed
Merge pull request #204 from Progi1984/issue120
#120 : Presentation with predefined View Type
2 parents def4684 + 7c958ef commit bd75454

File tree

8 files changed

+188
-12
lines changed

8 files changed

+188
-12
lines changed

CHANGELOG.md

+1
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+
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120
2526

2627
## 0.6.0 - 2016-01-24
2728

docs/general.rst

+39
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@ Presentation Properties
7575

7676
You can define some properties which are relative to the presentation, like the zoom or the thumbnail.
7777

78+
Comments
79+
````````
80+
81+
You can define if the presentation display or not the comments with the method ``setCommentVisible``.
82+
83+
.. code-block:: php
84+
85+
$oPresentation = new PhpPresentation();
86+
$oProperties = $oPresentation->getPresentationProperties();
87+
// Get the display for comment
88+
var_export($oProperties->isCommentVisible());
89+
// Output : false
90+
// Enable the display for comment
91+
$oProperties->setCommentVisible(true);
92+
// Get the display for comment
93+
var_export($oProperties->isCommentVisible());
94+
// Output : true
95+
96+
Last View
97+
`````````
98+
99+
You can define the last view of the presentation with the method ``setLastView``.
100+
101+
.. code-block:: php
102+
103+
$oPresentation = new PhpPresentation();
104+
$oProperties = $oPresentation->getPresentationProperties();
105+
// Get the last view of the presentation
106+
echo $oProperties->getZoom();
107+
// Output : PresentationProperties::VIEW_SLIDE
108+
// Set the last view of the presentation
109+
$oProperties->setLastView(PresentationProperties::VIEW_NOTES);
110+
// Get the last view of the presentation
111+
echo $oProperties->getZoom();
112+
// Output : PresentationProperties::VIEW_NOTES
78113
79114
Thumbnail
80115
`````````
@@ -99,7 +134,11 @@ You can define the zoom of the presentation with the method ``setZoom``.
99134
100135
$oPresentation = new PhpPresentation();
101136
$oProperties = $oPresentation->getPresentationProperties();
137+
// Get zoom of the presentation
138+
echo $oProperties->getZoom();
139+
// Output : 1
102140
// Set zoom of the presentation (3 = 300%)
103141
$oProperties->setZoom(3);
104142
// Get zoom of the presentation
105143
echo $oProperties->getZoom();
144+
// Output : 3

src/PhpPresentation/PhpPresentation.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,35 @@ class PhpPresentation
3030
*
3131
* @var \PhpOffice\PhpPresentation\DocumentProperties
3232
*/
33-
private $documentProperties;
34-
33+
protected $documentProperties;
34+
3535
/**
3636
* Presentation properties
3737
*
3838
* @var \PhpOffice\PhpPresentation\PresentationProperties
3939
*/
40-
private $presentationProperties;
40+
protected $presentationProps;
4141

4242
/**
4343
* Document layout
4444
*
4545
* @var \PhpOffice\PhpPresentation\DocumentLayout
4646
*/
47-
private $layout;
47+
protected $layout;
4848

4949
/**
5050
* Collection of Slide objects
5151
*
5252
* @var \PhpOffice\PhpPresentation\Slide[]
5353
*/
54-
private $slideCollection = array();
54+
protected $slideCollection = array();
5555

5656
/**
5757
* Active slide index
5858
*
5959
* @var int
6060
*/
61-
private $activeSlideIndex = 0;
61+
protected $activeSlideIndex = 0;
6262

6363
/**
6464
* Create a new PhpPresentation with one Slide
@@ -128,7 +128,7 @@ public function setDocumentProperties(DocumentProperties $value)
128128
*/
129129
public function getPresentationProperties()
130130
{
131-
return $this->presentationProperties;
131+
return $this->presentationProps;
132132
}
133133

134134
/**
@@ -139,7 +139,7 @@ public function getPresentationProperties()
139139
*/
140140
public function setPresentationProperties(PresentationProperties $value)
141141
{
142-
$this->presentationProperties = $value;
142+
$this->presentationProps = $value;
143143
return $this;
144144
}
145145

src/PhpPresentation/PresentationProperties.php

+70
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
*/
2222
class PresentationProperties
2323
{
24+
const VIEW_HANDOUT = 'handoutView';
25+
const VIEW_NOTES = 'notesView';
26+
const VIEW_NOTES_MASTER = 'notesMasterView';
27+
const VIEW_OUTLINE = 'outlineView';
28+
const VIEW_SLIDE = 'sldView';
29+
const VIEW_SLIDE_MASTER = 'sldMasterView';
30+
const VIEW_SLIDE_SORTER = 'sldSorterView';
31+
const VIEW_SLIDE_THUMBNAIL = 'sldThumbnailView';
32+
33+
protected $arrayView = array(
34+
self::VIEW_HANDOUT,
35+
self::VIEW_NOTES,
36+
self::VIEW_NOTES_MASTER,
37+
self::VIEW_OUTLINE,
38+
self::VIEW_SLIDE,
39+
self::VIEW_SLIDE_MASTER,
40+
self::VIEW_SLIDE_SORTER,
41+
self::VIEW_SLIDE_THUMBNAIL,
42+
);
43+
2444
/*
2545
* @var boolean
2646
*/
@@ -42,6 +62,16 @@ class PresentationProperties
4262
* @var float
4363
*/
4464
protected $zoom = 1;
65+
66+
/*
67+
* @var boolean
68+
*/
69+
protected $lastView = self::VIEW_SLIDE;
70+
71+
/*
72+
* @var boolean
73+
*/
74+
protected $isCommentVisible = false;
4575

4676
/**
4777
* @return bool
@@ -128,4 +158,44 @@ public function getZoom()
128158
{
129159
return $this->zoom;
130160
}
161+
162+
/**
163+
* @param string $value
164+
* @return $this
165+
*/
166+
public function setLastView($value = self::VIEW_SLIDE)
167+
{
168+
if (in_array($value, $this->arrayView)) {
169+
$this->lastView = $value;
170+
}
171+
return $this;
172+
}
173+
174+
/**
175+
* @return string
176+
*/
177+
public function getLastView()
178+
{
179+
return $this->lastView;
180+
}
181+
182+
/**
183+
* @param bool $value
184+
* @return $this
185+
*/
186+
public function setCommentVisible($value = false)
187+
{
188+
if (is_bool($value)) {
189+
$this->isCommentVisible = $value;
190+
}
191+
return $this;
192+
}
193+
194+
/**
195+
* @return string
196+
*/
197+
public function isCommentVisible()
198+
{
199+
return $this->isCommentVisible;
200+
}
131201
}

src/PhpPresentation/Writer/PowerPoint2007/PptViewProps.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function render()
2121
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
2222
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
2323
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
24-
$objWriter->writeAttribute('showComments', '0');
24+
$objWriter->writeAttribute('showComments', $this->getPresentation()->getPresentationProperties()->isCommentVisible() ? 1 : 0);
25+
$objWriter->writeAttribute('lastView', $this->getPresentation()->getPresentationProperties()->getLastView());
2526

2627
// p:viewPr > p:slideViewPr
2728
$objWriter->startElement('p:slideViewPr');

tests/PhpPresentation/Tests/PhpPresentationTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpOffice\PhpPresentation\DocumentLayout;
2121
use PhpOffice\PhpPresentation\DocumentProperties;
2222
use PhpOffice\PhpPresentation\PhpPresentation;
23+
use PhpOffice\PhpPresentation\PresentationProperties;
2324

2425
/**
2526
* Test class for PhpPresentation
@@ -59,6 +60,14 @@ public function testProperties()
5960
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getDocumentProperties());
6061
}
6162

63+
public function testPresentationProperties()
64+
{
65+
$object = new PhpPresentation();
66+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->getPresentationProperties());
67+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->setPresentationProperties(new PresentationProperties()));
68+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->getPresentationProperties());
69+
}
70+
6271
/**
6372
* Test add external slide
6473
*/

tests/PhpPresentation/Tests/PresentationPropertiesTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
*/
2727
class PresentationPropertiesTest extends \PHPUnit_Framework_TestCase
2828
{
29+
public function testCommentVisible()
30+
{
31+
$object = new PresentationProperties();
32+
$this->assertFalse($object->isCommentVisible());
33+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setCommentVisible('AAAA'));
34+
$this->assertFalse($object->isCommentVisible());
35+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setCommentVisible(true));
36+
$this->assertTrue($object->isCommentVisible());
37+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setCommentVisible(false));
38+
$this->assertFalse($object->isCommentVisible());
39+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setCommentVisible());
40+
$this->assertFalse($object->isCommentVisible());
41+
}
42+
2943
public function testLoopUntilEsc()
3044
{
3145
$object = new PresentationProperties();
@@ -40,6 +54,18 @@ public function testLoopUntilEsc()
4054
$this->assertFalse($object->isLoopContinuouslyUntilEsc());
4155
}
4256

57+
public function testLastView()
58+
{
59+
$object = new PresentationProperties();
60+
$this->assertEquals(PresentationProperties::VIEW_SLIDE, $object->getLastView());
61+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setLastView('AAAA'));
62+
$this->assertEquals(PresentationProperties::VIEW_SLIDE, $object->getLastView());
63+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setLastView(PresentationProperties::VIEW_OUTLINE));
64+
$this->assertEquals(PresentationProperties::VIEW_OUTLINE, $object->getLastView());
65+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setLastView());
66+
$this->assertEquals(PresentationProperties::VIEW_SLIDE, $object->getLastView());
67+
}
68+
4369
public function testMarkAsFinal()
4470
{
4571
$object = new PresentationProperties();

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

+33-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace PhpPresentation\Tests\Writer\PowerPoint2007;
1010

1111
use PhpOffice\PhpPresentation\PhpPresentation;
12+
use PhpOffice\PhpPresentation\PresentationProperties;
1213
use PhpOffice\PhpPresentation\Tests\TestHelperDOCX;
1314

1415
class PptViewPropsTest extends \PHPUnit_Framework_TestCase
@@ -23,12 +24,41 @@ public function tearDown()
2324

2425
public function testRender()
2526
{
27+
$expectedElement = '/p:viewPr';
28+
29+
$oPhpPresentation = new PhpPresentation();
30+
31+
$oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
32+
$this->assertTrue($oXMLDoc->fileExists('ppt/viewProps.xml'));
33+
$this->assertTrue($oXMLDoc->elementExists($expectedElement, 'ppt/viewProps.xml'));
34+
$this->assertEquals('0', $oXMLDoc->getElementAttribute($expectedElement, 'showComments', 'ppt/viewProps.xml'));
35+
$this->assertEquals(PresentationProperties::VIEW_SLIDE, $oXMLDoc->getElementAttribute($expectedElement, 'lastView', 'ppt/viewProps.xml'));
36+
}
37+
38+
public function testCommentVisible()
39+
{
40+
$expectedElement ='/p:viewPr';
41+
42+
$oPhpPresentation = new PhpPresentation();
43+
$oPhpPresentation->getPresentationProperties()->setCommentVisible(true);
44+
45+
$oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
46+
$this->assertTrue($oXMLDoc->fileExists('ppt/viewProps.xml'));
47+
$this->assertTrue($oXMLDoc->elementExists($expectedElement, 'ppt/viewProps.xml'));
48+
$this->assertEquals(1, $oXMLDoc->getElementAttribute($expectedElement, 'showComments', 'ppt/viewProps.xml'));
49+
}
50+
51+
public function testLastView()
52+
{
53+
$expectedElement ='/p:viewPr';
54+
$expectedLastView = PresentationProperties::VIEW_OUTLINE;
55+
2656
$oPhpPresentation = new PhpPresentation();
57+
$oPhpPresentation->getPresentationProperties()->setLastView($expectedLastView);
2758

2859
$oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
2960
$this->assertTrue($oXMLDoc->fileExists('ppt/viewProps.xml'));
30-
$element = '/p:viewPr';
31-
$this->assertTrue($oXMLDoc->elementExists($element, 'ppt/viewProps.xml'));
32-
$this->assertEquals('0', $oXMLDoc->getElementAttribute($element, 'showComments', 'ppt/viewProps.xml'));
61+
$this->assertTrue($oXMLDoc->elementExists($expectedElement, 'ppt/viewProps.xml'));
62+
$this->assertEquals($expectedLastView, $oXMLDoc->getElementAttribute($expectedElement, 'lastView', 'ppt/viewProps.xml'));
3363
}
3464
}

0 commit comments

Comments
 (0)