File indexing completed on 2025-02-09 07:14:33
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_HiveContentCategory extends Local_Model_Table 0023 { 0024 protected $_keyColumnsForRow = array('id'); 0025 protected $_key = 'id'; 0026 protected $_name = "hive_content_category"; 0027 0028 0029 0030 0031 /** 0032 * @param int $category_id 0033 * @return Num of rows 0034 **/ 0035 public function fetchCountProjectsForCategory($category_id) 0036 { 0037 0038 $sql = " 0039 SELECT 0040 count(1) AS 'count' 0041 FROM 0042 hive_content 0043 WHERE 0044 type = ? 0045 AND is_imported = 0 0046 AND deletedat = 0 0047 GROUP BY type 0048 "; 0049 0050 $sql = $this->_db->quoteInto($sql, $category_id, 'INTEGER'); 0051 0052 $result = $this->_db->fetchRow($sql); 0053 0054 return $result['count']; 0055 0056 } 0057 0058 /** 0059 * @param int $category_id 0060 * @return Num of rows 0061 **/ 0062 public function fetchCountAllProjectsForCategory($category_id) 0063 { 0064 0065 $sql = " 0066 SELECT 0067 count(1) AS 'count' 0068 FROM 0069 hive_content 0070 WHERE 0071 type = ? 0072 AND deletedat = 0 0073 GROUP BY type 0074 "; 0075 0076 $sql = $this->_db->quoteInto($sql, $category_id, 'INTEGER'); 0077 0078 $result = $this->_db->fetchRow($sql); 0079 0080 return $result['count']; 0081 0082 } 0083 0084 /** 0085 * @param int $category_id Hive-Dat-Id 0086 * @param int $startIndex Default 0 0087 * @param int $limit Default 5 0088 * @param int $alsoDeleted Default false 0089 * @return Num of rows 0090 **/ 0091 public function fetchAllProjectsForCategory($category_id, $startIndex = 0, $limit = 5, $alsoDeleted = false) 0092 { 0093 0094 $sql = " 0095 SELECT 0096 *,convert(cast(convert(description using latin1) as binary) using utf8) as description_utf8,from_unixtime(created) as created_at,from_unixtime(changed) as changed_at, CASE WHEN deletedat > 0 THEN FROM_UNIXTIME(deletedat) ELSE null END as deleted_at 0097 FROM 0098 hive_content 0099 WHERE 0100 type = ? 0101 AND is_imported = 0 0102 "; 0103 if(!$alsoDeleted) { 0104 $sql .= " 0105 AND deletedat = 0 0106 AND status = 1"; 0107 } 0108 $sql .= " 0109 LIMIT ".$limit." OFFSET ".$startIndex." 0110 "; 0111 0112 $sql = $this->_db->quoteInto($sql, $category_id, 'INTEGER'); 0113 0114 $result = $this->_db->fetchAll($sql); 0115 0116 return $result; 0117 0118 } 0119 0120 /** 0121 * @param int $category_id 0122 * @return Num of rows 0123 **/ 0124 public function fetchCountPlingProjectsForCategory($category_id) 0125 { 0126 0127 $sql = " 0128 SELECT 0129 count(1) AS 'count' 0130 FROM 0131 project p 0132 JOIN hive_content h ON 0133 WHERE 0134 type = ? 0135 AND is_imported = 0 0136 GROUP BY project_category_id 0137 "; 0138 0139 $sql = $this->_db->quoteInto($sql, $category_id, 'INTEGER'); 0140 0141 $result = $this->_db->fetchRow($sql); 0142 0143 return $result['count']; 0144 0145 } 0146 0147 /** 0148 * @return Num of rows 0149 **/ 0150 public function fetchCountProjects() 0151 { 0152 0153 $sql = " 0154 SELECT 0155 count(1) AS 'count' 0156 FROM 0157 hive_content 0158 WHERE 0159 is_imported = 0 0160 "; 0161 0162 $result = $this->_db->fetchRow($sql); 0163 0164 return $result['count']; 0165 0166 } 0167 0168 /** 0169 * @return array 0170 */ 0171 public function fetchOcsCategories() 0172 { 0173 $resultSet = $this->queryPlingCategories(); 0174 return $resultSet; 0175 } 0176 0177 /** 0178 * @return array 0179 */ 0180 public function fetchHiveCategories($cat_ids) 0181 { 0182 $resultSet = $this->queryCategories($cat_ids); 0183 return $resultSet; 0184 } 0185 0186 /** 0187 * @return array 0188 */ 0189 public function fetchHiveCategory($cat_id) 0190 { 0191 $result = $this->queryCategory($cat_id); 0192 return $result; 0193 } 0194 0195 /** 0196 * @return array 0197 */ 0198 private function queryCategory($id) 0199 { 0200 $sql = "SELECT id, `desc` FROM hive_content_category WHERE id = ".$id." ORDER BY `desc`;"; 0201 $resultSet = $this->_db->fetchRow($sql); 0202 return $resultSet; 0203 } 0204 0205 /** 0206 * @return array 0207 */ 0208 public function fetchOcsCategory($cat_id) 0209 { 0210 $result = $this->queryPlingCategory($cat_id); 0211 return $result; 0212 } 0213 0214 public function fetchOcsCategoryForHiveCategory($cat_id) { 0215 $sql = "SELECT pling_cat_id FROM hive_content_category WHERE id = ".$cat_id.";"; 0216 $resultSet = $this->_db->fetchRow($sql); 0217 return $resultSet['pling_cat_id']; 0218 } 0219 0220 /** 0221 * @return array 0222 */ 0223 private function queryPlingCategory($id) 0224 { 0225 $sql = "SELECT project_category_id as id, `title` as `desc` FROM project_category WHERE is_deleted = 0 AND is_active = 1 AND project_category_id = ".$id." ORDER BY `title`;"; 0226 $resultSet = $this->_db->fetchRow($sql); 0227 return $resultSet; 0228 } 0229 0230 /** 0231 * @return array 0232 */ 0233 private function queryPlingCategories() 0234 { 0235 $sql = "SELECT project_category_id as id, `title` as `desc` FROM project_category WHERE is_deleted = 0 AND is_active = 1 ORDER BY `title`;"; 0236 $resultSet = $this->_db->fetchAll($sql); 0237 return $resultSet; 0238 } 0239 0240 /** 0241 * @return array 0242 */ 0243 private function queryCategories($cat_ids) 0244 { 0245 $sql = "SELECT id, `desc`, pling_cat_id FROM hive_content_category WHERE id in (".$cat_ids.") ORDER BY `desc`;"; 0246 $resultSet = $this->_db->fetchAll($sql); 0247 return $resultSet; 0248 } 0249 0250 0251 0252 /** 0253 * @param array $resultSetConfig 0254 * @return array 0255 */ 0256 private function createCategoriesArray($resultSetConfig) 0257 { 0258 $result = array(); 0259 foreach ($resultSetConfig as $element) { 0260 $result[$element['id']] = $element['desc']; 0261 } 0262 return $result; 0263 } 0264 0265 }