File indexing completed on 2024-05-26 05:59:16

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 class Default_Model_DbTable_VConfigStoreCategory extends Local_Model_Table
0023 {
0024 
0025     protected $_keyColumnsForRow = array('store_category_id');
0026     protected $_key = 'store_category_id';
0027     protected $_name = "v_config_store_category";
0028 
0029     /**
0030      * @param int $dataId
0031      */
0032     public function deleteId($dataId)
0033     {
0034         $sql = "DELETE FROM {$this->_name} WHERE {$this->_key} = ?";
0035         $this->_db->query($sql,$dataId)->execute();
0036     }
0037 
0038     /**
0039      * @param int $storeId
0040      * @return array
0041      */
0042     public function fetchAllCategoriesForStore($storeId)
0043     {
0044         $active = Default_Model_DbTable_ProjectCategory::CATEGORY_ACTIVE;
0045         $notDeleted = Default_Model_DbTable_ProjectCategory::CATEGORY_NOT_DELETED;
0046         $sql = "
0047                 SELECT pc2.project_category_id
0048                 FROM v_category AS pc, v_category AS pc2
0049                 WHERE pc.v_category_id IN (SELECT DISTINCT csc.v_category_id
0050                                                  FROM v_config_store_category AS csc
0051                                                    JOIN v_category AS pc ON csc.v_category_id = pc.v_category_id
0052                                                  WHERE csc.store_id = :storeId)
0053                 ORDER BY pc2.v_category_id;
0054                 ";
0055         $results = $this->_db->fetchAll($sql, array('storeId' => $storeId));
0056         $values = array_map(function($row) { return $row['project_category_id']; }, $results);
0057         return $values;
0058     }
0059 
0060     /**
0061      * @param int|array $listCatId
0062      * @return array
0063      */
0064     public function fetchStoresForCatdId($listCatId)
0065     {
0066         $inQuery = '?';
0067         if (is_array($listCatId)) {
0068             $inQuery = implode(',', array_fill(0, count($listCatId), '?'));
0069         }
0070 
0071         $sql = '
0072             SELECT cs.store_id, cs.config_id_name 
0073             FROM config_store_category as csc
0074             join config_store as cs on cs.store_id = csc.store_id 
0075             where csc.project_category_id in ('.$inQuery.')
0076         ';
0077         
0078         $result = $this->_db->query($sql, $listCatId)->fetchAll();
0079         
0080         if (count($result) > 0) {
0081             return $result;
0082         } else {
0083             return array();
0084         }
0085     }
0086 
0087     public function fetchCatIdsForStore($store_id)
0088     {
0089         $sql = "
0090             SELECT csc.v_category_id 
0091             FROM v_config_store_category AS csc
0092             JOIN v_category AS pc ON pc.v_category_id = csc.v_category_id
0093             WHERE csc.store_id = :store_id
0094             AND csc.deleted_at IS NULL
0095              ORDER BY csc.`order`, pc.title
0096         ";
0097         $results = $this->_db->fetchAll($sql, array('store_id' => $store_id));
0098         $values = array_map(function($row) { return $row['v_category_id']; }, $results);
0099         return $values;
0100     }
0101 
0102 }