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