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 | $layoutId = $pSlide->getSlideLayout()->layoutNr; |
||
| 85 | } |
||
| 86 | 52 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml'); |
|
| 87 | |||
| 88 | // Write drawing relationships? |
||
| 89 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 90 | // Loop trough images and write relationships |
||
| 91 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 92 | 33 | while ($iterator->valid()) { |
|
| 93 | 33 | if ($iterator->current() instanceof Media) { |
|
| 94 | // Write relationship for image drawing |
||
| 95 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 96 | $iterator->current()->relationId = 'rId' . $relId; |
||
| 97 | ++$relId; |
||
| 98 | 33 | } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
|
| 99 | // Write relationship for image drawing |
||
| 100 | 4 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator->current()->getIndexedFilename()); |
|
| 101 | 4 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 102 | 4 | ++$relId; |
|
| 103 | 29 | } elseif ($iterator->current() instanceof ShapeChart) { |
|
| 104 | // Write relationship for chart drawing |
||
| 105 | 24 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename()); |
|
| 106 | |||
| 107 | 24 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 108 | |||
| 109 | 24 | ++$relId; |
|
| 110 | 5 | } elseif ($iterator->current() instanceof Group) { |
|
| 111 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
||
| 112 | while ($iterator2->valid()) { |
||
| 113 | if ($iterator->current() instanceof Media) { |
||
| 114 | // Write relationship for image drawing |
||
| 115 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 116 | $iterator->current()->relationId = 'rId' . $relId; |
||
| 117 | ++$relId; |
||
| 118 | } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
||
| 119 | // Write relationship for image drawing |
||
| 120 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename()); |
||
| 121 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 122 | |||
| 123 | ++$relId; |
||
| 124 | } elseif ($iterator2->current() instanceof ShapeChart) { |
||
| 125 | // Write relationship for chart drawing |
||
| 126 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename()); |
||
| 127 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 128 | |||
| 129 | ++$relId; |
||
| 130 | } |
||
| 131 | $iterator2->next(); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | 33 | $iterator->next(); |
|
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | // Write background relationships? |
||
| 140 | 52 | $oBackground = $pSlide->getBackground(); |
|
| 141 | 52 | if ($oBackground instanceof Image) { |
|
| 142 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($idxSlide)); |
||
| 143 | $oBackground->relationId = 'rId' . $relId; |
||
| 144 | ++$relId; |
||
| 145 | } |
||
| 146 | |||
| 147 | // Write hyperlink relationships? |
||
| 148 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 149 | // Loop trough hyperlinks and write relationships |
||
| 150 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 151 | 33 | while ($iterator->valid()) { |
|
| 152 | // Hyperlink on shape |
||
| 153 | 33 | if ($iterator->current()->hasHyperlink()) { |
|
| 154 | // Write relationship for hyperlink |
||
| 155 | $hyperlink = $iterator->current()->getHyperlink(); |
||
| 156 | $hyperlink->relationId = 'rId' . $relId; |
||
| 157 | |||
| 158 | if (!$hyperlink->isInternal()) { |
||
| 159 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 160 | } else { |
||
| 161 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 162 | } |
||
| 163 | |||
| 164 | ++$relId; |
||
| 165 | } |
||
| 166 | |||
| 167 | // Hyperlink on rich text run |
||
| 168 | 33 | if ($iterator->current() instanceof RichText) { |
|
| 169 | foreach ($iterator->current()->getParagraphs() as $paragraph) { |
||
| 170 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 171 | if ($element instanceof Run || $element instanceof RunTextElement) { |
||
| 172 | if ($element->hasHyperlink()) { |
||
| 173 | // Write relationship for hyperlink |
||
| 174 | $hyperlink = $element->getHyperlink(); |
||
| 175 | $hyperlink->relationId = 'rId' . $relId; |
||
| 176 | |||
| 177 | if (!$hyperlink->isInternal()) { |
||
| 178 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 179 | } else { |
||
| 180 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 181 | } |
||
| 182 | |||
| 183 | ++$relId; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | // Hyperlink in table |
||
| 191 | 33 | if ($iterator->current() instanceof ShapeTable) { |
|
| 192 | // Rows |
||
| 193 | $countRows = count($iterator->current()->getRows()); |
||
| 194 | for ($row = 0; $row < $countRows; $row++) { |
||
| 195 | // Cells in rows |
||
| 196 | $countCells = count($iterator->current()->getRow($row)->getCells()); |
||
| 197 | for ($cell = 0; $cell < $countCells; $cell++) { |
||
| 198 | $currentCell = $iterator->current()->getRow($row)->getCell($cell); |
||
| 199 | // Paragraphs in cell |
||
| 200 | foreach ($currentCell->getParagraphs() as $paragraph) { |
||
| 201 | // RichText in paragraph |
||
| 202 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 203 | // Run or Text in RichText |
||
| 204 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 205 | if ($element->hasHyperlink()) { |
||
| 206 | // Write relationship for hyperlink |
||
| 207 | $hyperlink = $element->getHyperlink(); |
||
| 208 | $hyperlink->relationId = 'rId' . $relId; |
||
| 209 | |||
| 210 | if (!$hyperlink->isInternal()) { |
||
| 211 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 212 | } else { |
||
| 213 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 214 | } |
||
| 215 | |||
| 216 | ++$relId; |
||
| 217 | } |
||
| 218 | } |
||
| 219 | } |
||
| 220 | } |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | 33 | if ($iterator->current() instanceof Group) { |
|
| 226 | $iterator2 = $pSlide->getShapeCollection()->getIterator(); |
||
| 227 | while ($iterator2->valid()) { |
||
| 228 | // Hyperlink on shape |
||
| 229 | if ($iterator2->current()->hasHyperlink()) { |
||
| 230 | // Write relationship for hyperlink |
||
| 231 | $hyperlink = $iterator2->current()->getHyperlink(); |
||
| 232 | $hyperlink->relationId = 'rId' . $relId; |
||
| 233 | |||
| 234 | if (!$hyperlink->isInternal()) { |
||
| 235 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 236 | } else { |
||
| 237 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 238 | } |
||
| 239 | |||
| 240 | ++$relId; |
||
| 241 | } |
||
| 242 | |||
| 243 | // Hyperlink on rich text run |
||
| 244 | if ($iterator2->current() instanceof RichText) { |
||
| 245 | foreach ($iterator2->current()->getParagraphs() as $paragraph) { |
||
| 246 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 247 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 248 | if ($element->hasHyperlink()) { |
||
| 249 | // Write relationship for hyperlink |
||
| 250 | $hyperlink = $element->getHyperlink(); |
||
| 251 | $hyperlink->relationId = 'rId' . $relId; |
||
| 252 | |||
| 253 | if (!$hyperlink->isInternal()) { |
||
| 254 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 255 | } else { |
||
| 256 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 257 | } |
||
| 258 | |||
| 259 | ++$relId; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | // Hyperlink in table |
||
| 267 | if ($iterator2->current() instanceof ShapeTable) { |
||
| 268 | // Rows |
||
| 269 | $countRows = count($iterator2->current()->getRows()); |
||
| 270 | for ($row = 0; $row < $countRows; $row++) { |
||
| 271 | // Cells in rows |
||
| 272 | $countCells = count($iterator2->current()->getRow($row)->getCells()); |
||
| 273 | for ($cell = 0; $cell < $countCells; $cell++) { |
||
| 274 | $currentCell = $iterator2->current()->getRow($row)->getCell($cell); |
||
| 275 | // Paragraphs in cell |
||
| 276 | foreach ($currentCell->getParagraphs() as $paragraph) { |
||
| 277 | // RichText in paragraph |
||
| 278 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 279 | // Run or Text in RichText |
||
| 280 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 281 | if ($element->hasHyperlink()) { |
||
| 282 | // Write relationship for hyperlink |
||
| 283 | $hyperlink = $element->getHyperlink(); |
||
| 284 | $hyperlink->relationId = 'rId' . $relId; |
||
| 285 | |||
| 286 | if (!$hyperlink->isInternal()) { |
||
| 287 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 288 | } else { |
||
| 289 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 290 | } |
||
| 291 | |||
| 292 | ++$relId; |
||
| 293 | } |
||
| 294 | } |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | $iterator2->next(); |
||
| 302 | } |
||
| 303 | } |
||
| 304 | |||
| 305 | 33 | $iterator->next(); |
|
| 306 | } |
||
| 307 | } |
||
| 308 | |||
| 309 | // Write comment relationships |
||
| 310 | 52 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 311 | 33 | $hasSlideComment = false; |
|
| 312 | |||
| 313 | // Loop trough images and write relationships |
||
| 314 | 33 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 315 | 33 | while ($iterator->valid()) { |
|
| 316 | 33 | if ($iterator->current() instanceof Comment) { |
|
| 317 | 5 | $hasSlideComment = true; |
|
| 318 | 5 | break; |
|
| 319 | 28 | } elseif ($iterator->current() instanceof Group) { |
|
| 320 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
||
| 321 | while ($iterator2->valid()) { |
||
| 322 | if ($iterator2->current() instanceof Comment) { |
||
| 323 | $hasSlideComment = true; |
||
| 324 | break 2; |
||
| 325 | } |
||
| 326 | $iterator2->next(); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | 28 | $iterator->next(); |
|
| 331 | } |
||
| 332 | |||
| 333 | 33 | if ($hasSlideComment) { |
|
| 334 | 5 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', '../comments/comment'.($idxSlide + 1).'.xml'); |
|
| 335 | 5 | ++$relId; |
|
| 336 | } |
||
| 337 | } |
||
| 338 | |||
| 339 | 52 | if ($pSlide->getNote()->getShapeCollection()->count() > 0) { |
|
| 340 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide', '../notesSlides/notesSlide'.($idxSlide + 1).'.xml'); |
||
| 341 | } |
||
| 342 | |||
| 343 | 52 | $objWriter->endElement(); |
|
| 344 | |||
| 345 | // Return |
||
| 346 | 52 | return $objWriter->getData(); |
|
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Write slide to XML format |
||
| 351 | * |
||
| 352 | * @param \PhpOffice\PhpPresentation\Slide $pSlide |
||
| 353 | * @return string XML Output |
||
| 354 | * @throws \Exception |
||
| 355 | */ |
||
| 356 | 52 | public function writeSlide(Slide $pSlide) |
|
| 502 | |||
| 503 | /** |
||
| 504 | * @param XMLWriter $objWriter |
||
| 505 | * @param Slide $oSlide |
||
| 506 | */ |
||
| 507 | 52 | protected function writeSlideAnimations(XMLWriter $objWriter, Slide $oSlide) |
|
| 508 | { |
||
| 509 | 52 | $arrayAnimations = $oSlide->getAnimations(); |
|
| 510 | 52 | if (empty($arrayAnimations)) { |
|
| 511 | 52 | return; |
|
| 512 | } |
||
| 513 | |||
| 514 | // Variables |
||
| 515 | $shapeId = 1; |
||
| 516 | $idCount = 1; |
||
| 517 | $hashToIdMap = array(); |
||
| 518 | $arrayAnimationIds = array(); |
||
| 519 | |||
| 520 | foreach ($oSlide->getShapeCollection() as $shape) { |
||
| 521 | $hashToIdMap[$shape->getHashCode()] = ++$shapeId; |
||
| 522 | } |
||
| 523 | foreach ($arrayAnimations as $oAnimation) { |
||
| 524 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
||
| 525 | $arrayAnimationIds[] = $hashToIdMap[$oShape->getHashCode()]; |
||
| 526 | } |
||
| 527 | } |
||
| 528 | |||
| 529 | // p:timing |
||
| 530 | $objWriter->startElement('p:timing'); |
||
| 531 | // p:timing/p:tnLst |
||
| 532 | $objWriter->startElement('p:tnLst'); |
||
| 533 | // p:timing/p:tnLst/p:par |
||
| 534 | $objWriter->startElement('p:par'); |
||
| 535 | // p:timing/p:tnLst/p:par/p:cTn |
||
| 536 | $objWriter->startElement('p:cTn'); |
||
| 537 | $objWriter->writeAttribute('id', $idCount++); |
||
| 538 | $objWriter->writeAttribute('dur', 'indefinite'); |
||
| 539 | $objWriter->writeAttribute('restart', 'never'); |
||
| 540 | $objWriter->writeAttribute('nodeType', 'tmRoot'); |
||
| 541 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst |
||
| 542 | $objWriter->startElement('p:childTnLst'); |
||
| 543 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq |
||
| 544 | $objWriter->startElement('p:seq'); |
||
| 545 | $objWriter->writeAttribute('concurrent', '1'); |
||
| 546 | $objWriter->writeAttribute('nextAc', 'seek'); |
||
| 547 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn |
||
| 548 | $objWriter->startElement('p:cTn'); |
||
| 549 | $objWriter->writeAttribute('id', $idCount++); |
||
| 550 | $objWriter->writeAttribute('dur', 'indefinite'); |
||
| 551 | $objWriter->writeAttribute('nodeType', 'mainSeq'); |
||
| 552 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst |
||
| 553 | $objWriter->startElement('p:childTnLst'); |
||
| 554 | |||
| 555 | // Each animation has multiple shapes |
||
| 556 | foreach ($arrayAnimations as $oAnimation) { |
||
| 557 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par |
||
| 558 | $objWriter->startElement('p:par'); |
||
| 559 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn |
||
| 560 | $objWriter->startElement('p:cTn'); |
||
| 561 | $objWriter->writeAttribute('id', $idCount++); |
||
| 562 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 563 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst |
||
| 564 | $objWriter->startElement('p:stCondLst'); |
||
| 565 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst/p:cond |
||
| 566 | $objWriter->startElement('p:cond'); |
||
| 567 | $objWriter->writeAttribute('delay', 'indefinite'); |
||
| 568 | $objWriter->endElement(); |
||
| 569 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:stCondLst |
||
| 570 | $objWriter->endElement(); |
||
| 571 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst |
||
| 572 | $objWriter->startElement('p:childTnLst'); |
||
| 573 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par |
||
| 574 | $objWriter->startElement('p:par'); |
||
| 575 | // 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 |
||
| 576 | $objWriter->startElement('p:cTn'); |
||
| 577 | $objWriter->writeAttribute('id', $idCount++); |
||
| 578 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 579 | // 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 |
||
| 580 | $objWriter->startElement('p:stCondLst'); |
||
| 581 | // 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 |
||
| 582 | $objWriter->startElement('p:cond'); |
||
| 583 | $objWriter->writeAttribute('delay', '0'); |
||
| 584 | $objWriter->endElement(); |
||
| 585 | // 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 |
||
| 586 | $objWriter->endElement(); |
||
| 587 | // 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 |
||
| 588 | $objWriter->startElement('p:childTnLst'); |
||
| 589 | |||
| 590 | $firstAnimation = true; |
||
| 591 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
||
| 592 | $nodeType = $firstAnimation ? 'clickEffect' : 'withEffect'; |
||
| 593 | $shapeId = $hashToIdMap[$oShape->getHashCode()]; |
||
| 594 | |||
| 595 | // p:par |
||
| 596 | $objWriter->startElement('p:par'); |
||
| 597 | // p:par/p:cTn |
||
| 598 | $objWriter->startElement('p:cTn'); |
||
| 599 | $objWriter->writeAttribute('id', $idCount++); |
||
| 600 | $objWriter->writeAttribute('presetID', '1'); |
||
| 601 | $objWriter->writeAttribute('presetClass', 'entr'); |
||
| 602 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 603 | $objWriter->writeAttribute('presetSubtype', '0'); |
||
| 604 | $objWriter->writeAttribute('grpId', '0'); |
||
| 605 | $objWriter->writeAttribute('nodeType', $nodeType); |
||
| 606 | // p:par/p:cTn/p:stCondLst |
||
| 607 | $objWriter->startElement('p:stCondLst'); |
||
| 608 | // p:par/p:cTn/p:stCondLst/p:cond |
||
| 609 | $objWriter->startElement('p:cond'); |
||
| 610 | $objWriter->writeAttribute('delay', '0'); |
||
| 611 | $objWriter->endElement(); |
||
| 612 | // p:par/p:cTn\##p:stCondLst |
||
| 613 | $objWriter->endElement(); |
||
| 614 | // p:par/p:cTn/p:childTnLst |
||
| 615 | $objWriter->startElement('p:childTnLst'); |
||
| 616 | // p:par/p:cTn/p:childTnLst/p:set |
||
| 617 | $objWriter->startElement('p:set'); |
||
| 618 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr |
||
| 619 | $objWriter->startElement('p:cBhvr'); |
||
| 620 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn |
||
| 621 | $objWriter->startElement('p:cTn'); |
||
| 622 | $objWriter->writeAttribute('id', $idCount++); |
||
| 623 | $objWriter->writeAttribute('dur', '1'); |
||
| 624 | $objWriter->writeAttribute('fill', 'hold'); |
||
| 625 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst |
||
| 626 | $objWriter->startElement('p:stCondLst'); |
||
| 627 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst/p:cond |
||
| 628 | $objWriter->startElement('p:cond'); |
||
| 629 | $objWriter->writeAttribute('delay', '0'); |
||
| 630 | $objWriter->endElement(); |
||
| 631 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn\##p:stCondLst |
||
| 632 | $objWriter->endElement(); |
||
| 633 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:cTn |
||
| 634 | $objWriter->endElement(); |
||
| 635 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl |
||
| 636 | $objWriter->startElement('p:tgtEl'); |
||
| 637 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl/p:spTgt |
||
| 638 | $objWriter->startElement('p:spTgt'); |
||
| 639 | $objWriter->writeAttribute('spid', $shapeId); |
||
| 640 | $objWriter->endElement(); |
||
| 641 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:tgtEl |
||
| 642 | $objWriter->endElement(); |
||
| 643 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst |
||
| 644 | $objWriter->startElement('p:attrNameLst'); |
||
| 645 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst/p:attrName |
||
| 646 | $objWriter->writeElement('p:attrName', 'style.visibility'); |
||
| 647 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:attrNameLst |
||
| 648 | $objWriter->endElement(); |
||
| 649 | // p:par/p:cTn/p:childTnLst/p:set\##p:cBhvr |
||
| 650 | $objWriter->endElement(); |
||
| 651 | // p:par/p:cTn/p:childTnLst/p:set/p:to |
||
| 652 | $objWriter->startElement('p:to'); |
||
| 653 | // p:par/p:cTn/p:childTnLst/p:set/p:to/p:strVal |
||
| 654 | $objWriter->startElement('p:strVal'); |
||
| 655 | $objWriter->writeAttribute('val', 'visible'); |
||
| 656 | $objWriter->endElement(); |
||
| 657 | // p:par/p:cTn/p:childTnLst/p:set\##p:to |
||
| 658 | $objWriter->endElement(); |
||
| 659 | // p:par/p:cTn/p:childTnLst\##p:set |
||
| 660 | $objWriter->endElement(); |
||
| 661 | // p:par/p:cTn\##p:childTnLst |
||
| 662 | $objWriter->endElement(); |
||
| 663 | // p:par\##p:cTn |
||
| 664 | $objWriter->endElement(); |
||
| 665 | // ##p:par |
||
| 666 | $objWriter->endElement(); |
||
| 667 | |||
| 668 | $firstAnimation = false; |
||
| 669 | } |
||
| 670 | |||
| 671 | // 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 |
||
| 672 | $objWriter->endElement(); |
||
| 673 | // 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 |
||
| 674 | $objWriter->endElement(); |
||
| 675 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst\##p:par |
||
| 676 | $objWriter->endElement(); |
||
| 677 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:childTnLst |
||
| 678 | $objWriter->endElement(); |
||
| 679 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par\##p:cTn |
||
| 680 | $objWriter->endElement(); |
||
| 681 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst\##p:par |
||
| 682 | $objWriter->endElement(); |
||
| 683 | } |
||
| 684 | |||
| 685 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn\##p:childTnLst |
||
| 686 | $objWriter->endElement(); |
||
| 687 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:cTn |
||
| 688 | $objWriter->endElement(); |
||
| 689 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst |
||
| 690 | $objWriter->startElement('p:prevCondLst'); |
||
| 691 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond |
||
| 692 | $objWriter->startElement('p:cond'); |
||
| 693 | $objWriter->writeAttribute('evt', 'onPrev'); |
||
| 694 | $objWriter->writeAttribute('delay', '0'); |
||
| 695 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl |
||
| 696 | $objWriter->startElement('p:tgtEl'); |
||
| 697 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 698 | $objWriter->writeElement('p:sldTgt', null); |
||
| 699 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond\##p:tgtEl |
||
| 700 | $objWriter->endElement(); |
||
| 701 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst\##p:cond |
||
| 702 | $objWriter->endElement(); |
||
| 703 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:prevCondLst |
||
| 704 | $objWriter->endElement(); |
||
| 705 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst |
||
| 706 | $objWriter->startElement('p:nextCondLst'); |
||
| 707 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond |
||
| 708 | $objWriter->startElement('p:cond'); |
||
| 709 | $objWriter->writeAttribute('evt', 'onNext'); |
||
| 710 | $objWriter->writeAttribute('delay', '0'); |
||
| 711 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl |
||
| 712 | $objWriter->startElement('p:tgtEl'); |
||
| 713 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 714 | $objWriter->writeElement('p:sldTgt', null); |
||
| 715 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond\##p:tgtEl |
||
| 716 | $objWriter->endElement(); |
||
| 717 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst\##p:cond |
||
| 718 | $objWriter->endElement(); |
||
| 719 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:nextCondLst |
||
| 720 | $objWriter->endElement(); |
||
| 721 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst\##p:seq |
||
| 722 | $objWriter->endElement(); |
||
| 723 | // p:timing/p:tnLst/p:par/p:cTn\##p:childTnLst |
||
| 724 | $objWriter->endElement(); |
||
| 725 | // p:timing/p:tnLst/p:par\##p:cTn |
||
| 726 | $objWriter->endElement(); |
||
| 727 | // p:timing/p:tnLst\##p:par |
||
| 728 | $objWriter->endElement(); |
||
| 729 | // p:timing\##p:tnLst |
||
| 730 | $objWriter->endElement(); |
||
| 731 | |||
| 732 | // p:timing/p:bldLst |
||
| 733 | $objWriter->startElement('p:bldLst'); |
||
| 734 | |||
| 735 | // Add in ids of all shapes in this slides animations |
||
| 736 | foreach ($arrayAnimationIds as $id) { |
||
| 737 | // p:timing/p:bldLst/p:bldP |
||
| 738 | $objWriter->startElement('p:bldP'); |
||
| 739 | $objWriter->writeAttribute('spid', $id); |
||
| 740 | $objWriter->writeAttribute('grpId', 0); |
||
| 741 | $objWriter->endELement(); |
||
| 742 | } |
||
| 743 | |||
| 744 | // p:timing\##p:bldLst |
||
| 745 | $objWriter->endElement(); |
||
| 746 | |||
| 747 | // ##p:timing |
||
| 748 | $objWriter->endElement(); |
||
| 749 | } |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Write group |
||
| 753 | * |
||
| 754 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 755 | * @param \PhpOffice\PhpPresentation\Shape\Group $group |
||
| 756 | * @param int $shapeId |
||
| 757 | */ |
||
| 758 | protected function writeShapeGroup(XMLWriter $objWriter, Group $group, &$shapeId) |
||
| 759 | { |
||
| 760 | // p:grpSp |
||
| 761 | $objWriter->startElement('p:grpSp'); |
||
| 762 | |||
| 763 | // p:nvGrpSpPr |
||
| 764 | $objWriter->startElement('p:nvGrpSpPr'); |
||
| 765 | |||
| 766 | // p:cNvPr |
||
| 767 | $objWriter->startElement('p:cNvPr'); |
||
| 768 | $objWriter->writeAttribute('name', 'Group '.$shapeId++); |
||
| 769 | $objWriter->writeAttribute('id', $shapeId); |
||
| 770 | $objWriter->endElement(); // p:cNvPr |
||
| 771 | // NOTE: Re: $shapeId This seems to be how PowerPoint 2010 does business. |
||
| 772 | |||
| 773 | // p:cNvGrpSpPr |
||
| 774 | $objWriter->writeElement('p:cNvGrpSpPr', null); |
||
| 775 | |||
| 776 | // p:nvPr |
||
| 777 | $objWriter->writeElement('p:nvPr', null); |
||
| 778 | |||
| 779 | $objWriter->endElement(); // p:nvGrpSpPr |
||
| 780 | |||
| 781 | // p:grpSpPr |
||
| 782 | $objWriter->startElement('p:grpSpPr'); |
||
| 783 | |||
| 784 | // a:xfrm |
||
| 785 | $objWriter->startElement('a:xfrm'); |
||
| 786 | |||
| 787 | // a:off |
||
| 788 | $objWriter->startElement('a:off'); |
||
| 789 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); |
||
| 790 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); |
||
| 791 | $objWriter->endElement(); // a:off |
||
| 792 | |||
| 793 | // a:ext |
||
| 794 | $objWriter->startElement('a:ext'); |
||
| 795 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); |
||
| 796 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); |
||
| 797 | $objWriter->endElement(); // a:ext |
||
| 798 | |||
| 799 | // a:chOff |
||
| 800 | $objWriter->startElement('a:chOff'); |
||
| 801 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($group->getOffsetX())); |
||
| 802 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($group->getOffsetY())); |
||
| 803 | $objWriter->endElement(); // a:chOff |
||
| 804 | |||
| 805 | // a:chExt |
||
| 806 | $objWriter->startElement('a:chExt'); |
||
| 807 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($group->getExtentX())); |
||
| 808 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($group->getExtentY())); |
||
| 809 | $objWriter->endElement(); // a:chExt |
||
| 810 | |||
| 811 | $objWriter->endElement(); // a:xfrm |
||
| 812 | |||
| 813 | $objWriter->endElement(); // p:grpSpPr |
||
| 814 | |||
| 815 | $this->writeShapeCollection($objWriter, $group->getShapeCollection(), $shapeId); |
||
| 816 | $objWriter->endElement(); // p:grpSp |
||
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Write chart |
||
| 821 | * |
||
| 822 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 823 | * @param \PhpOffice\PhpPresentation\Shape\Chart $shape |
||
| 824 | * @param int $shapeId |
||
| 825 | */ |
||
| 826 | 24 | protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $shapeId) |
|
| 893 | |||
| 894 | /** |
||
| 895 | * Write pic |
||
| 896 | * |
||
| 897 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 898 | * @param \PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter $shape |
||
| 899 | * @param int $shapeId |
||
| 900 | * @throws \Exception |
||
| 901 | */ |
||
| 902 | protected function writeShapeDrawing(XMLWriter $objWriter, ShapeDrawing\AbstractDrawingAdapter $shape, $shapeId) |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Write txt |
||
| 1024 | * |
||
| 1025 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1026 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
| 1027 | * @param int $shapeId |
||
| 1028 | * @throws \Exception |
||
| 1029 | */ |
||
| 1030 | protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId) |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Write table |
||
| 1170 | * |
||
| 1171 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1172 | * @param \PhpOffice\PhpPresentation\Shape\Table $shape |
||
| 1173 | * @param int $shapeId |
||
| 1174 | * @throws \Exception |
||
| 1175 | */ |
||
| 1176 | protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, $shapeId) |
||
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Write paragraphs |
||
| 1396 | * |
||
| 1397 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1398 | * @param \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs |
||
| 1399 | * @param bool $bIsPlaceholder |
||
| 1400 | * @throws \Exception |
||
| 1401 | */ |
||
| 1402 | protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceholder = false) |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * Write Line Shape |
||
| 1519 | * |
||
| 1520 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1521 | * @param \PhpOffice\PhpPresentation\Shape\Line $shape |
||
| 1522 | * @param int $shapeId |
||
| 1523 | */ |
||
| 1524 | protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId) |
||
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Write hyperlink |
||
| 1631 | * |
||
| 1632 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1633 | * @param \PhpOffice\PhpPresentation\AbstractShape|\PhpOffice\PhpPresentation\Shape\RichText\TextElement $shape |
||
| 1634 | */ |
||
| 1635 | protected function writeHyperlink(XMLWriter $objWriter, $shape) |
||
| 1649 | |||
| 1650 | /** |
||
| 1651 | * Write Note Slide |
||
| 1652 | * @param Note $pNote |
||
| 1653 | * @throws \Exception |
||
| 1654 | * @return string |
||
| 1655 | */ |
||
| 1656 | protected function writeNote(Note $pNote) |
||
| 1936 | |||
| 1937 | /** |
||
| 1938 | * Write Transition Slide |
||
| 1939 | * @link http://officeopenxml.com/prSlide-transitions.php |
||
| 1940 | * @param XMLWriter $objWriter |
||
| 1941 | * @param Transition $transition |
||
| 1942 | */ |
||
| 1943 | 52 | protected function writeSlideTransition(XMLWriter $objWriter, $transition) |
|
| 2190 | } |
||
| 2191 |
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: