1 <?php
2
3 /* --------------------------------------------------------------
4 StoredCategory.inc.php 2016-01-16
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2016 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 MainFactory::load_class('StoredCategoryInterface');
14
15
16 /**
17 * Class StoredCategory
18 *
19 * This class extends the Category class and represents a persisted category with an unique ID.
20 *
21 * @category System
22 * @package Category
23 * @subpackage Entities
24 */
25 class StoredCategory extends Category implements StoredCategoryInterface
26 {
27 /**
28 * Category ID.
29 *
30 * @var int
31 */
32 protected $categoryId = 0;
33
34
35 /**
36 * Class Constructor
37 *
38 * @param IdType $categoryId Category ID.
39 * @param CategorySettingsInterface $settings Category settings.
40 */
41 public function __construct(IdType $categoryId, CategorySettingsInterface $settings)
42 {
43 parent::__construct($settings);
44
45 $this->categoryId = $categoryId->asInt();
46 }
47
48
49 /**
50 * Gets the ID of the StoredCategory.
51 *
52 * @return int
53 */
54 public function getCategoryId()
55 {
56 return $this->categoryId;
57 }
58
59
60 /**
61 * Get the addon value container ID.
62 *
63 * @return int
64 */
65 public function getAddonValueContainerId()
66 {
67 return $this->getCategoryId();
68 }
69
70
71 /**
72 * Sets the parent ID of the category.
73 *
74 * @param IdType $categoryId The parent ID.
75 *
76 * @throws LogicException When the passed id is equal to the category id.
77 *
78 * @return StoredCategory|$this Same instance for chained method calls.
79 */
80 public function setParentId(IdType $categoryId)
81 {
82 $id = $categoryId->asInt();
83 if($this->getCategoryId() === $id)
84 {
85 throw new LogicException('The parent id can not be equal to the category id "' . $id . '"');
86 }
87 parent::setParentId($categoryId);
88 }
89 }