1 <?php
2
3 /* --------------------------------------------------------------
4 CategoryListItem.inc.php 2015-11-26
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 /**
14 * Class CategoryListItem
15 *
16 * This class represents a flattened category with just its essential data.
17 * The object stores language specific data only in one language and is mainly used inside a CategoryListItemCollection
18 * for displaying among other CategoryListItems in a list.
19 * The class provides only read access and can not use to manipulate and persist categories data.
20 *
21 * @category System
22 * @package Category
23 * @subpackage Entities
24 */
25 class CategoryListItem
26 {
27 /**
28 * Category repository.
29 *
30 * @var CategoryRepositoryInterface
31 */
32 protected $categoryRepo;
33
34 /**
35 * Category list provider.
36 *
37 * @var CategoryListProviderInterface
38 */
39 protected $categoryListProvider;
40
41 /**
42 * Category ID.
43 *
44 * @var int
45 */
46 protected $categoryId;
47
48 /**
49 * Category parent ID.
50 *
51 * @var int
52 */
53 protected $parentId;
54
55 /**
56 * Value whether category is active?
57 *
58 * @var bool
59 */
60 protected $active;
61
62 /**
63 * Category name.
64 *
65 * @var string
66 */
67 protected $name;
68
69 /**
70 * Category heading title.
71 *
72 * @var string
73 */
74 protected $headingTitle;
75
76 /**
77 * Category description.
78 *
79 * @var string
80 */
81 protected $description;
82
83 /**
84 * Category URL keywords.
85 *
86 * @var string
87 */
88 protected $urlKeywords;
89
90 /**
91 * Category image.
92 *
93 * @var string
94 */
95 protected $image;
96
97 /**
98 * Image alternative text.
99 *
100 * @var string
101 */
102 protected $imageAltText;
103
104 /**
105 * Category icon file.
106 *
107 * @var string
108 */
109 protected $icon;
110
111
112 /**
113 * CategoryListItem constructor.
114 *
115 * @param CategoryRepositoryInterface $categoryRepo Category repository.
116 * @param CategoryListProviderInterface $categoryListProvider Category list provider.
117 * @param IdType $categoryId Category ID.
118 * @param IdType $parentId Category parent ID.
119 * @param BoolType $active Is category active?
120 * @param StringType $name Category name.
121 * @param StringType $headingTitle Category heading title.
122 * @param StringType $description Category description.
123 * @param StringType $urlKeywords URL keywords.
124 * @param StringType $image Category image.
125 * @param StringType $imageAltText Image alternative text.
126 * @param StringType $icon Category icon.
127 */
128 public function __construct(CategoryRepositoryInterface $categoryRepo,
129 CategoryListProviderInterface $categoryListProvider,
130 IdType $categoryId,
131 IdType $parentId,
132 BoolType $active,
133 StringType $name,
134 StringType $headingTitle,
135 StringType $description,
136 StringType $urlKeywords,
137 StringType $image,
138 StringType $imageAltText,
139 StringType $icon)
140 {
141
142 $this->categoryRepo = $categoryRepo;
143 $this->categoryListProvider = $categoryListProvider;
144 $this->categoryId = $categoryId->asInt();
145 $this->parentId = $parentId->asInt();
146 $this->active = $active->asBool();
147 $this->name = $name->asString();
148 $this->headingTitle = $headingTitle->asString();
149 $this->description = $description->asString();
150 $this->urlKeywords = $urlKeywords->asString();
151 $this->image = $image->asString();
152 $this->imageAltText = $imageAltText->asString();
153 $this->icon = $icon->asString();
154 }
155
156
157 /**
158 * Returns the category ID.
159 *
160 * @return int
161 */
162 public function getCategoryId()
163 {
164 return $this->categoryId;
165 }
166
167
168 /**
169 * Returns the category parent ID.
170 *
171 * @return int
172 */
173 public function getParentId()
174 {
175 return $this->parentId;
176 }
177
178
179 /**
180 * Returns the value whether the category is active.
181 *
182 * @return boolean
183 */
184 public function isActive()
185 {
186 return $this->active;
187 }
188
189
190 /**
191 * Returns the category name.
192 *
193 * @return string
194 */
195 public function getName()
196 {
197 return $this->name;
198 }
199
200
201 /**
202 * Returns the category heading title.
203 *
204 * @return string
205 */
206 public function getHeadingTitle()
207 {
208 return $this->headingTitle;
209 }
210
211
212 /**
213 * Returns the category description.
214 *
215 * @return string
216 */
217 public function getDescription()
218 {
219 return $this->description;
220 }
221
222
223 /**
224 * Returns the URL keywords.
225 *
226 * @return string
227 */
228 public function getUrlKeywords()
229 {
230 return $this->urlKeywords;
231 }
232
233
234 /**
235 * Returns the category image.
236 *
237 * @return string
238 */
239 public function getImage()
240 {
241 return $this->image;
242 }
243
244
245 /**
246 * Returns the image alternative text.
247 *
248 * @return string
249 */
250 public function getImageAltText()
251 {
252 return $this->imageAltText;
253 }
254
255
256 /**
257 * Returns the category icon.
258 *
259 * @return string
260 */
261 public function getIcon()
262 {
263 return $this->icon;
264 }
265
266
267 /**
268 * Returns the category object.
269 *
270 * @return CategoryInterface
271 */
272 public function getCategoryObject()
273 {
274 $id = new IdType($this->getCategoryId());
275
276 return $this->categoryRepo->getCategoryById($id);
277 }
278
279
280 /**
281 * Returns the subcategory collection.
282 *
283 * @return CategoryListItemCollection
284 */
285 public function getSubcategoryList()
286 {
287 $id = new IdType($this->getCategoryId());
288
289 return $this->categoryListProvider->getByParentId($id);
290 }
291 }