Complex classes like PptSlides often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PptSlides, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class PptSlides extends AbstractSlide |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Add slides (drawings, ...) and slide relationships (drawings, ...) |
||
| 33 | * @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
||
| 34 | */ |
||
| 35 | 52 | public function render() |
|
| 36 | { |
||
| 37 | 52 | foreach ($this->oPresentation->getAllSlides() as $idx => $oSlide) { |
|
| 38 | 52 | $this->oZip->addFromString('ppt/slides/_rels/slide' . ($idx + 1) . '.xml.rels', $this->writeSlideRelationships($oSlide)); |
|
| 39 | 52 | $this->oZip->addFromString('ppt/slides/slide' . ($idx + 1) . '.xml', $this->writeSlide($oSlide)); |
|
| 40 | |||
| 41 | // Add note slide |
||
| 42 | 52 | if ($oSlide->getNote()->getShapeCollection()->count() > 0) { |
|
| 43 | $this->oZip->addFromString('ppt/notesSlides/notesSlide' . ($idx + 1) . '.xml', $this->writeNote($oSlide->getNote())); |
||
|
|
|||
| 44 | } |
||
| 45 | |||
| 46 | // Add background image slide |
||
| 47 | 52 | $oBkgImage = $oSlide->getBackground(); |
|
| 48 | 52 | if ($oBkgImage instanceof Image) { |
|
| 49 | 52 | $this->oZip->addFromString('ppt/media/'.$oBkgImage->getIndexedFilename($idx), file_get_contents($oBkgImage->getPath())); |
|
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | 52 | return $this->oZip; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Write slide relationships to XML format |
||
| 58 | * |
||
| 59 | * @param \PhpOffice\PhpPresentation\Slide $pSlide |
||
| 60 | * @return string XML Output |
||
| 61 | * @throws \Exception |
||
| 62 | */ |
||
| 63 | 52 | protected function writeSlideRelationships(Slide $pSlide) |
|
| 64 | { |
||
| 65 | //@todo Group all getShapeCollection()->getIterator |
||
| 66 | |||
| 67 | // Create XML writer |
||
| 68 | 52 | $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
| 69 | |||
| 70 | // XML header |
||
| 71 | 52 | $objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
| 72 | |||
| 73 | // Relationships |
||
| 74 | 52 | $objWriter->startElement('Relationships'); |
|
| 75 | 52 | $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
| 76 | |||
| 77 | // Starting relation id |
||
| 78 | 52 | $relId = 1; |
|
| 79 | 52 | $idxSlide = $pSlide->getParent()->getIndex($pSlide); |
|
| 80 | |||
| 81 | // Write slideLayout relationship |
||
| 82 | 52 | $layoutId = 1; |
|
| 83 | 52 | if ($pSlide->getSlideLayout()) { |
|
| 84 | 52 | $layoutId = $pSlide->getSlideLayout()->layoutNr; |
|
| 85 | } |
||
| 86 | 52 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml'); |
|
| 87 | 52 | ++$relId; |
|
| 88 | |||
| 89 | // Write drawing relationships? |
||
| 90 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 91 | // Loop trough images and write relationships |
||
| 92 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 93 | 33 | while ($iterator->valid()) { |
|
| 94 | 33 | if ($iterator->current() instanceof Media) { |
|
| 95 | // Write relationship for image drawing |
||
| 96 | $iterator->current()->relationId = 'rId' . $relId; |
||
| 97 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 98 | ++$relId; |
||
| 99 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 100 | ++$relId; |
||
| 101 | 33 | } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
|
| 102 | // Write relationship for image drawing |
||
| 103 | 4 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator->current()->getIndexedFilename()); |
|
| 104 | 4 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 105 | 4 | ++$relId; |
|
| 106 | 29 | } elseif ($iterator->current() instanceof ShapeChart) { |
|
| 107 | // Write relationship for chart drawing |
||
| 108 | 24 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename()); |
|
| 109 | |||
| 110 | 24 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 111 | |||
| 112 | 24 | ++$relId; |
|
| 113 | 5 | } elseif ($iterator->current() instanceof Group) { |
|
| 114 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
||
| 115 | while ($iterator2->valid()) { |
||
| 116 | if ($iterator2->current() instanceof Media) { |
||
| 117 | // Write relationship for image drawing |
||
| 118 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 119 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/video', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 120 | ++$relId; |
||
| 121 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 122 | ++$relId; |
||
| 123 | } elseif ($iterator2->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
||
| 124 | // Write relationship for image drawing |
||
| 125 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename()); |
||
| 126 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 127 | |||
| 128 | ++$relId; |
||
| 129 | } elseif ($iterator2->current() instanceof ShapeChart) { |
||
| 130 | // Write relationship for chart drawing |
||
| 131 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename()); |
||
| 132 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 133 | |||
| 134 | ++$relId; |
||
| 135 | } |
||
| 136 | $iterator2->next(); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | 33 | $iterator->next(); |
|
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | // Write background relationships? |
||
| 145 | 52 | $oBackground = $pSlide->getBackground(); |
|
| 146 | 52 | if ($oBackground instanceof Image) { |
|
| 147 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($idxSlide)); |
||
| 148 | $oBackground->relationId = 'rId' . $relId; |
||
| 149 | ++$relId; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Write hyperlink relationships? |
||
| 153 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 154 | // Loop trough hyperlinks and write relationships |
||
| 155 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 156 | 33 | while ($iterator->valid()) { |
|
| 157 | // Hyperlink on shape |
||
| 158 | 33 | if ($iterator->current()->hasHyperlink()) { |
|
| 159 | // Write relationship for hyperlink |
||
| 160 | $hyperlink = $iterator->current()->getHyperlink(); |
||
| 161 | $hyperlink->relationId = 'rId' . $relId; |
||
| 162 | |||
| 163 | if (!$hyperlink->isInternal()) { |
||
| 164 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 165 | } else { |
||
| 166 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 167 | } |
||
| 168 | |||
| 169 | ++$relId; |
||
| 170 | } |
||
| 171 | |||
| 172 | // Hyperlink on rich text run |
||
| 173 | 33 | if ($iterator->current() instanceof RichText) { |
|
| 174 | foreach ($iterator->current()->getParagraphs() as $paragraph) { |
||
| 175 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 176 | if ($element instanceof Run || $element instanceof RunTextElement) { |
||
| 177 | if ($element->hasHyperlink()) { |
||
| 178 | // Write relationship for hyperlink |
||
| 179 | $hyperlink = $element->getHyperlink(); |
||
| 180 | $hyperlink->relationId = 'rId' . $relId; |
||
| 181 | |||
| 182 | if (!$hyperlink->isInternal()) { |
||
| 183 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 184 | } else { |
||
| 185 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 186 | } |
||
| 187 | |||
| 188 | ++$relId; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | // Hyperlink in table |
||
| 196 | 33 | if ($iterator->current() instanceof ShapeTable) { |
|
| 197 | // Rows |
||
| 198 | $countRows = count($iterator->current()->getRows()); |
||
| 199 | for ($row = 0; $row < $countRows; $row++) { |
||
| 200 | // Cells in rows |
||
| 201 | $countCells = count($iterator->current()->getRow($row)->getCells()); |
||
| 202 | for ($cell = 0; $cell < $countCells; $cell++) { |
||
| 203 | $currentCell = $iterator->current()->getRow($row)->getCell($cell); |
||
| 204 | // Paragraphs in cell |
||
| 205 | foreach ($currentCell->getParagraphs() as $paragraph) { |
||
| 206 | // RichText in paragraph |
||
| 207 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 208 | // Run or Text in RichText |
||
| 209 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 210 | if ($element->hasHyperlink()) { |
||
| 211 | // Write relationship for hyperlink |
||
| 212 | $hyperlink = $element->getHyperlink(); |
||
| 213 | $hyperlink->relationId = 'rId' . $relId; |
||
| 214 | |||
| 215 | if (!$hyperlink->isInternal()) { |
||
| 216 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 217 | } else { |
||
| 218 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 219 | } |
||
| 220 | |||
| 221 | ++$relId; |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | 33 | if ($iterator->current() instanceof Group) { |
|
| 231 | $iterator2 = $pSlide->getShapeCollection()->getIterator(); |
||
| 232 | while ($iterator2->valid()) { |
||
| 233 | // Hyperlink on shape |
||
| 234 | if ($iterator2->current()->hasHyperlink()) { |
||
| 235 | // Write relationship for hyperlink |
||
| 236 | $hyperlink = $iterator2->current()->getHyperlink(); |
||
| 237 | $hyperlink->relationId = 'rId' . $relId; |
||
| 238 | |||
| 239 | if (!$hyperlink->isInternal()) { |
||
| 240 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 241 | } else { |
||
| 242 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 243 | } |
||
| 244 | |||
| 245 | ++$relId; |
||
| 246 | } |
||
| 247 | |||
| 248 | // Hyperlink on rich text run |
||
| 249 | if ($iterator2->current() instanceof RichText) { |
||
| 250 | foreach ($iterator2->current()->getParagraphs() as $paragraph) { |
||
| 251 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 252 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 253 | if ($element->hasHyperlink()) { |
||
| 254 | // Write relationship for hyperlink |
||
| 255 | $hyperlink = $element->getHyperlink(); |
||
| 256 | $hyperlink->relationId = 'rId' . $relId; |
||
| 257 | |||
| 258 | if (!$hyperlink->isInternal()) { |
||
| 259 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 260 | } else { |
||
| 261 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 262 | } |
||
| 263 | |||
| 264 | ++$relId; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | // Hyperlink in table |
||
| 272 | if ($iterator2->current() instanceof ShapeTable) { |
||
| 273 | // Rows |
||
| 274 | $countRows = count($iterator2->current()->getRows()); |
||
| 275 | for ($row = 0; $row < $countRows; $row++) { |
||
| 276 | // Cells in rows |
||
| 277 | $countCells = count($iterator2->current()->getRow($row)->getCells()); |
||
| 278 | for ($cell = 0; $cell < $countCells; $cell++) { |
||
| 279 | $currentCell = $iterator2->current()->getRow($row)->getCell($cell); |
||
| 280 | // Paragraphs in cell |
||
| 281 | foreach ($currentCell->getParagraphs() as $paragraph) { |
||
| 282 | // RichText in paragraph |
||
| 283 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 284 | // Run or Text in RichText |
||
| 285 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 286 | if ($element->hasHyperlink()) { |
||
| 287 | // Write relationship for hyperlink |
||
| 288 | $hyperlink = $element->getHyperlink(); |
||
| 289 | $hyperlink->relationId = 'rId' . $relId; |
||
| 290 | |||
| 291 | if (!$hyperlink->isInternal()) { |
||
| 292 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 293 | } else { |
||
| 294 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 295 | } |
||
| 296 | |||
| 297 | ++$relId; |
||
| 298 | } |
||
| 299 | } |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } |
||
| 303 | } |
||
| 304 | } |
||
| 305 | |||
| 306 | $iterator2->next(); |
||
| 307 | } |
||
| 308 | } |
||
| 309 | |||
| 310 | 33 | $iterator->next(); |
|
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | // Write comment relationships |
||
| 315 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 316 | 33 | $hasSlideComment = false; |
|
| 317 | |||
| 318 | // Loop trough images and write relationships |
||
| 319 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 320 | 33 | while ($iterator->valid()) { |
|
| 321 | 33 | if ($iterator->current() instanceof Comment) { |
|
| 322 | 5 | $hasSlideComment = true; |
|
| 323 | 5 | break; |
|
| 324 | 28 | } elseif ($iterator->current() instanceof Group) { |
|
| 325 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
||
| 326 | while ($iterator2->valid()) { |
||
| 327 | if ($iterator2->current() instanceof Comment) { |
||
| 328 | $hasSlideComment = true; |
||
| 329 | break 2; |
||
| 330 | } |
||
| 331 | $iterator2->next(); |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | 28 | $iterator->next(); |
|
| 336 | } |
||
| 337 | |||
| 338 | 33 | if ($hasSlideComment) { |
|
| 339 | 5 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', '../comments/comment'.($idxSlide + 1).'.xml'); |
|
| 340 | 5 | ++$relId; |
|
| 341 | } |
||
| 342 | } |
||
| 343 | |||
| 344 | 52 | if ($pSlide->getNote()->getShapeCollection()->count() > 0) { |
|
| 345 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide', '../notesSlides/notesSlide'.($idxSlide + 1).'.xml'); |
||
| 346 | } |
||
| 347 | |||
| 348 | 52 | $objWriter->endElement(); |
|
| 349 | |||
| 350 | // Return |
||
| 351 | 52 | return $objWriter->getData(); |
|
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Write slide to XML format |
||
| 356 | * |
||
| 357 | * @param \PhpOffice\PhpPresentation\Slide $pSlide |
||
| 358 | * @return string XML Output |
||
| 359 | * @throws \Exception |
||
| 360 | */ |
||
| 361 | 52 | public function writeSlide(Slide $pSlide) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * @param XMLWriter $objWriter |
||
| 510 | * @param Slide $oSlide |
||
| 511 | */ |
||
| 512 | 52 | protected function writeSlideAnimations(XMLWriter $objWriter, Slide $oSlide) |
|
| 513 | { |
||
| 514 | 52 | $arrayAnimations = $oSlide->getAnimations(); |
|
| 515 | 52 | if (empty($arrayAnimations)) { |
|
| 516 | 52 | return; |
|
| 517 | } |
||
| 518 | |||
| 519 | // Variables |
||
| 520 | $shapeId = 1; |
||
| 521 | $idCount = 1; |
||
| 522 | $hashToIdMap = array(); |
||
| 523 | $arrayAnimationIds = array(); |
||
| 524 | |||
| 525 | foreach ($oSlide->getShapeCollection() as $shape) { |
||
| 526 | $hashToIdMap[$shape->getHashCode()] = ++$shapeId; |
||
| 527 | } |
||
| 528 | foreach ($arrayAnimations as $oAnimation) { |
||
| 529 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
||
| 530 | $arrayAnimationIds[] = $hashToIdMap[$oShape->getHashCode()]; |
||
| 531 | } |
||
| 532 | } |
||
| 533 | |||
| 534 | // p:timing |
||
| 535 | $objWriter->startElement('p:timing'); |
||
| 536 | // p:timing/p:tnLst |
||
| 537 | $objWriter->startElement('p:tnLst'); |
||
| 538 | // p:timing/p:tnLst/p:par |
||
| 539 | $objWriter->startElement('p:par'); |
||
| 540 | // p:timing/p:tnLst/p:par/p:cTn |
||
| 541 | $objWriter->startElement('p:cTn'); |
||
| 542 | $objWriter->writeAttribute('id', $idCount++); |
||
| 543 | $objWriter->writeAttribute('dur', 'indefinite'); |
||
| 544 | $objWriter->writeAttribute('restart', 'never'); |
||
| 545 | $objWriter->writeAttribute('nodeType', 'tmRoot'); |
||
| 546 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst |
||
| 547 | $objWriter->startElement('p:childTnLst'); |
||
| 548 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq |
||
| 549 | $objWriter->startElement('p:seq'); |
||
| 550 | $objWriter->writeAttribute('concurrent', '1'); |
||
| 551 | $objWriter->writeAttribute('nextAc', 'seek'); |
||
| 552 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn |
||
| 553 | $objWriter->startElement('p:cTn'); |
||
| 554 | $objWriter->writeAttribute('id', $idCount++); |
||
| 555 | $objWriter->writeAttribute('dur', 'indefinite'); |
||
| 556 | $objWriter->writeAttribute('nodeType', 'mainSeq'); |
||
| 557 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst |
||
| 558 | $objWriter->startElement('p:childTnLst'); |
||
| 559 | |||
| 560 | // Each animation has multiple shapes |
||
| 561 | foreach ($arrayAnimations as $oAnimation) { |
||
| 562 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par |
||
| 563 | $objWriter->startElement('p:par'); |
||
| 564 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn |
||
| 565 | $objWriter->startElement('p:cTn'); |
||
| 566 | $objWriter->writeAttribute('id', $idCount++); |
||
| 567 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 568 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst |
||
| 569 | $objWriter->startElement('p:stCondLst'); |
||
| 570 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst/p:cond |
||
| 571 | $objWriter->startElement('p:cond'); |
||
| 572 | $objWriter->writeAttribute('delay', 'indefinite'); |
||
| 573 | $objWriter->endElement(); |
||
| 574 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:stCondLst |
||
| 575 | $objWriter->endElement(); |
||
| 576 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst |
||
| 577 | $objWriter->startElement('p:childTnLst'); |
||
| 578 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par |
||
| 579 | $objWriter->startElement('p:par'); |
||
| 580 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn |
||
| 581 | $objWriter->startElement('p:cTn'); |
||
| 582 | $objWriter->writeAttribute('id', $idCount++); |
||
| 583 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 584 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst |
||
| 585 | $objWriter->startElement('p:stCondLst'); |
||
| 586 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst/p:cond |
||
| 587 | $objWriter->startElement('p:cond'); |
||
| 588 | $objWriter->writeAttribute('delay', '0'); |
||
| 589 | $objWriter->endElement(); |
||
| 590 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn\##p:stCondLst |
||
| 591 | $objWriter->endElement(); |
||
| 592 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst |
||
| 593 | $objWriter->startElement('p:childTnLst'); |
||
| 594 | |||
| 595 | $firstAnimation = true; |
||
| 596 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
||
| 597 | $nodeType = $firstAnimation ? 'clickEffect' : 'withEffect'; |
||
| 598 | $shapeId = $hashToIdMap[$oShape->getHashCode()]; |
||
| 599 | |||
| 600 | // p:par |
||
| 601 | $objWriter->startElement('p:par'); |
||
| 602 | // p:par/p:cTn |
||
| 603 | $objWriter->startElement('p:cTn'); |
||
| 604 | $objWriter->writeAttribute('id', $idCount++); |
||
| 605 | $objWriter->writeAttribute('presetID', '1'); |
||
| 606 | $objWriter->writeAttribute('presetClass', 'entr'); |
||
| 607 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 608 | $objWriter->writeAttribute('presetSubtype', '0'); |
||
| 609 | $objWriter->writeAttribute('grpId', '0'); |
||
| 610 | $objWriter->writeAttribute('nodeType', $nodeType); |
||
| 611 | // p:par/p:cTn/p:stCondLst |
||
| 612 | $objWriter->startElement('p:stCondLst'); |
||
| 613 | // p:par/p:cTn/p:stCondLst/p:cond |
||
| 614 | $objWriter->startElement('p:cond'); |
||
| 615 | $objWriter->writeAttribute('delay', '0'); |
||
| 616 | $objWriter->endElement(); |
||
| 617 | // p:par/p:cTn\##p:stCondLst |
||
| 618 | $objWriter->endElement(); |
||
| 619 | // p:par/p:cTn/p:childTnLst |
||
| 620 | $objWriter->startElement('p:childTnLst'); |
||
| 621 | // p:par/p:cTn/p:childTnLst/p:set |
||
| 622 | $objWriter->startElement('p:set'); |
||
| 623 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr |
||
| 624 | $objWriter->startElement('p:cBhvr'); |
||
| 625 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn |
||
| 626 | $objWriter->startElement('p:cTn'); |
||
| 627 | $objWriter->writeAttribute('id', $idCount++); |
||
| 628 | $objWriter->writeAttribute('dur', '1'); |
||
| 629 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 630 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst |
||
| 631 | $objWriter->startElement('p:stCondLst'); |
||
| 632 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst/p:cond |
||
| 633 | $objWriter->startElement('p:cond'); |
||
| 634 | $objWriter->writeAttribute('delay', '0'); |
||
| 635 | $objWriter->endElement(); |
||
| 636 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn\##p:stCondLst |
||
| 637 | $objWriter->endElement(); |
||
| 638 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:cTn |
||
| 639 | $objWriter->endElement(); |
||
| 640 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl |
||
| 641 | $objWriter->startElement('p:tgtEl'); |
||
| 642 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl/p:spTgt |
||
| 643 | $objWriter->startElement('p:spTgt'); |
||
| 644 | $objWriter->writeAttribute('spid', $shapeId); |
||
| 645 | $objWriter->endElement(); |
||
| 646 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:tgtEl |
||
| 647 | $objWriter->endElement(); |
||
| 648 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst |
||
| 649 | $objWriter->startElement('p:attrNameLst'); |
||
| 650 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst/p:attrName |
||
| 651 | $objWriter->writeElement('p:attrName', 'style.visibility'); |
||
| 652 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:attrNameLst |
||
| 653 | $objWriter->endElement(); |
||
| 654 | // p:par/p:cTn/p:childTnLst/p:set\##p:cBhvr |
||
| 655 | $objWriter->endElement(); |
||
| 656 | // p:par/p:cTn/p:childTnLst/p:set/p:to |
||
| 657 | $objWriter->startElement('p:to'); |
||
| 658 | // p:par/p:cTn/p:childTnLst/p:set/p:to/p:strVal |
||
| 659 | $objWriter->startElement('p:strVal'); |
||
| 660 | $objWriter->writeAttribute('val', 'visible'); |
||
| 661 | $objWriter->endElement(); |
||
| 662 | // p:par/p:cTn/p:childTnLst/p:set\##p:to |
||
| 663 | $objWriter->endElement(); |
||
| 664 | // p:par/p:cTn/p:childTnLst\##p:set |
||
| 665 | $objWriter->endElement(); |
||
| 666 | // p:par/p:cTn\##p:childTnLst |
||
| 667 | $objWriter->endElement(); |
||
| 668 | // p:par\##p:cTn |
||
| 669 | $objWriter->endElement(); |
||
| 670 | // ##p:par |
||
| 671 | $objWriter->endElement(); |
||
| 672 | |||
| 673 | $firstAnimation = false; |
||
| 674 | } |
||
| 675 | |||
| 676 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn\##p:childTnLst |
||
| 677 | $objWriter->endElement(); |
||
| 678 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par\##p:cTn |
||
| 679 | $objWriter->endElement(); |
||
| 680 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst\##p:par |
||
| 681 | $objWriter->endElement(); |
||
| 682 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:childTnLst |
||
| 683 | $objWriter->endElement(); |
||
| 684 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par\##p:cTn |
||
| 685 | $objWriter->endElement(); |
||
| 686 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst\##p:par |
||
| 687 | $objWriter->endElement(); |
||
| 688 | } |
||
| 689 | |||
| 690 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn\##p:childTnLst |
||
| 691 | $objWriter->endElement(); |
||
| 692 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:cTn |
||
| 693 | $objWriter->endElement(); |
||
| 694 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst |
||
| 695 | $objWriter->startElement('p:prevCondLst'); |
||
| 696 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond |
||
| 697 | $objWriter->startElement('p:cond'); |
||
| 698 | $objWriter->writeAttribute('evt', 'onPrev'); |
||
| 699 | $objWriter->writeAttribute('delay', '0'); |
||
| 700 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl |
||
| 701 | $objWriter->startElement('p:tgtEl'); |
||
| 702 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 703 | $objWriter->writeElement('p:sldTgt', null); |
||
| 704 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond\##p:tgtEl |
||
| 705 | $objWriter->endElement(); |
||
| 706 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst\##p:cond |
||
| 707 | $objWriter->endElement(); |
||
| 708 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:prevCondLst |
||
| 709 | $objWriter->endElement(); |
||
| 710 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst |
||
| 711 | $objWriter->startElement('p:nextCondLst'); |
||
| 712 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond |
||
| 713 | $objWriter->startElement('p:cond'); |
||
| 714 | $objWriter->writeAttribute('evt', 'onNext'); |
||
| 715 | $objWriter->writeAttribute('delay', '0'); |
||
| 716 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl |
||
| 717 | $objWriter->startElement('p:tgtEl'); |
||
| 718 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 719 | $objWriter->writeElement('p:sldTgt', null); |
||
| 720 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond\##p:tgtEl |
||
| 721 | $objWriter->endElement(); |
||
| 722 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst\##p:cond |
||
| 723 | $objWriter->endElement(); |
||
| 724 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:nextCondLst |
||
| 725 | $objWriter->endElement(); |
||
| 726 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst\##p:seq |
||
| 727 | $objWriter->endElement(); |
||
| 728 | // p:timing/p:tnLst/p:par/p:cTn\##p:childTnLst |
||
| 729 | $objWriter->endElement(); |
||
| 730 | // p:timing/p:tnLst/p:par\##p:cTn |
||
| 731 | $objWriter->endElement(); |
||
| 732 | // p:timing/p:tnLst\##p:par |
||
| 733 | $objWriter->endElement(); |
||
| 734 | // p:timing\##p:tnLst |
||
| 735 | $objWriter->endElement(); |
||
| 736 | |||
| 737 | // p:timing/p:bldLst |
||
| 738 | $objWriter->startElement('p:bldLst'); |
||
| 739 | |||
| 740 | // Add in ids of all shapes in this slides animations |
||
| 741 | foreach ($arrayAnimationIds as $id) { |
||
| 742 | // p:timing/p:bldLst/p:bldP |
||
| 743 | $objWriter->startElement('p:bldP'); |
||
| 744 | $objWriter->writeAttribute('spid', $id); |
||
| 745 | $objWriter->writeAttribute('grpId', 0); |
||
| 746 | $objWriter->endELement(); |
||
| 747 | } |
||
| 748 | |||
| 749 | // p:timing\##p:bldLst |
||
| 750 | $objWriter->endElement(); |
||
| 751 | |||
| 752 | // ##p:timing |
||
| 753 | $objWriter->endElement(); |
||
| 754 | } |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Write group |
||
| 758 | * |
||
| 759 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 760 | * @param \PhpOffice\PhpPresentation\Shape\Group $group |
||
| 761 | * @param int $shapeId |
||
| 762 | */ |
||
| 763 | protected function writeShapeGroup(XMLWriter $objWriter, Group $group, &$shapeId) |
||
| 764 | { |
||
| 765 | // p:grpSp |
||
| 766 | $objWriter->startElement('p:grpSp'); |
||
| 767 | |||
| 768 | // p:nvGrpSpPr |
||
| 769 | $objWriter->startElement('p:nvGrpSpPr'); |
||
| 770 | |||
| 771 | // p:cNvPr |
||
| 772 | $objWriter->startElement('p:cNvPr'); |
||
| 773 | $objWriter->writeAttribute('name', 'Group '.$shapeId++); |
||
| 774 | $objWriter->writeAttribute('id', $shapeId); |
||
| 775 | $objWriter->endElement(); // p:cNvPr |
||
| 776 | // NOTE: Re: $shapeId This seems to be how PowerPoint 2010 does business. |
||
| 777 | |||
| 778 | // p:cNvGrpSpPr |
||
| 779 | $objWriter->writeElement('p:cNvGrpSpPr', null); |
||
| 780 | |||
| 781 | // p:nvPr |
||
| 782 | $objWriter->writeElement('p:nvPr', null); |
||
| 783 | |||
| 784 | $objWriter->endElement(); // p:nvGrpSpPr |
||
| 785 | |||
| 786 | // p:grpSpPr |
||
| 787 | $objWriter->startElement('p:grpSpPr'); |
||
| 788 | |||
| 789 | // a:xfrm |
||
| 790 | $objWriter->startElement('a:xfrm'); |
||
| 791 | |||
| 792 | // a:off |
||
| 793 | $objWriter->startElement('a:off'); |
||
| 794 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); |
||
| 795 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); |
||
| 796 | $objWriter->endElement(); // a:off |
||
| 797 | |||
| 798 | // a:ext |
||
| 799 | $objWriter->startElement('a:ext'); |
||
| 800 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); |
||
| 801 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); |
||
| 802 | $objWriter->endElement(); // a:ext |
||
| 803 | |||
| 804 | // a:chOff |
||
| 805 | $objWriter->startElement('a:chOff'); |
||
| 806 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); |
||
| 807 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); |
||
| 808 | $objWriter->endElement(); // a:chOff |
||
| 809 | |||
| 810 | // a:chExt |
||
| 811 | $objWriter->startElement('a:chExt'); |
||
| 812 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); |
||
| 813 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); |
||
| 814 | $objWriter->endElement(); // a:chExt |
||
| 815 | |||
| 816 | $objWriter->endElement(); // a:xfrm |
||
| 817 | |||
| 818 | $objWriter->endElement(); // p:grpSpPr |
||
| 819 | |||
| 820 | $this->writeShapeCollection($objWriter, $group->getShapeCollection(), $shapeId); |
||
| 821 | $objWriter->endElement(); // p:grpSp |
||
| 822 | } |
||
| 823 | |||
| 824 | /** |
||
| 825 | * Write chart |
||
| 826 | * |
||
| 827 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 828 | * @param \PhpOffice\PhpPresentation\Shape\Chart $shape |
||
| 829 | * @param int $shapeId |
||
| 830 | */ |
||
| 831 | 24 | protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $shapeId) |
|
| 898 | |||
| 899 | /** |
||
| 900 | * Write pic |
||
| 901 | * |
||
| 902 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 903 | * @param \PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter $shape |
||
| 904 | * @param int $shapeId |
||
| 905 | * @throws \Exception |
||
| 906 | */ |
||
| 907 | protected function writeShapeDrawing(XMLWriter $objWriter, ShapeDrawing\AbstractDrawingAdapter $shape, $shapeId) |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Write txt |
||
| 1029 | * |
||
| 1030 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1031 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
| 1032 | * @param int $shapeId |
||
| 1033 | * @throws \Exception |
||
| 1034 | */ |
||
| 1035 | protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId) |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Write table |
||
| 1175 | * |
||
| 1176 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1177 | * @param \PhpOffice\PhpPresentation\Shape\Table $shape |
||
| 1178 | * @param int $shapeId |
||
| 1179 | * @throws \Exception |
||
| 1180 | */ |
||
| 1181 | protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, $shapeId) |
||
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Write paragraphs |
||
| 1408 | * |
||
| 1409 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1410 | * @param \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs |
||
| 1411 | * @param bool $bIsPlaceholder |
||
| 1412 | * @throws \Exception |
||
| 1413 | */ |
||
| 1414 | protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceholder = false) |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * Write Line Shape |
||
| 1537 | * |
||
| 1538 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1539 | * @param \PhpOffice\PhpPresentation\Shape\Line $shape |
||
| 1540 | * @param int $shapeId |
||
| 1541 | */ |
||
| 1542 | protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId) |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Write hyperlink |
||
| 1649 | * |
||
| 1650 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1651 | * @param \PhpOffice\PhpPresentation\AbstractShape|\PhpOffice\PhpPresentation\Shape\RichText\TextElement $shape |
||
| 1652 | */ |
||
| 1653 | protected function writeHyperlink(XMLWriter $objWriter, $shape) |
||
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Write Note Slide |
||
| 1670 | * @param Note $pNote |
||
| 1671 | * @throws \Exception |
||
| 1672 | * @return string |
||
| 1673 | */ |
||
| 1674 | protected function writeNote(Note $pNote) |
||
| 1954 | |||
| 1955 | /** |
||
| 1956 | * Write Transition Slide |
||
| 1957 | * @link http://officeopenxml.com/prSlide-transitions.php |
||
| 1958 | * @param XMLWriter $objWriter |
||
| 1959 | * @param Transition $transition |
||
| 1960 | */ |
||
| 1961 | 52 | protected function writeSlideTransition(XMLWriter $objWriter, $transition) |
|
| 2208 | } |
||
| 2209 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: