Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#121 : Set name of a slide #137

Merged
merged 2 commits into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis_shell_after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ echo "TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG"
echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"

##if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPPresentation" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPPowerPoint" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPPresentation" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then

echo -e "Publishing PHPDoc...\n"

Expand All @@ -16,8 +15,7 @@ if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPPowerPoint" ] && [ "$TRAVIS_PULL_REQUE
cd $HOME
git config --global user.email "[email protected]"
git config --global user.name "travis-ci"
## git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/PHPPresentation gh-pages > /dev/null
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/PHPPowerPoint gh-pages > /dev/null
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/PHPPresentation gh-pages > /dev/null

cd gh-pages
echo "--DEBUG : Suppression"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 0.6.0 - WIP
### Features
- ODPresentation Writer : Name of the slide - @Progi1984 GH-121

## 0.5.0 - 2015-10-08

### Features
Expand Down
4 changes: 4 additions & 0 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Writers
+---------------------------+----------------------+--------+-------+-------+-------+
| | Custom | | | | |
+---------------------------+----------------------+--------+-------+-------+-------+
| **Slides** | | ✓ | ✓ | | |
+---------------------------+----------------------+--------+-------+-------+-------+
| | Name | | ✓ | | |
+---------------------------+----------------------+--------+-------+-------+-------+
| **Element Shape** | Image | ✓ | ✓ | | |
+---------------------------+----------------------+--------+-------+-------+-------+
| | Hyperlink | ✓ | ✓ | | |
Expand Down
11 changes: 11 additions & 0 deletions docs/slides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ 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');
3 changes: 3 additions & 0 deletions src/PhpPresentation/Reader/ODPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ protected function loadSlide(\DOMElement $nodeSlide)
// Core
$this->oPhpPresentation->createSlide();
$this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
if ($nodeSlide->hasAttribute('draw:name')) {
$this->oPhpPresentation->getActiveSlide()->setName($nodeSlide->getAttribute('draw:name'));
}
foreach ($this->oXMLReader->getElements('draw:frame', $nodeSlide) as $oNodeFrame) {
if ($this->oXMLReader->getElement('draw:image', $oNodeFrame)) {
$this->loadShapeDrawing($oNodeFrame);
Expand Down
27 changes: 27 additions & 0 deletions src/PhpPresentation/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ class Slide implements ComparableInterface, ShapeContainerInterface
*/
protected $extentY;

/**
* Name of the title
*
* @var string
*/
protected $name;

/**
* Create a new slide
*
Expand Down Expand Up @@ -462,4 +469,24 @@ public function setTransition(Transition $transition = null)

return $this;
}

/**
* Get the name of the slide
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Set the name of the slide
* @param string $name
* @return $this
*/
public function setName($name = null)
{
$this->name = $name;
return $this;
}
}
5 changes: 4 additions & 1 deletion src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ public function writePart(PhpPresentation $pPhpPresentation)
for ($i = 0; $i < $slideCount; ++$i) {
$pSlide = $pPhpPresentation->getSlide($i);
$objWriter->startElement('draw:page');
$objWriter->writeAttribute('draw:name', 'page' . $i);
$name = $pSlide->getName();
if (!is_null($name)) {
$objWriter->writeAttribute('draw:name', $name);
}
$objWriter->writeAttribute('draw:master-page-name', 'Standard');
$objWriter->writeAttribute('draw:style-name', 'stylePage' . $i);
// Images
Expand Down
10 changes: 10 additions & 0 deletions tests/PhpPresentation/Tests/Reader/ODPresentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,14 @@ public function testLoadFile01()
$this->assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getHyperlink()->getUrl());
//$this->assertEquals('PHPPresentation', $oRichText->getHyperlink()->getTooltip());
}

public function testSlideName()
{
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/ODP_Slide_Name.odp';
$object = new ODPresentation();
$oPhpPresentation = $object->load($file);
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);

$this->assertEquals('MaDiapo', $oPhpPresentation->getSlide(0)->getName());
}
}
10 changes: 10 additions & 0 deletions tests/PhpPresentation/Tests/SlideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public function testGroup()
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Group', $object->createGroup());
}

public function testName()
{
$object = new Slide();
$this->assertNull($object->getName());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setName('AAAA'));
$this->assertEquals('AAAA', $object->getName());
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->setName());
$this->assertNull($object->getName());
}

public function testTransition()
{
$object = new Slide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,32 @@ public function testRichTextShadow()
}
}
}


public function testSlideName()
{
$phpPresentation = new PhpPresentation();
$oSlide = $phpPresentation->getActiveSlide();

$element = '/office:document-content/office:body/office:presentation/draw:page';

$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($element, 'content.xml'));
$this->assertFalse($pres->attributeElementExists($element, 'draw:name', 'content.xml'));

$oSlide->setName('AAAA');

$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($element, 'content.xml'));
$this->assertTrue($pres->attributeElementExists($element, 'draw:name', 'content.xml'));
$this->assertEquals('AAAA', $pres->getElementAttribute($element, 'draw:name', 'content.xml'));

$oSlide->setName();

$pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation');
$this->assertTrue($pres->elementExists($element, 'content.xml'));
$this->assertFalse($pres->attributeElementExists($element, 'draw:name', 'content.xml'));
}

public function testStyleAlignment()
{
$phpPresentation = new PhpPresentation();
Expand Down
Binary file added tests/resources/files/ODP_Slide_Name.odp
Binary file not shown.