[TASK] EM: extension info within "Get Extensions"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / Extension.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Main extension model
31 *
32 * @author Susanne Moog <typo3@susannemoog.de>
33 */
34 class Extension extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
35
36 /**
37 * Contains default categories.
38 *
39 * @var array
40 */
41 static protected $defaultCategories = array(
42 0 => 'be',
43 1 => 'module',
44 2 => 'fe',
45 3 => 'plugin',
46 4 => 'misc',
47 5 => 'services',
48 6 => 'templates',
49 8 => 'doc',
50 9 => 'example'
51 );
52
53 /**
54 * Contains default states.
55 *
56 * @var array
57 */
58 static protected $defaultStates = array(
59 0 => 'alpha',
60 1 => 'beta',
61 2 => 'stable',
62 3 => 'experimental',
63 4 => 'test',
64 5 => 'obsolete',
65 6 => 'excludeFromUpdates',
66 999 => 'n/a'
67 );
68
69 /**
70 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
71 */
72 protected $objectManager;
73
74 /**
75 * @var string
76 */
77 protected $extensionKey = '';
78
79 /**
80 * @var string
81 */
82 protected $version = '';
83
84 /**
85 * @var integer
86 */
87 protected $integerVersion = 0;
88
89 /**
90 * @var string
91 */
92 protected $title = '';
93
94 /**
95 * @var string
96 */
97 protected $description = '';
98
99 /**
100 * @var integer
101 */
102 protected $state = 0;
103
104 /**
105 * @var integer
106 */
107 protected $category = 0;
108
109 /**
110 * @var \DateTime
111 */
112 protected $lastUpdated;
113
114 /**
115 * @var string
116 */
117 protected $updateComment = '';
118
119 /**
120 * @var string
121 */
122 protected $authorName = '';
123
124 /**
125 * @var string
126 */
127 protected $authorEmail = '';
128
129 /**
130 * @var boolean
131 */
132 protected $currentVersion = FALSE;
133
134 /**
135 * @var string
136 */
137 protected $md5hash = '';
138
139 /**
140 * @var integer
141 */
142 protected $reviewState;
143
144 /**
145 * @var integer
146 */
147 protected $alldownloadcounter;
148
149 /**
150 * @var string
151 */
152 protected $serializedDependencies = '';
153
154 /**
155 * @var \SplObjectStorage<Tx_Extensionmanager_Utility_Dependency>
156 */
157 protected $dependencies = NULL;
158
159 /**
160 * @internal
161 * @var integer
162 */
163 protected $position = 0;
164
165 /**
166 * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
167 * @return void
168 */
169 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
170 $this->objectManager = $objectManager;
171 }
172
173 /**
174 * @param string $authorEmail
175 * @return void
176 */
177 public function setAuthorEmail($authorEmail) {
178 $this->authorEmail = $authorEmail;
179 }
180
181 /**
182 * @return string
183 */
184 public function getAuthorEmail() {
185 return $this->authorEmail;
186 }
187
188 /**
189 * @param string $authorName
190 * @return void
191 */
192 public function setAuthorName($authorName) {
193 $this->authorName = $authorName;
194 }
195
196 /**
197 * @return string
198 */
199 public function getAuthorName() {
200 return $this->authorName;
201 }
202
203 /**
204 * @param integer $category
205 * @return void
206 */
207 public function setCategory($category) {
208 $this->category = $category;
209 }
210
211 /**
212 * @return integer
213 */
214 public function getCategory() {
215 return $this->category;
216 }
217
218 /**
219 * Get Category String
220 *
221 * @return string
222 */
223 public function getCategoryString() {
224 $categoryString = '';
225 if (isset(self::$defaultCategories[$this->getCategory()])) {
226 $categoryString = self::$defaultCategories[$this->getCategory()];
227 }
228 return $categoryString;
229 }
230
231 /**
232 * Returns category index from a given string or a integer.
233 * Fallback to 4 - 'misc' in case string is not found or integer ist out of range.
234 *
235 * @param string|integer $category Category string or integer
236 * @return integer Valid category index
237 */
238 public function getCategoryIndexFromStringOrNumber($category) {
239 $categoryIndex = 4;
240 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($category)) {
241 $categoryIndex = (integer)$category;
242 if ($categoryIndex < 0 || $categoryIndex > 9) {
243 $categoryIndex = 4;
244 }
245 } elseif (is_string($category)) {
246 $categoryIndex = array_search($category, self::$defaultCategories);
247 if ($categoryIndex === FALSE) {
248 $categoryIndex = 4;
249 }
250 }
251 return $categoryIndex;
252 }
253
254 /**
255 * @param string $description
256 * @return void
257 */
258 public function setDescription($description) {
259 $this->description = $description;
260 }
261
262 /**
263 * @return string
264 */
265 public function getDescription() {
266 return $this->description;
267 }
268
269 /**
270 * @param string $extensionKey
271 * @return void
272 */
273 public function setExtensionKey($extensionKey) {
274 $this->extensionKey = $extensionKey;
275 }
276
277 /**
278 * @return string
279 */
280 public function getExtensionKey() {
281 return $this->extensionKey;
282 }
283
284 /**
285 * @param \DateTime $lastUpdated
286 * @return void
287 */
288 public function setLastUpdated(\DateTime $lastUpdated) {
289 $this->lastUpdated = $lastUpdated;
290 }
291
292 /**
293 * @return \DateTime
294 */
295 public function getLastUpdated() {
296 return $this->lastUpdated;
297 }
298
299 /**
300 * @param integer $state
301 * @return void
302 */
303 public function setState($state) {
304 $this->state = $state;
305 }
306
307 /**
308 * @return integer
309 */
310 public function getState() {
311 return $this->state;
312 }
313
314 /**
315 * Get State string
316 *
317 * @return string
318 */
319 public function getStateString() {
320 $stateString = '';
321 if (isset(self::$defaultStates[$this->getState()])) {
322 $stateString = self::$defaultStates[$this->getState()];
323 }
324 return $stateString;
325 }
326
327 /**
328 * Returns either array with all default states or index/title
329 * of a state entry.
330 *
331 * @param mixed $state state title or state index
332 * @return mixed
333 */
334 public function getDefaultState($state = NULL) {
335 $defaultState = '';
336 if (is_null($state)) {
337 $defaultState = self::$defaultStates;
338 } else {
339 if (is_string($state)) {
340 $stateIndex = array_search(strtolower($state), self::$defaultStates);
341 if ($stateIndex === FALSE) {
342 // default state
343 $stateIndex = 999;
344 }
345 $defaultState = $stateIndex;
346 } else {
347 if (is_int($state) && $state >= 0) {
348 if (array_key_exists($state, self::$defaultStates)) {
349 $stateTitle = self::$defaultStates[$state];
350 } else {
351 // default state
352 $stateTitle = 'n/a';
353 }
354 $defaultState = $stateTitle;
355 }
356 }
357 }
358 return $defaultState;
359 }
360
361 /**
362 * @param string $title
363 * @return void
364 */
365 public function setTitle($title) {
366 $this->title = $title;
367 }
368
369 /**
370 * @return string
371 */
372 public function getTitle() {
373 return $this->title;
374 }
375
376 /**
377 * @param string $updateComment
378 * @return void
379 */
380 public function setUpdateComment($updateComment) {
381 $this->updateComment = $updateComment;
382 }
383
384 /**
385 * @return string
386 */
387 public function getUpdateComment() {
388 return $this->updateComment;
389 }
390
391 /**
392 * @param string $version
393 * @return void
394 */
395 public function setVersion($version) {
396 $this->version = $version;
397 }
398
399 /**
400 * @return string
401 */
402 public function getVersion() {
403 return $this->version;
404 }
405
406 /**
407 * @param boolean $currentVersion
408 * @return void
409 */
410 public function setCurrentVersion($currentVersion) {
411 $this->currentVersion = $currentVersion;
412 }
413
414 /**
415 * @return boolean
416 */
417 public function getCurrentVersion() {
418 return $this->currentVersion;
419 }
420
421 /**
422 * @param string $md5hash
423 * @return void
424 */
425 public function setMd5hash($md5hash) {
426 $this->md5hash = $md5hash;
427 }
428
429 /**
430 * @return string
431 */
432 public function getMd5hash() {
433 return $this->md5hash;
434 }
435
436 /**
437 * Possible install pathes
438 *
439 * @static
440 * @return array
441 */
442 static public function returnInstallPaths() {
443 $installPaths = array(
444 'System' => PATH_typo3 . 'sysext/',
445 'Global' => PATH_typo3 . 'ext/',
446 'Local' => PATH_typo3conf . 'ext/'
447 );
448 return $installPaths;
449 }
450
451 /**
452 * Allowed install pathes
453 *
454 * @static
455 * @return array
456 */
457 static public function returnAllowedInstallPaths() {
458 $installPaths = self::returnInstallPaths();
459 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall'])) {
460 unset($installPaths['System']);
461 }
462 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall'])) {
463 unset($installPaths['Global']);
464 }
465 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowLocalInstall'])) {
466 unset($installPaths['Local']);
467 }
468 return $installPaths;
469 }
470
471 /**
472 * Allowed install names: System, Global, Local
473 *
474 * @static
475 * @return array
476 */
477 static public function returnAllowedInstallTypes() {
478 $installPaths = self::returnAllowedInstallPaths();
479 return array_keys($installPaths);
480 }
481
482 /**
483 * @param string $dependencies
484 * @return void
485 */
486 public function setSerializedDependencies($dependencies) {
487 $this->serializedDependencies = $dependencies;
488 }
489
490 /**
491 * @return string
492 */
493 public function getSerializedDependencies() {
494 return $this->serializedDependencies;
495 }
496
497 /**
498 * @param \SplObjectStorage $dependencies
499 * @return void
500 */
501 public function setDependencies($dependencies) {
502 $this->dependencies = $dependencies;
503 }
504
505 /**
506 * @return \SplObjectStorage
507 */
508 public function getDependencies() {
509 if (!is_object($this->dependencies)) {
510 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility */
511 $dependencyUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
512 $this->setDependencies($dependencyUtility->convertDependenciesToObjects($this->getSerializedDependencies()));
513 }
514 return $this->dependencies;
515 }
516
517 /**
518 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency $dependency
519 * @return void
520 */
521 public function addDependency(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency $dependency) {
522 $this->dependencies->attach($dependency);
523 }
524
525 /**
526 * @param integer $integerVersion
527 * @return void
528 */
529 public function setIntegerVersion($integerVersion) {
530 $this->integerVersion = $integerVersion;
531 }
532
533 /**
534 * @return integer
535 */
536 public function getIntegerVersion() {
537 return $this->integerVersion;
538 }
539
540 /**
541 * @param integer $reviewState
542 * @return void
543 */
544 public function setReviewState($reviewState) {
545 $this->reviewState = $reviewState;
546 }
547
548 /**
549 * @return integer
550 */
551 public function getReviewState() {
552 return $this->reviewState;
553 }
554
555 /**
556 * @param integer $position
557 * @return void
558 */
559 public function setPosition($position) {
560 $this->position = $position;
561 }
562
563 /**
564 * @return integer
565 */
566 public function getPosition() {
567 return $this->position;
568 }
569
570 /**
571 * @param integer $alldownloadcounter
572 */
573 public function setAlldownloadcounter($alldownloadcounter) {
574 $this->alldownloadcounter = $alldownloadcounter;
575 }
576
577 /**
578 * @return integer
579 */
580 public function getAlldownloadcounter() {
581 return $this->alldownloadcounter;
582 }
583
584 }
585
586 ?>