setActiveSlideIndex() public method

Set active slide index
public setActiveSlideIndex ( integer $index ) : Slide
$index integer Active slide index
return Slide
 /**
  * Read Slide
  *
  * @param \DOMElement $nodeSlide
  */
 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'));
     }
     if ($nodeSlide->hasAttribute('draw:style-name')) {
         $keyStyle = $nodeSlide->getAttribute('draw:style-name');
         if (isset($this->arrayStyles[$keyStyle])) {
             $this->oPhpPresentation->getActiveSlide()->setBackground($this->arrayStyles[$keyStyle]['background']);
         }
     }
     foreach ($this->oXMLReader->getElements('draw:frame', $nodeSlide) as $oNodeFrame) {
         if ($this->oXMLReader->getElement('draw:image', $oNodeFrame)) {
             $this->loadShapeDrawing($oNodeFrame);
             continue;
         }
         if ($this->oXMLReader->getElement('draw:text-box', $oNodeFrame)) {
             $this->loadShapeRichText($oNodeFrame);
             continue;
         }
     }
     return true;
 }
Example #2
0
 /**
  * Extract data from slide
  * @param \DOMElement $nodeSlide
  */
 protected function loadSlide(\DOMElement $nodeSlide)
 {
     // Core
     $this->oPhpPresentation->createSlide();
     $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
     foreach ($this->oXMLReader->getElements('draw:frame', $nodeSlide) as $oNodeFrame) {
         if ($this->oXMLReader->getElement('draw:image', $oNodeFrame)) {
             $this->loadShapeDrawing($oNodeFrame);
             continue;
         }
         if ($this->oXMLReader->getElement('draw:text-box', $oNodeFrame)) {
             $this->loadShapeRichText($oNodeFrame);
             continue;
         }
     }
     return true;
 }
Example #3
0
 /**
  * Extract data from slide
  * @param string $sPart
  * @param string $baseFile
  */
 protected function loadSlide($sPart, $baseFile)
 {
     $xmlReader = new XMLReader();
     if ($xmlReader->getDomFromString($sPart)) {
         // Core
         $this->oPhpPresentation->createSlide();
         $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
         foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
             switch ($oNode->tagName) {
                 case 'p:pic':
                     $this->loadShapeDrawing($xmlReader, $oNode, $baseFile);
                     break;
                 case 'p:sp':
                     $this->loadShapeRichText($xmlReader, $oNode, $baseFile);
                     break;
                 default:
                     //var_export($oNode->tagName);
             }
         }
     }
 }
