Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
30 / 30 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| AbstractWriter | |
100.00% |
30 / 30 |
|
100.00% |
7 / 7 |
12 | |
100.00% |
1 / 1 |
| getDrawingHashTable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPhpPresentation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPhpPresentation | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setZipAdapter | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getZipAdapter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| allDrawings | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| iterateCollection | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
| 4 | * presentations documents. |
| 5 | * |
| 6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
| 7 | * General Public License version 3 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * For the full copyright and license information, please read the LICENSE |
| 10 | * file that was distributed with this source code. For the full list of |
| 11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
| 12 | * |
| 13 | * @see https://github.com/PHPOffice/PHPPresentation |
| 14 | * |
| 15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace PhpOffice\PhpPresentation\Writer; |
| 21 | |
| 22 | use PhpOffice\Common\Adapter\Zip\ZipInterface; |
| 23 | use PhpOffice\PhpPresentation\AbstractShape; |
| 24 | use PhpOffice\PhpPresentation\HashTable; |
| 25 | use PhpOffice\PhpPresentation\PhpPresentation; |
| 26 | use PhpOffice\PhpPresentation\Shape\Chart; |
| 27 | use PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter; |
| 28 | use PhpOffice\PhpPresentation\Shape\Group; |
| 29 | |
| 30 | abstract class AbstractWriter |
| 31 | { |
| 32 | /** |
| 33 | * Private unique hash table. |
| 34 | * |
| 35 | * @var HashTable |
| 36 | */ |
| 37 | protected $oDrawingHashTable; |
| 38 | |
| 39 | /** |
| 40 | * Private PhpPresentation. |
| 41 | * |
| 42 | * @var null|PhpPresentation |
| 43 | */ |
| 44 | protected $oPresentation; |
| 45 | |
| 46 | /** |
| 47 | * @var null|ZipInterface |
| 48 | */ |
| 49 | protected $oZipAdapter; |
| 50 | |
| 51 | /** |
| 52 | * Get drawing hash table. |
| 53 | */ |
| 54 | public function getDrawingHashTable(): HashTable |
| 55 | { |
| 56 | return $this->oDrawingHashTable; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get PhpPresentation object. |
| 61 | */ |
| 62 | public function getPhpPresentation(): ?PhpPresentation |
| 63 | { |
| 64 | return $this->oPresentation; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get PhpPresentation object. |
| 69 | * |
| 70 | * @param null|PhpPresentation $pPhpPresentation PhpPresentation object |
| 71 | * |
| 72 | * @return self |
| 73 | */ |
| 74 | public function setPhpPresentation(?PhpPresentation $pPhpPresentation = null) |
| 75 | { |
| 76 | $this->oPresentation = $pPhpPresentation; |
| 77 | |
| 78 | return $this; |
| 79 | } |
| 80 | |
| 81 | public function setZipAdapter(ZipInterface $oZipAdapter): self |
| 82 | { |
| 83 | $this->oZipAdapter = $oZipAdapter; |
| 84 | |
| 85 | return $this; |
| 86 | } |
| 87 | |
| 88 | public function getZipAdapter(): ?ZipInterface |
| 89 | { |
| 90 | return $this->oZipAdapter; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get an array of all drawings. |
| 95 | * |
| 96 | * @return array<int, AbstractShape> |
| 97 | */ |
| 98 | protected function allDrawings(): array |
| 99 | { |
| 100 | // Get an array of all drawings |
| 101 | $aDrawings = []; |
| 102 | |
| 103 | // Get an array of all master slides |
| 104 | $aSlideMasters = $this->getPhpPresentation()->getAllMasterSlides(); |
| 105 | |
| 106 | $aSlideMasterLayouts = array_map(function ($oSlideMaster) { |
| 107 | return $oSlideMaster->getAllSlideLayouts(); |
| 108 | }, $aSlideMasters); |
| 109 | |
| 110 | // Get an array of all slide layouts |
| 111 | $aSlideLayouts = []; |
| 112 | array_walk_recursive($aSlideMasterLayouts, function ($oSlideLayout) use (&$aSlideLayouts): void { |
| 113 | $aSlideLayouts[] = $oSlideLayout; |
| 114 | }); |
| 115 | |
| 116 | // Loop through PhpPresentation |
| 117 | foreach (array_merge($this->getPhpPresentation()->getAllSlides(), $aSlideMasters, $aSlideLayouts) as $oSlide) { |
| 118 | $arrayReturn = $this->iterateCollection($oSlide->getShapeCollection()); |
| 119 | $aDrawings = array_merge($aDrawings, $arrayReturn); |
| 120 | } |
| 121 | |
| 122 | return $aDrawings; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @param array<int, AbstractShape> $collection |
| 127 | * |
| 128 | * @return array<int, AbstractShape> |
| 129 | */ |
| 130 | private function iterateCollection(array $collection): array |
| 131 | { |
| 132 | $arrayReturn = []; |
| 133 | |
| 134 | foreach ($collection as $oShape) { |
| 135 | if ($oShape instanceof AbstractDrawingAdapter) { |
| 136 | $arrayReturn[] = $oShape; |
| 137 | } elseif ($oShape instanceof Chart) { |
| 138 | $arrayReturn[] = $oShape; |
| 139 | } elseif ($oShape instanceof Group) { |
| 140 | $arrayGroup = $this->iterateCollection($oShape->getShapeCollection()); |
| 141 | $arrayReturn = array_merge($arrayReturn, $arrayGroup); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return $arrayReturn; |
| 146 | } |
| 147 | } |