1 <?php
2 3 4 5 6 7 8 9 10
11
12 13 14 15 16 17 18 19 20 21 22
23 class CategorySettingsRepositoryReader implements CategorySettingsRepositoryReaderInterface
24 {
25 26 27 28
29 protected $db;
30
31 32 33 34
35 protected $categoryFactory;
36
37
38 39 40 41
42 protected $customerStatusProvider;
43
44
45 46 47 48 49 50 51
52 public function __construct(CI_DB_query_builder $db,
53 CategoryFactoryInterface $categoryFactory,
54 CustomerStatusProviderInterface $customerStatusProvider)
55 {
56 $this->db = $db;
57 $this->categoryFactory = $categoryFactory;
58 $this->customerStatusProvider = $customerStatusProvider;
59 }
60
61
62 63 64 65 66 67 68 69 70
71 public function getById(IdType $categoryId)
72 {
73 $category = $this->db->get_where('categories', array('categories_id' => $categoryId->asInt()))->row_array();
74
75 if($category === null)
76 {
77 throw new UnexpectedValueException('The requested category was not found in the database (ID:'
78 . $categoryId->asInt() . ')');
79 }
80
81 return $this->_createAndReturnCategorySettings($category);
82 }
83
84
85 86 87 88 89 90 91
92 protected function _createAndReturnCategorySettings(array $category)
93 {
94
95 $categorySettings = $this->categoryFactory->createCategorySettings();
96 $categorySettings->setCategoryListingTemplate(new StringType((string)$category['categories_template']));
97 $categorySettings->setProductListingTemplate(new StringType((string)$category['listing_template']));
98 $categorySettings->setProductSortColumn(new StringType((string)$category['products_sorting']));
99 $categorySettings->setProductSortDirection(new StringType((string)$category['products_sorting2']));
100 $categorySettings->setSitemapEntry(new BoolType($category['gm_sitemap_entry']));
101 $categorySettings->setSitemapPriority(new StringType((string)$category['gm_priority']));
102 $categorySettings->setSitemapChangeFreq(new StringType((string)$category['gm_changefreq']));
103 $categorySettings->setShowAttributes(new BoolType($category['gm_show_attributes']));
104 $categorySettings->setShowGraduatedPrices(new BoolType($category['gm_show_graduated_prices']));
105 $categorySettings->setShowQuantityInput(new BoolType($category['gm_show_qty']));
106 $categorySettings->setShowStock(new BoolType($category['gm_show_qty_info']));
107 $categorySettings->setShowSubcategories(new BoolType($category['show_sub_categories']));
108 $categorySettings->setShowSubcategoryImages(new BoolType($category['show_sub_categories_images']));
109 $categorySettings->setShowSubcategoryNames(new BoolType($category['show_sub_categories_names']));
110 $categorySettings->setShowSubcategoryProducts(new BoolType($category['show_sub_products']));
111 $categorySettings->setDefaultViewModeTiled(new BoolType($category['view_mode_tiled']));
112
113
114 $groupPermissionIds = $this->customerStatusProvider->getCustomerStatusIds();
115 $this->_setGroupPermissions($category, $groupPermissionIds, $categorySettings);
116
117 return $categorySettings;
118 }
119
120
121 122 123 124 125 126 127 128 129
130 protected function _setGroupPermissions($category, $groupPermissionIds, $categorySettings)
131 {
132 foreach($groupPermissionIds as $id)
133 {
134 if(array_key_exists('group_permission_' . $id, $category))
135 {
136 $categorySettings->setPermittedCustomerStatus(new IdType($id),
137 new BoolType($category['group_permission_' . $id]));
138 }
139 }
140
141 return $this;
142 }
143 }