1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer; |
4
|
|
|
|
5
|
|
|
use PhpOffice\Common\Adapter\Zip\ZipInterface; |
6
|
|
|
use PhpOffice\PhpPresentation\PhpPresentation; |
7
|
|
|
use PhpOffice\PhpPresentation\Shape\Chart; |
8
|
|
|
use PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter; |
9
|
|
|
use PhpOffice\PhpPresentation\Shape\Group; |
10
|
|
|
|
11
|
|
|
abstract class AbstractWriter |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Private unique hash table |
15
|
|
|
* |
16
|
|
|
* @var \PhpOffice\PhpPresentation\HashTable |
17
|
|
|
*/ |
18
|
|
|
protected $oDrawingHashTable; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Private PhpPresentation |
22
|
|
|
* |
23
|
|
|
* @var PhpPresentation |
24
|
|
|
*/ |
25
|
|
|
protected $oPresentation; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var ZipInterface |
29
|
|
|
*/ |
30
|
|
|
protected $oZipAdapter; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get drawing hash table |
34
|
|
|
* |
35
|
|
|
* @return \PhpOffice\PhpPresentation\HashTable |
36
|
|
|
*/ |
37
|
177 |
|
public function getDrawingHashTable() |
38
|
|
|
{ |
39
|
177 |
|
return $this->oDrawingHashTable; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get PhpPresentation object |
44
|
|
|
* |
45
|
|
|
* @return PhpPresentation |
46
|
|
|
* @throws \Exception |
47
|
|
|
*/ |
48
|
188 |
|
public function getPhpPresentation() |
49
|
|
|
{ |
50
|
188 |
|
if (empty($this->oPresentation)) { |
51
|
5 |
|
throw new \Exception("No PhpPresentation assigned."); |
52
|
|
|
} |
53
|
183 |
|
return $this->oPresentation; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get PhpPresentation object |
58
|
|
|
* |
59
|
|
|
* @param PhpPresentation $pPhpPresentation PhpPresentation object |
60
|
|
|
* @throws \Exception |
61
|
|
|
* @return \PhpOffice\PhpPresentation\Writer\ODPresentation |
62
|
|
|
*/ |
63
|
197 |
|
public function setPhpPresentation(PhpPresentation $pPhpPresentation = null) |
64
|
|
|
{ |
65
|
197 |
|
$this->oPresentation = $pPhpPresentation; |
66
|
197 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param ZipInterface $oZipAdapter |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
197 |
|
public function setZipAdapter(ZipInterface $oZipAdapter) |
75
|
|
|
{ |
76
|
197 |
|
$this->oZipAdapter = $oZipAdapter; |
77
|
197 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return ZipInterface |
82
|
|
|
*/ |
83
|
180 |
|
public function getZipAdapter() |
84
|
|
|
{ |
85
|
180 |
|
return $this->oZipAdapter; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get an array of all drawings |
90
|
|
|
* |
91
|
|
|
* @return \PhpOffice\PhpPresentation\Shape\AbstractDrawing[] All drawings in PhpPresentation |
92
|
|
|
* @throws \Exception |
93
|
|
|
*/ |
94
|
177 |
|
protected function allDrawings() |
95
|
|
|
{ |
96
|
|
|
// Get an array of all drawings |
97
|
177 |
|
$aDrawings = array(); |
98
|
|
|
|
99
|
|
|
// Loop through PhpPresentation |
100
|
177 |
|
foreach (array_merge($this->getPhpPresentation()->getAllSlides(), $this->getPhpPresentation()->getAllMasterSlides()) as $oSlide) { |
101
|
177 |
|
$arrayReturn = $this->iterateCollection($oSlide->getShapeCollection()->getIterator()); |
102
|
177 |
|
$aDrawings = array_merge($aDrawings, $arrayReturn); |
103
|
|
|
} |
104
|
|
|
|
105
|
177 |
|
return $aDrawings; |
106
|
|
|
} |
107
|
|
|
|
108
|
177 |
|
private function iterateCollection(\ArrayIterator $oIterator) |
109
|
|
|
{ |
110
|
177 |
|
$arrayReturn = array(); |
111
|
177 |
|
if ($oIterator->count() <= 0) { |
112
|
175 |
|
return $arrayReturn; |
113
|
|
|
} |
114
|
|
|
|
115
|
142 |
|
while ($oIterator->valid()) { |
116
|
142 |
|
$oShape = $oIterator->current(); |
117
|
142 |
|
if ($oShape instanceof AbstractDrawingAdapter) { |
118
|
22 |
|
$arrayReturn[] = $oShape; |
119
|
|
|
} elseif ($oShape instanceof Chart) { |
120
|
58 |
|
$arrayReturn[] = $oShape; |
121
|
|
|
} elseif ($oShape instanceof Group) { |
122
|
2 |
|
$arrayGroup = $this->iterateCollection($oShape->getShapeCollection()->getIterator()); |
123
|
2 |
|
$arrayReturn = array_merge($arrayReturn, $arrayGroup); |
124
|
|
|
} |
125
|
142 |
|
$oIterator->next(); |
126
|
|
|
} |
127
|
142 |
|
return $arrayReturn; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|