File indexing completed on 2024-05-12 05:58:47
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Default_Model_ProjectClone extends Default_Model_DbTable_ProjectClone 0024 { 0025 public function fetchOrigins($project_id) 0026 { 0027 $sql = " 0028 SELECT 0029 c.project_id as project_id_clone 0030 ,c.project_id_parent as project_id 0031 ,c.external_link 0032 ,c.member_id 0033 ,c.text 0034 ,' ' as catTitle 0035 ,p.project_category_id 0036 ,p.title 0037 ,p.image_small 0038 ,p.changed_at 0039 FROM project_clone c 0040 JOIN project p ON p.project_id = c.project_id_parent 0041 WHERE c.is_deleted = 0 and c.is_valid = 1 and c.project_id = :project_id 0042 AND p.`status` = 100 0043 order by c.created_at desc 0044 "; 0045 $resultSet = $this->_db->fetchAll($sql, array('project_id' => $project_id)); 0046 return $this->generateRowSet($resultSet); 0047 // return $resultSet; 0048 } 0049 0050 public function fetchClones($project_id) 0051 { 0052 $sql = " 0053 SELECT 0054 c.project_id as project_id 0055 ,c.project_id_parent as project_id_origin 0056 ,c.external_link 0057 ,c.member_id 0058 ,c.text 0059 ,' ' as catTitle 0060 ,(select project_category_id from project p where p.project_id = c.project_id_parent) project_category_id 0061 ,p.title 0062 ,p.image_small 0063 ,p.changed_at 0064 FROM project_clone c 0065 JOIN project p ON p.project_id = c.project_id 0066 WHERE c.is_deleted = 0 and c.is_valid = 1 and c.project_id_parent = :project_id 0067 AND p.`status` = 100 0068 order by c.created_at desc 0069 "; 0070 $resultSet = $this->_db->fetchAll($sql, array('project_id' => $project_id)); 0071 return $this->generateRowSet($resultSet); 0072 // return $resultSet; 0073 } 0074 0075 public function fetchParent($project_id) 0076 { 0077 $sql = " 0078 SELECT 0079 * 0080 FROM project_clone c 0081 WHERE c.is_deleted = 0 and c.is_valid = 1 and c.project_id = :project_id 0082 "; 0083 $resultSet = $this->_db->fetchRow($sql, array('project_id' => $project_id)); 0084 return $this->generateRowSet($resultSet); 0085 } 0086 0087 public function fetchRelatedProducts($project_id) 0088 { 0089 $sql = " 0090 select distinct * from 0091 ( 0092 SELECT 0093 c.project_id as project_id 0094 0095 ,c.external_link 0096 ,c.member_id 0097 ,c.text 0098 ,' ' as catTitle 0099 ,(select project_category_id from project p where p.project_id = c.project_id_parent) project_category_id 0100 ,p.title 0101 ,p.image_small 0102 ,p.changed_at 0103 FROM project_clone c 0104 JOIN project p on p.project_id = c.project_id 0105 WHERE c.is_deleted = 0 and c.is_valid = 1 and c.project_id_parent = :project_id 0106 AND p.`status` = 100 0107 0108 union 0109 0110 SELECT 0111 c.project_id as project_id 0112 0113 ,c.external_link 0114 ,c.member_id 0115 ,c.text 0116 ,' ' as catTitle 0117 ,(select project_category_id from project p where p.project_id = c.project_id_parent) project_category_id 0118 ,p.title 0119 ,p.image_small 0120 ,p.changed_at 0121 FROM project_clone c 0122 JOIN project p on p.project_id = c.project_id 0123 WHERE c.project_id<> :project_id and c.is_deleted = 0 and c.is_valid = 1 AND p.`status` = 100 and c.project_id_parent in ( 0124 select project_id_parent from project_clone c 0125 where c.project_id = :project_id and c.is_valid = 1 and c.is_deleted = 0 0126 ) 0127 ) a 0128 where a.catTitle is not null 0129 order by changed_at desc 0130 "; 0131 $resultSet = $this->_db->fetchAll($sql, array('project_id' => $project_id)); 0132 return $this->generateRowSet($resultSet); 0133 } 0134 0135 public function fetchMods() 0136 { 0137 $sql = " 0138 0139 SELECT 0140 c.project_clone_id 0141 ,c.project_id 0142 ,c.project_id_parent 0143 ,c.external_link 0144 ,c.text 0145 ,c.member_id as reported_by 0146 ,m.username as reporter_username 0147 ,m.profile_image_url as reporter_profile_image_url 0148 ,p.cat_title catTitle 0149 ,p.title 0150 ,p.image_small 0151 ,p.changed_at 0152 ,p.laplace_score 0153 ,p.member_id 0154 ,p.username 0155 0156 FROM project_clone c 0157 join member m on m.member_id = c.member_id 0158 JOIN stat_projects p on p.project_id = c.project_id 0159 WHERE c.is_deleted = 0 and c.is_valid = 0 and c.project_clone_type=1 0160 order by c.created_at desc 0161 0162 "; 0163 0164 $resultSet = $this->_db->fetchAll($sql); 0165 return $this->generateRowSet($resultSet); 0166 } 0167 0168 public function fetchCredits() 0169 { 0170 $sql = " 0171 0172 SELECT 0173 c.project_clone_id 0174 ,c.project_id 0175 ,c.project_id_parent 0176 ,c.external_link 0177 ,c.text 0178 ,c.member_id as reported_by 0179 ,m.username as reporter_username 0180 ,m.profile_image_url as reporter_profile_image_url 0181 ,p.cat_title catTitle 0182 ,p.title 0183 ,p.image_small 0184 ,p.changed_at 0185 ,p.laplace_score 0186 ,p.member_id 0187 ,p.username 0188 ,pp.cat_title parent_catTitle 0189 ,pp.title parent_title 0190 ,pp.image_small parent_image_small 0191 ,pp.changed_at parent_changed_at 0192 ,pp.laplace_score parent_laplace_score 0193 ,pp.member_id parent_member_id 0194 ,pp.username parent_username 0195 FROM project_clone c 0196 join stat_projects pp on pp.project_id =c.project_id_parent 0197 join member m on m.member_id = c.member_id 0198 left JOIN stat_projects p on p.project_id = c.project_id 0199 WHERE c.is_deleted = 0 and c.is_valid = 0 AND pp.status = 100 and c.project_clone_type=0 0200 order by c.created_at desc 0201 0202 "; 0203 0204 $resultSet = $this->_db->fetchAll($sql); 0205 return $this->generateRowSet($resultSet); 0206 } 0207 0208 /** 0209 * @return string comma seperated ids 0210 */ 0211 function fetchChildrensIds($project_id){ 0212 $sql = " 0213 select GROUP_CONCAT(project_id) as ids from project_clone c where c.project_id_parent = :project_id and is_valid=1 0214 "; 0215 $resultSet = $this->_db->fetchRow($sql, array('project_id' => $project_id)); 0216 return $resultSet['ids']; 0217 } 0218 0219 /** 0220 * @return string comma seperated ids 0221 */ 0222 function fetchChildrensChildrenIds($ids){ 0223 $sql = " 0224 select GROUP_CONCAT(project_id) as ids from project_clone c where c.project_id_parent in (".$ids.") and is_valid=1 0225 "; 0226 $resultSet = $this->_db->fetchRow($sql); 0227 return $resultSet['ids']; 0228 } 0229 0230 /** 0231 * @return string comma seperated ids 0232 */ 0233 function fetchParentIds($project_id){ 0234 $sql = " 0235 select GROUP_CONCAT(distinct project_id_parent) as ids from project_clone c where c.project_id = :project_id and c.is_valid=1 and c.is_deleted=0 0236 and c.project_id_parent >0 0237 "; 0238 $resultSet = $this->_db->fetchRow($sql, array('project_id' => $project_id)); 0239 return $resultSet['ids']; 0240 } 0241 0242 /** 0243 * @return string siblings project ids without itself 0244 */ 0245 function fetchSiblings($project_id){ 0246 $sql = " 0247 select GROUP_CONCAT(distinct project_id) as ids from project_clone c where c.project_id_parent in ( 0248 select project_id_parent from project_clone c where c.project_id = :project_id and c.is_valid=1 0249 ) and c.project_id <> :project_id and c.is_valid=1 0250 "; 0251 $resultSet = $this->_db->fetchRow($sql, array('project_id' => $project_id)); 0252 return $resultSet['ids']; 0253 } 0254 0255 /** 0256 * @return string comma seperated ids 0257 */ 0258 function fetchAncestersIds($project_id,$level=5){ 0259 0260 $parentIds = self::fetchParentIds($project_id); 0261 $ids=''; 0262 while ($level>0 && strlen($parentIds)>0) { 0263 $sql = "select GROUP_CONCAT(distinct project_id_parent) as ids from project_clone c where c.project_id in(".$parentIds.") and c.is_valid=1 and c.project_id_parent>0"; 0264 $resultSet = $this->_db->fetchRow($sql); 0265 if($resultSet['ids']) 0266 { 0267 $ids.=','.$resultSet['ids']; 0268 } 0269 else{ 0270 break; 0271 } 0272 $parentIds = $resultSet['ids']; 0273 $level--; 0274 } 0275 if(substr($ids, 0, 1)==','){ $ids=substr($ids,1);}; 0276 return $ids; 0277 } 0278 0279 function fetchParentLevelRelatives($project_id){ 0280 $ancesters = self::fetchAncestersIds($project_id); 0281 $sql = " 0282 select GROUP_CONCAT(project_id) as ids from project_clone c where c.project_id_parent in (".$ancesters.") and is_valid=1 0283 "; 0284 $resultSet = $this->_db->fetchRow($sql); 0285 return $resultSet['ids']; 0286 } 0287 function fetchSiblingsLevelRelatives($parentids,$project_id){ 0288 $sql = " 0289 select GROUP_CONCAT(project_id) as ids from project_clone c where c.project_id_parent in (".$parentids.") and is_valid=1 0290 and c.project_id <> :project_id 0291 "; 0292 $resultSet = $this->_db->fetchRow($sql,array('project_id' =>$project_id)); 0293 return $resultSet['ids']; 0294 } 0295 0296 function fetchParentsLevel($ids) 0297 { 0298 $sql = "select GROUP_CONCAT(distinct project_id_parent) as ids from project_clone c where c.project_id in(".$ids.") and c.is_valid=1 and c.project_id_parent>0 and c.is_deleted=0"; 0299 $resultSet = $this->_db->fetchRow($sql); 0300 return $resultSet['ids']; 0301 } 0302 function fetchChildrensLevel($ids) 0303 { 0304 $sql = "select GROUP_CONCAT(distinct project_id) as ids from project_clone c where c.project_id_parent in(".$ids.") and c.is_valid=1 and c.project_id_parent>0 and c.is_deleted=0"; 0305 $resultSet = $this->_db->fetchRow($sql); 0306 return $resultSet['ids']; 0307 } 0308 }