Example #4
0
 /**
  * A container record that specifies a presentation slide or title master slide.
  * @param string $stream
  * @param int $pos
  * @link http://msdn.microsoft.com/en-us/library/dd946323(v=office.12).aspx
  */
 private function readRecordSlideContainer($stream, $pos)
 {
     // Core
     $this->oPhpPresentation->createSlide();
     $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
     // *** slideAtom (32 bytes)
     $slideAtom = $this->readRecordSlideAtom($stream, $pos);
     if ($slideAtom['length'] == 0) {
         throw new \Exception('PowerPoint97 Reader : record SlideAtom');
     }
     $pos += $slideAtom['length'];
     // *** slideShowSlideInfoAtom (24 bytes)
     $slideShowInfoAtom = $this->readRecordSlideShowSlideInfoAtom($stream, $pos);
     $pos += $slideShowInfoAtom['length'];
     // *** perSlideHFContainer (variable) : optional
     $perSlideHFContainer = $this->readRecordPerSlideHeadersFootersContainer($stream, $pos);
     $pos += $perSlideHFContainer['length'];
     // *** rtSlideSyncInfo12 (variable) : optional
     $rtSlideSyncInfo12 = $this->readRecordRoundTripSlideSyncInfo12Container($stream, $pos);
     $pos += $rtSlideSyncInfo12['length'];
     // *** drawing (variable)
     $drawing = $this->readRecordDrawingContainer($stream, $pos);
     $pos += $drawing['length'];
     // *** slideSchemeColorSchemeAtom (40 bytes)
     $slideSchemeColorAtom = $this->readRecordSlideSchemeColorSchemeAtom($stream, $pos);
     if ($slideSchemeColorAtom['length'] == 0) {
         throw new \Exception('PowerPoint97 Reader : record SlideSchemeColorSchemeAtom');
     }
     $pos += $slideSchemeColorAtom['length'];
     // *** slideNameAtom (variable)
     $slideNameAtom = $this->readRecordSlideNameAtom($stream, $pos);
     $pos += $slideNameAtom['length'];
     // *** slideProgTagsContainer (variable).
     $slideProgTags = $this->readRecordSlideProgTagsContainer($stream, $pos);
     $pos += $slideProgTags['length'];
     // *** rgRoundTripSlide (variable)
 }
 /**
  * Test set active slide index exception
  *
  * @expectedException Exception
  * @expectedExceptionMessage Active slide index is out of bounds.
  */
 public function testSetActiveSlideIndexException()
 {
     $object = new PhpPresentation();
     $object->setActiveSlideIndex(1);
 }
 /**
  * Extract data from slide
  * @param string $sPart
  * @param string $baseFile
  */
 protected function loadSlide($sPart, $baseFile)
 {
     $xmlReader = new XMLReader();
     if ($xmlReader->getDomFromString($sPart)) {
         // Core
         $oSlide = $this->oPhpPresentation->createSlide();
         $this->oPhpPresentation->setActiveSlideIndex($this->oPhpPresentation->getSlideCount() - 1);
         $oSlide->setRelsIndex('ppt/slides/_rels/' . $baseFile . '.rels');
         // Background
         $oElement = $xmlReader->getElement('/p:sld/p:cSld/p:bg/p:bgPr');
         if ($oElement) {
             $oElementColor = $xmlReader->getElement('a:solidFill/a:srgbClr', $oElement);
             if ($oElementColor) {
                 // Color
                 $oColor = new Color();
                 $oColor->setRGB($oElementColor->hasAttribute('val') ? $oElementColor->getAttribute('val') : null);
                 // Background
                 $oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Color();
                 $oBackground->setColor($oColor);
                 // Slide Background
                 $oSlide = $this->oPhpPresentation->getActiveSlide();
                 $oSlide->setBackground($oBackground);
             }
             $oElementImage = $xmlReader->getElement('a:blipFill/a:blip', $oElement);
             if ($oElementImage) {
                 $relImg = $this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'][$oElementImage->getAttribute('r:embed')];
                 if (is_array($relImg)) {
                     // File
                     $pathImage = 'ppt/slides/' . $relImg['Target'];
                     $pathImage = explode('/', $pathImage);
                     foreach ($pathImage as $key => $partPath) {
                         if ($partPath == '..') {
                             unset($pathImage[$key - 1]);
                             unset($pathImage[$key]);
                         }
                     }
                     $pathImage = implode('/', $pathImage);
                     $contentImg = $this->oZip->getFromName($pathImage);
                     $tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderPpt2007Bkg');
                     file_put_contents($tmpBkgImg, $contentImg);
                     // Background
                     $oBackground = new Image();
                     $oBackground->setPath($tmpBkgImg);
                     // Slide Background
                     $oSlide = $this->oPhpPresentation->getActiveSlide();
                     $oSlide->setBackground($oBackground);
                 }
             }
         }
         // Shapes
         foreach ($xmlReader->getElements('/p:sld/p:cSld/p:spTree/*') as $oNode) {
             switch ($oNode->tagName) {
                 case 'p:pic':
                     $this->loadShapeDrawing($xmlReader, $oNode, $oSlide);
                     break;
                 case 'p:sp':
                     $this->loadShapeRichText($xmlReader, $oNode, $oSlide);
                     break;
                 default:
                     //var_export($oNode->tagName);
             }
         }
         // Layout
         $oSlide = $this->oPhpPresentation->getActiveSlide();
         foreach ($this->arrayRels['ppt/slides/_rels/' . $baseFile . '.rels'] as $valueRel) {
             if ($valueRel['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout') {
                 $layoutBasename = basename($valueRel['Target']);
                 if (array_key_exists($layoutBasename, $this->arraySlideLayouts)) {
                     $oSlide->setSlideLayout($this->arraySlideLayouts[$layoutBasename]);
                 }
                 break;
             }
         }
     }
 }