Commit | Line | Data |
---|---|---|
13d8b49b MS |
1 | <?php |
2 | namespace wcf\data\category; | |
3 | use wcf\data\DatabaseObject; | |
4 | use wcf\system\category\CategoryHandler; | |
5 | use wcf\system\request\IRouteController; | |
6 | use wcf\system\WCF; | |
7 | ||
8 | /** | |
9 | * Represents a category. | |
10 | * | |
11 | * @author Matthias Schmidt | |
12 | * @copyright 2001-2012 WoltLab GmbH | |
13 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
14 | * @package com.woltlab.wcf | |
15 | * @subpackage data.category | |
16 | * @category Community Framework | |
17 | */ | |
18 | class Category extends DatabaseObject implements IRouteController { | |
19 | /** | |
20 | * category type of this category | |
21 | * @var wcf\system\category\ICategoryType | |
22 | */ | |
23 | protected $categoryType = null; | |
24 | ||
25 | /** | |
26 | * list of all parent category generations of this category | |
27 | * @var array<wcf\data\category\Category> | |
28 | */ | |
29 | protected $parentCategories = null; | |
30 | ||
31 | /** | |
32 | * parent category of this category | |
33 | * @var wcf\data\category\Category | |
34 | */ | |
35 | protected $parentCategory = null; | |
36 | ||
37 | /** | |
38 | * @see wcf\data\DatabaseObject::$databaseTableIndexName | |
39 | */ | |
40 | protected static $databaseTableIndexName = 'categoryID'; | |
41 | ||
42 | /** | |
43 | * @see wcf\data\DatabaseObject::$databaseTableName | |
44 | */ | |
45 | protected static $databaseTableName = 'category'; | |
46 | ||
47 | /** | |
48 | * @see wcf\data\IStorableObject::__get() | |
49 | */ | |
50 | public function __get($name) { | |
51 | $value = parent::__get($name); | |
52 | ||
53 | // check additional data | |
54 | if ($value === null) { | |
55 | if (isset($this->data['additionalData'][$name])) { | |
56 | $value = $this->data['additionalData'][$name]; | |
57 | } | |
58 | } | |
59 | ||
60 | return $value; | |
61 | } | |
62 | ||
63 | /** | |
64 | * Returns the category type of this category. | |
65 | * | |
66 | * @return wcf\system\category\ICategoryType | |
67 | */ | |
68 | public function getCategoryType() { | |
69 | if ($this->categoryType === null) { | |
70 | $this->categoryType = CategoryHandler::getInstance()->getObjectType($this->objectTypeID)->getProcessor(); | |
71 | } | |
72 | ||
73 | return $this->categoryType; | |
74 | } | |
75 | ||
76 | /** | |
77 | * @see wcf\system\request\IRouteController::getID() | |
78 | */ | |
79 | public function getID() { | |
80 | return $this->objectTypeCategoryID; | |
81 | } | |
82 | ||
83 | /** | |
84 | * Returns the parent category of this category. | |
85 | * | |
86 | * @return wcf\data\category\Category | |
87 | */ | |
88 | public function getParentCategory() { | |
89 | if ($this->parentCategoryID && $this->parentCategory === null) { | |
90 | $this->parentCategory = CategoryHandler::getInstance()->getCategory($this->objectTypeID, $this->parentCategoryID); | |
91 | } | |
92 | ||
93 | return $this->parentCategory; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Returns the parent categories of this category. | |
98 | * | |
99 | * @return array<wcf\data\category\Category> | |
100 | */ | |
101 | public function getParentCategories() { | |
102 | if ($this->parentCategories === null) { | |
103 | $this->parentCategories = array(); | |
104 | $parentCaregory = $this; | |
105 | while ($parentCaregory = $parentCaregory->getParentCategory()) { | |
106 | $this->parentCategories[] = $parentCaregory; | |
107 | } | |
108 | ||
109 | $this->parentCategories = array_reverse($this->parentCategories); | |
110 | } | |
111 | ||
112 | return $this->parentCategories; | |
113 | } | |
114 | ||
115 | /** | |
116 | * @see wcf\system\request\IRouteController::getTitle() | |
117 | */ | |
118 | public function getTitle() { | |
119 | return WCF::getLanguage()->get($this->title); | |
120 | } | |
121 | ||
122 | /** | |
123 | * @see wcf\data\DatabaseObject::handleData() | |
124 | */ | |
125 | protected function handleData($data) { | |
126 | // handle additional data | |
127 | $data['additionalData'] = @unserialize($data['additionalData']); | |
128 | if (!is_array($data['additionalData'])) { | |
129 | $data['additionalData'] = array(); | |
130 | } | |
131 | ||
132 | parent::handleData($data); | |
133 | } | |
134 | } |