[CLEANUP] Adjust code to coding guidelines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Domain / Model / Category.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Fabien Udriot <fabien.udriot@typo3.org>
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 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This model represents a category (for anything).
28 *
29 * @author Fabien Udriot <fabien.udriot@typo3.org>
30 * @api
31 */
32 class Category extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
33
34 /**
35 * @var string
36 * @validate notEmpty
37 */
38 protected $title = '';
39
40 /**
41 * @var string
42 */
43 protected $description = '';
44
45 /**
46 * @var \TYPO3\CMS\Extbase\Domain\Model\Category|NULL
47 * @lazy
48 */
49 protected $parent = NULL;
50
51 /**
52 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\DomainObject\AbstractEntity>
53 * @lazy
54 */
55 protected $items = NULL;
56
57 /**
58 * The constructor.
59 */
60 public function __construct() {
61 $this->initStorageObjects();
62 }
63
64 /**
65 * Initializes all \TYPO3\CMS\Extbase\Persistence\ObjectStorage properties.
66 *
67 * @return void
68 * @api
69 */
70 protected function initStorageObjects() {
71 $this->items = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
72 }
73
74 /**
75 * Gets the title.
76 *
77 * @return string the title, might be empty
78 * @api
79 */
80 public function getTitle() {
81 return $this->title;
82 }
83
84 /**
85 * Sets the title.
86 *
87 * @param string $title the title to set, may be empty
88 * @return void
89 * @api
90 */
91 public function setTitle($title) {
92 $this->title = $title;
93 }
94
95 /**
96 * Gets the description.
97 *
98 * @return string the description, might be empty
99 * @api
100 */
101 public function getDescription() {
102 return $this->description;
103 }
104
105 /**
106 * Sets the description.
107 *
108 * @param string $description the description to set, may be empty
109 * @return void
110 * @api
111 */
112 public function setDescription($description) {
113 $this->description = $description;
114 }
115
116 /**
117 * Gets the parent category.
118 *
119 * @return \TYPO3\CMS\Extbase\Domain\Model\Category|NULL the parent category
120 * @api
121 */
122 public function getParent() {
123 if ($this->parent instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
124 $this->parent->_loadRealInstance();
125 }
126 return $this->parent;
127 }
128
129 /**
130 * Sets the parent category.
131 *
132 * @param \TYPO3\CMS\Extbase\Domain\Model\Category $parent the parent category
133 * @return void
134 * @api
135 */
136 public function setParent(\TYPO3\CMS\Extbase\Domain\Model\Category $parent) {
137 $this->parent = $parent;
138 }
139
140 /**
141 * Returns the items within this category.
142 *
143 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage the items, might be empty
144 * @api
145 */
146 public function getItems() {
147 return $this->items;
148 }
149
150 /**
151 * Sets the items within this category.
152 *
153 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $items
154 * @return void
155 * @api
156 */
157 public function setItems(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $items) {
158 $this->items = $items;
159 }
160
161 /**
162 * Adds a item to the items property
163 *
164 * @param \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $item
165 * @return void
166 * @api
167 */
168 public function addItem(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity $item) {
169 $this->items->attach($item);
170 }
171
172 /**
173 * Removes a item of the items property
174 *
175 * @param \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $item
176 * @return void
177 * @api
178 */
179 public function removeItem(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity $item) {
180 $this->items->detach($item);
181 }
182 }
183
184 ?>