|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of PHPProject - A pure PHP library for reading and writing |
|
4
|
|
|
* presentations documents. |
|
5
|
|
|
* |
|
6
|
|
|
* PHPProject 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/PHPWord/contributors. |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/PHPOffice/PHPProject |
|
14
|
|
|
* @copyright 2009-2014 PHPProject contributors |
|
15
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace PhpOffice\PhpProject; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* PHPProject |
|
22
|
|
|
* |
|
23
|
|
|
* @category PHPProject |
|
24
|
|
|
* @package PHPProject |
|
25
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject) |
|
26
|
|
|
*/ |
|
27
|
|
|
class PhpProject |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Document properties |
|
31
|
|
|
* |
|
32
|
|
|
* @var DocumentProperties |
|
33
|
|
|
*/ |
|
34
|
|
|
private $properties; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Document informations |
|
38
|
|
|
* |
|
39
|
|
|
* @var DocumentInformations |
|
40
|
|
|
*/ |
|
41
|
|
|
private $informations; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Collection of task objects |
|
45
|
|
|
* |
|
46
|
|
|
* @var Task[] |
|
47
|
|
|
*/ |
|
48
|
|
|
private $taskCollection = array(); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Collection of resource objects |
|
52
|
|
|
* |
|
53
|
|
|
* @var Resource[] |
|
54
|
|
|
*/ |
|
55
|
|
|
private $resourceCollection = array(); |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Create a new PHPProject |
|
59
|
|
|
*/ |
|
60
|
23 |
|
public function __construct() |
|
61
|
|
|
{ |
|
62
|
|
|
// Create document properties |
|
63
|
23 |
|
$this->properties = new DocumentProperties(); |
|
64
|
|
|
// Create document informations |
|
65
|
23 |
|
$this->informations = new DocumentInformations(); |
|
66
|
23 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
//=============================================== |
|
69
|
|
|
// Document Properties |
|
70
|
|
|
//=============================================== |
|
71
|
|
|
/** |
|
72
|
|
|
* Get properties |
|
73
|
|
|
* |
|
74
|
|
|
* @return PHPProject_DocumentProperties |
|
75
|
|
|
*/ |
|
76
|
3 |
|
public function getProperties() |
|
77
|
|
|
{ |
|
78
|
3 |
|
return $this->properties; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set properties |
|
83
|
|
|
* |
|
84
|
|
|
* @param PHPProject_DocumentProperties $pValue |
|
85
|
|
|
*/ |
|
86
|
1 |
|
public function setProperties(DocumentProperties $pValue) |
|
87
|
|
|
{ |
|
88
|
1 |
|
$this->properties = $pValue; |
|
89
|
1 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
//=============================================== |
|
93
|
|
|
// Document Informations |
|
94
|
|
|
//=============================================== |
|
95
|
|
|
/** |
|
96
|
|
|
* Get informations |
|
97
|
|
|
* |
|
98
|
|
|
* @return DocumentInformations |
|
99
|
|
|
*/ |
|
100
|
3 |
|
public function getInformations() |
|
101
|
|
|
{ |
|
102
|
3 |
|
return $this->informations; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Set informations |
|
107
|
|
|
* |
|
108
|
|
|
* @param PHPProject_DocumentProperties $pValue |
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function setInformations(DocumentInformations $pValue) |
|
111
|
|
|
{ |
|
112
|
1 |
|
$this->informations = $pValue; |
|
113
|
1 |
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
//=============================================== |
|
117
|
|
|
// Resources |
|
118
|
|
|
//=============================================== |
|
119
|
|
|
/** |
|
120
|
|
|
* Create a resource |
|
121
|
|
|
* |
|
122
|
|
|
* @return Resource |
|
123
|
|
|
* @throws \Exception |
|
124
|
|
|
*/ |
|
125
|
7 |
|
public function createResource() |
|
126
|
|
|
{ |
|
127
|
7 |
|
$newRessource = new Resource(); |
|
128
|
7 |
|
$this->resourceCollection[] = $newRessource; |
|
129
|
7 |
|
return $newRessource; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Get resource count |
|
134
|
|
|
* |
|
135
|
|
|
* @return int |
|
136
|
|
|
*/ |
|
137
|
3 |
|
public function getResourceCount() |
|
138
|
|
|
{ |
|
139
|
3 |
|
return count($this->resourceCollection); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get all resources |
|
144
|
|
|
* |
|
145
|
|
|
* @return \PhpOffice\PhpProject\Resource[] |
|
146
|
|
|
*/ |
|
147
|
5 |
|
public function getAllResources() |
|
148
|
|
|
{ |
|
149
|
5 |
|
return $this->resourceCollection; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Get active resource |
|
154
|
|
|
* |
|
155
|
|
|
* @return Resource|null |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function getActiveResource() |
|
158
|
|
|
{ |
|
159
|
1 |
|
if (!empty($this->resourceCollection)) { |
|
160
|
1 |
|
return end($this->resourceCollection); |
|
161
|
|
|
} |
|
162
|
1 |
|
return null; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Get resource from index |
|
167
|
|
|
* |
|
168
|
|
|
* @return Resource|null |
|
169
|
|
|
*/ |
|
170
|
4 |
|
public function getResourceFromIndex($pIndex) |
|
171
|
|
|
{ |
|
172
|
4 |
|
foreach ($this->resourceCollection as $oResource) { |
|
173
|
4 |
|
if ($oResource->getIndex() == $pIndex) { |
|
|
|
|
|
|
174
|
4 |
|
return $oResource; |
|
175
|
|
|
} |
|
176
|
3 |
|
} |
|
177
|
1 |
|
return null; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
//=============================================== |
|
181
|
|
|
// Tasks |
|
182
|
|
|
//=============================================== |
|
183
|
|
|
/** |
|
184
|
|
|
* Create a task |
|
185
|
|
|
* |
|
186
|
|
|
* @return Task |
|
187
|
|
|
* @throws \Exception |
|
188
|
|
|
*/ |
|
189
|
9 |
|
public function createTask() |
|
190
|
|
|
{ |
|
191
|
9 |
|
$newTask = new Task(); |
|
192
|
9 |
|
$this->taskCollection[] = $newTask; |
|
193
|
9 |
|
return $newTask; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Get task count |
|
198
|
|
|
* |
|
199
|
|
|
* @return int |
|
200
|
|
|
*/ |
|
201
|
3 |
|
public function getTaskCount() |
|
202
|
|
|
{ |
|
203
|
3 |
|
return count($this->taskCollection); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Get all tasks |
|
208
|
|
|
* |
|
209
|
|
|
* @return Task[] |
|
210
|
|
|
*/ |
|
211
|
5 |
|
public function getAllTasks() |
|
212
|
|
|
{ |
|
213
|
5 |
|
return $this->taskCollection; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Get active task |
|
218
|
|
|
* |
|
219
|
|
|
* @return Task |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function getActiveTask() |
|
222
|
|
|
{ |
|
223
|
1 |
|
if (!empty($this->taskCollection)) { |
|
224
|
1 |
|
return end($this->taskCollection); |
|
|
|
|
|
|
225
|
|
|
} |
|
226
|
1 |
|
return null; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Get task from index |
|
231
|
|
|
* |
|
232
|
|
|
* @return Task|null |
|
233
|
|
|
*/ |
|
234
|
4 |
|
public function getTaskFromIndex($pIndex, Task $oTaskParent = null) |
|
235
|
|
|
{ |
|
236
|
4 |
|
if (is_null($oTaskParent)) { |
|
237
|
4 |
|
$arrayTask = $this->taskCollection; |
|
238
|
4 |
|
} else { |
|
239
|
4 |
|
$arrayTask = $oTaskParent->getTasks(); |
|
240
|
|
|
} |
|
241
|
4 |
|
foreach ($arrayTask as $oTask) { |
|
242
|
4 |
|
if ($oTask->getIndex() == $pIndex) { |
|
243
|
4 |
|
return $oTask; |
|
244
|
|
|
} else { |
|
245
|
4 |
|
if ($oTask->getTaskCount() > 0) { |
|
246
|
4 |
|
$return = $this->getTaskFromIndex($pIndex, $oTask); |
|
247
|
4 |
|
if ($return instanceof Task) { |
|
248
|
3 |
|
return $return; |
|
249
|
|
|
} |
|
250
|
1 |
|
} |
|
251
|
|
|
} |
|
252
|
4 |
|
} |
|
253
|
1 |
|
return null; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Remove task by index |
|
258
|
|
|
* |
|
259
|
|
|
* @param int $pIndex Active task index |
|
260
|
|
|
* @throws \Exception |
|
261
|
|
|
*/ |
|
262
|
2 |
|
public function removeTaskByIndex($pIndex = 0) |
|
263
|
|
|
{ |
|
264
|
2 |
|
if (!isset($this->taskCollection[$pIndex])) { |
|
265
|
1 |
|
throw new \Exception('Task index is out of bounds.'); |
|
266
|
|
|
} else { |
|
267
|
1 |
|
array_splice($this->taskCollection, $pIndex, 1); |
|
268
|
|
|
} |
|
269
|
1 |
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.