1 <?php
2
3 /* --------------------------------------------------------------
4 CategoryReadService.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 CategoryReadService
15 *
16 * This class provides methods for retrieving data of a particular category and a collection of specific categories.
17 *
18 * @category System
19 * @package Category
20 */
21 class CategoryReadService implements CategoryReadServiceInterface
22 {
23 /**
24 * Category repository interface.
25 * @var CategoryRepositoryInterface
26 */
27 protected $categoryRepo;
28
29 /**
30 * Category list provider factory.
31 * @var CategoryListProviderFactoryInterface
32 */
33 protected $categoryListProviderFactory;
34
35
36 /**
37 * CategoryReadService constructor.
38 *
39 * @param CategoryRepositoryInterface $categoryRepo Category repository.
40 * @param CategoryListProviderFactoryInterface $categoryListProviderFactory Category list provider.
41 */
42 public function __construct(CategoryRepositoryInterface $categoryRepo,
43 CategoryListProviderFactoryInterface $categoryListProviderFactory)
44 {
45 $this->categoryRepo = $categoryRepo;
46 $this->categoryListProviderFactory = $categoryListProviderFactory;
47 }
48
49
50 /**
51 * Returns a StoredCategory object with the provided category ID.
52 *
53 * @param IdType $categoryId ID of the category.
54 *
55 * @return StoredCategoryInterface
56 */
57 public function getCategoryById(IdType $categoryId)
58 {
59 return $this->categoryRepo->getCategoryById($categoryId);
60 }
61
62
63 /**
64 * Returns a CategoryListItemCollection.
65 *
66 * @param LanguageCode $languageCode The language code for the wanted language.
67 * @param IdType|null $parentId The parent ID of the categories.
68 * @param IdType|null $customerStatusLimit Customer status ID to decide the allowance.
69 *
70 * @return CategoryListItemCollection
71 */
72 public function getCategoryList(LanguageCode $languageCode,
73 IdType $parentId = null,
74 IdType $customerStatusLimit = null)
75 {
76 if($parentId === null)
77 {
78 $parentId = new IdType(0);
79 }
80
81 if($customerStatusLimit === null)
82 {
83 $categoryListProvider = $this->categoryListProviderFactory->createCategoryListProvider($languageCode);
84 }
85 else
86 {
87 $categoryListProvider = $this->categoryListProviderFactory->createCategoryListProvider($languageCode, array(
88 'categories.group_permission_' . $customerStatusLimit => '1'
89 ));
90 }
91
92 return $categoryListProvider->getByParentId($parentId);
93 }
94
95
96 /**
97 * Returns CategoryListItemCollection of active categories.
98 *
99 * @param LanguageCode $languageCode The language code for the wanted language.
100 * @param IdType|null $parentId The parent ID of the categories.
101 * @param IdType|null $customerStatusLimit Customer status ID to decide the allowance.
102 *
103 * @return CategoryListItemCollection
104 */
105 public function getActiveCategoryList(LanguageCode $languageCode,
106 IdType $parentId = null,
107 IdType $customerStatusLimit = null)
108 {
109 if($parentId === null)
110 {
111 $parentId = new IdType(0);
112 }
113
114 if($customerStatusLimit === null)
115 {
116 $categoryListProvider = $this->categoryListProviderFactory->createCategoryListProvider($languageCode, array(
117 'categories.categories_status' => 1
118 ));
119 }
120 else
121 {
122 $categoryListProvider = $this->categoryListProviderFactory->createCategoryListProvider($languageCode, array(
123 'categories.categories_status' => 1,
124 'categories.group_permission_' . $customerStatusLimit => '1'
125 ));
126 }
127
128 return $categoryListProvider->getByParentId($parentId);
129 }
130 }
131