diff --git a/.travis_shell_after_success.sh b/.travis_shell_after_success.sh index a88b576e7..d3138a248 100644 --- a/.travis_shell_after_success.sh +++ b/.travis_shell_after_success.sh @@ -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" @@ -16,8 +15,7 @@ if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPPowerPoint" ] && [ "$TRAVIS_PULL_REQUE cd $HOME git config --global user.email "travis@travis-ci.org" 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" diff --git a/CHANGELOG.md b/CHANGELOG.md index 91743ab13..db9b76bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/intro.rst b/docs/intro.rst index 1d01c9761..76abf3c95 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -46,6 +46,10 @@ Writers +---------------------------+----------------------+--------+-------+-------+-------+ | | Custom | | | | | +---------------------------+----------------------+--------+-------+-------+-------+ +| **Slides** | | ✓ | ✓ | | | ++---------------------------+----------------------+--------+-------+-------+-------+ +| | Name | | ✓ | | | ++---------------------------+----------------------+--------+-------+-------+-------+ | **Element Shape** | Image | ✓ | ✓ | | | +---------------------------+----------------------+--------+-------+-------+-------+ | | Hyperlink | ✓ | ✓ | | | diff --git a/docs/slides.rst b/docs/slides.rst index 9d7858730..79a9bf4e3 100644 --- a/docs/slides.rst +++ b/docs/slides.rst @@ -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'); \ No newline at end of file diff --git a/src/PhpPresentation/Reader/ODPresentation.php b/src/PhpPresentation/Reader/ODPresentation.php index 996c6258d..af5ecc5a0 100644 --- a/src/PhpPresentation/Reader/ODPresentation.php +++ b/src/PhpPresentation/Reader/ODPresentation.php @@ -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); diff --git a/src/PhpPresentation/Slide.php b/src/PhpPresentation/Slide.php index ca4b09e69..b37871e9a 100644 --- a/src/PhpPresentation/Slide.php +++ b/src/PhpPresentation/Slide.php @@ -114,6 +114,13 @@ class Slide implements ComparableInterface, ShapeContainerInterface */ protected $extentY; + /** + * Name of the title + * + * @var string + */ + protected $name; + /** * Create a new slide * @@ -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; + } } diff --git a/src/PhpPresentation/Writer/ODPresentation/Content.php b/src/PhpPresentation/Writer/ODPresentation/Content.php index 9f4214c3c..d07b9ec41 100644 --- a/src/PhpPresentation/Writer/ODPresentation/Content.php +++ b/src/PhpPresentation/Writer/ODPresentation/Content.php @@ -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 diff --git a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php index 9b866fd4b..56781f62b 100644 --- a/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php +++ b/tests/PhpPresentation/Tests/Reader/ODPresentationTest.php @@ -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()); + } } diff --git a/tests/PhpPresentation/Tests/SlideTest.php b/tests/PhpPresentation/Tests/SlideTest.php index 6b161ed25..519b8dca8 100644 --- a/tests/PhpPresentation/Tests/SlideTest.php +++ b/tests/PhpPresentation/Tests/SlideTest.php @@ -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(); diff --git a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php index 0fb9ffab5..ffd9d725e 100644 --- a/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php +++ b/tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php @@ -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(); diff --git a/tests/resources/files/ODP_Slide_Name.odp b/tests/resources/files/ODP_Slide_Name.odp new file mode 100644 index 000000000..4a8b2fdc1 Binary files /dev/null and b/tests/resources/files/ODP_Slide_Name.odp differ