1 <?php
2
3 /* --------------------------------------------------------------
4 CategorySettingsRepositoryWriter.php 2015-11-23
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 CategorySettingsRepositoryWriter
15 *
16 * This class provides methods for updating particular columns of specific category records in the database.
17 * The category settings are stored in the categories table and are more related to display and visibility modes of
18 * category related data.
19 *
20 * @category System
21 * @package Category
22 * @subpackage Repositories
23 */
24 class CategorySettingsRepositoryWriter implements CategorySettingsRepositoryWriterInterface
25 {
26 /**
27 * Database connector.
28 * @var CI_DB_query_builder
29 */
30 protected $db;
31
32 /**
33 * Table name.
34 * @var string
35 */
36 protected $table = 'categories';
37
38
39 /**
40 * Customer Status Provider
41 * @var CustomerStatusProviderInterface
42 */
43 protected $customerStatusProvider;
44
45
46 /**
47 * Initialize the category settings repository writer.
48 *
49 * @param CI_DB_query_builder $dbQueryBuilder Database connector.
50 * @param CustomerStatusProviderInterface $customerStatusProvider Customer Status Provider
51 */
52 public function __construct(CI_DB_query_builder $dbQueryBuilder,
53 CustomerStatusProviderInterface $customerStatusProvider)
54 {
55 $this->db = $dbQueryBuilder;
56 $this->customerStatusProvider = $customerStatusProvider;
57 }
58
59
60 /**
61 * Updates a specific category settings entity.
62 *
63 * @param IdType $categoryId Category ID.
64 * @param CategorySettingsInterface $settings Category settings.
65 *
66 * @return CategorySettingsRepositoryWriter Same instance for chained method calls.
67 */
68 public function update(IdType $categoryId, CategorySettingsInterface $settings)
69 {
70 $setArray = array(
71 'categories_template' => $settings->getCategoryListingTemplate(),
72 'listing_template' => $settings->getProductListingTemplate(),
73 'products_sorting' => $settings->getProductSortColumn(),
74 'products_sorting2' => $settings->getProductSortDirection(),
75 'gm_sitemap_entry' => $settings->isSitemapEntry(),
76 'gm_priority' => $settings->getSitemapPriority(),
77 'gm_changefreq' => $settings->getSitemapChangeFreq(),
78 'gm_show_attributes' => $settings->showAttributes(),
79 'gm_show_graduated_prices' => $settings->showGraduatedPrices(),
80 'gm_show_qty' => $settings->showQuantityInput(),
81 'gm_show_qty_info' => $settings->showStock(),
82 'show_sub_categories' => $settings->showSubcategories(),
83 'show_sub_categories_images' => $settings->showSubcategoryImages(),
84 'show_sub_categories_names' => $settings->showSubcategoryNames(),
85 'show_sub_products' => $settings->showSubcategoryProducts(),
86 'view_mode_tiled' => $settings->isDefaultViewModeTiled(),
87 );
88
89 $customerStatusIds = $this->customerStatusProvider->getCustomerStatusIds();
90
91 foreach($customerStatusIds as $customerStatusId)
92 {
93 $setArray['group_permission_'
94 . $customerStatusId] = (int)$settings->isPermittedCustomerStatus(new IdType($customerStatusId));
95 }
96
97 $whereArray = array(
98 'categories_id' => $categoryId->asInt()
99 );
100 $this->db->update($this->table, $setArray, $whereArray);
101
102 return $this;
103 }
104 }