File indexing completed on 2025-05-04 05:29:13
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_ProjectTagRatings 0024 { 0025 0026 /** 0027 * @param $project_id 0028 */ 0029 public function getProjectTagRatings($project_id) 0030 { 0031 $sql = " 0032 SELECT 0033 r.tag_id, 0034 r.vote, 0035 r.member_id, 0036 r.tag_rating_id, 0037 r.comment_id, 0038 comments.comment_text 0039 FROM stat_projects p 0040 inner join project_category g on p.project_category_id = g.project_category_id 0041 inner join tag_group_item i on i.tag_group_id = g.tag_rating 0042 inner join tag_rating r on r.tag_id = i.tag_id and r.project_id = p.project_id and r.is_deleted=0 0043 inner join tag t on t.tag_id = r.tag_id 0044 inner join comments on comments.comment_id = r.comment_id 0045 where p.project_id = :project_id 0046 order by r.tag_rating_id desc 0047 "; 0048 $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('project_id' => $project_id))->fetchAll(); 0049 return $result; 0050 } 0051 0052 public function getCategoryTagRatings($category_id) 0053 { 0054 $sql ="SELECT 0055 t.tag_id as id, 0056 t.tag_fullname as name, 0057 tg.group_display_name 0058 FROM project_category g 0059 inner join tag_group_item i on i.tag_group_id = g.tag_rating 0060 inner join tag t on t.tag_id = i.tag_id 0061 inner join tag_group tg on g.tag_rating = tg.group_id 0062 where g.project_category_id =:category_id 0063 order by t.tag_fullname 0064 "; 0065 $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('category_id' => $category_id))->fetchAll(); 0066 return $result; 0067 } 0068 0069 /** 0070 * @return tag_rating_id,vote/false 0071 */ 0072 public function checkIfVote($member_id,$project_id,$tag_id) 0073 { 0074 $sql = "select tag_rating_id,vote from tag_rating where member_id=:member_id and project_id=:project_id and tag_id=:tag_id 0075 and is_deleted=0"; 0076 $result = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql,array("member_id"=>$member_id 0077 ,"project_id"=>$project_id 0078 ,"tag_id" =>$tag_id 0079 )); 0080 return $result; 0081 if($result && $result['tag_rating_id']) 0082 { 0083 return $result; 0084 }else{ 0085 return false; 0086 } 0087 } 0088 0089 public function doVote($member_id,$project_id,$tag_id,$vote,$msg) 0090 { 0091 $data = array(); 0092 $data['comment_target_id'] =$project_id; 0093 $data['comment_member_id'] =$member_id; 0094 $data['comment_parent_id'] = 0; 0095 $data['comment_text'] = $msg; 0096 $commentmodel = new Default_Model_ProjectComments(); 0097 $result = $commentmodel->save($data); 0098 $comment_id = $result->comment_id; 0099 0100 Zend_Db_Table::getDefaultAdapter()->insert('tag_rating' 0101 ,array('member_id' => $member_id 0102 ,'project_id' => $project_id 0103 ,'tag_id' => $tag_id 0104 ,'vote' => $vote 0105 ,'comment_id' => $comment_id 0106 )); 0107 0108 $this->sendNotificationToOwner($project_id, $msg,40); 0109 0110 } 0111 0112 public function removeVote($tag_rating_id) 0113 { 0114 $sql ="update tag_rating set is_deleted=1, deleted_at=now() where tag_rating_id=".$tag_rating_id; 0115 Zend_Db_Table::getDefaultAdapter()->query($sql); 0116 0117 $sql = "select comment_id from tag_rating where tag_rating_id=:tag_rating_id "; 0118 $result = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql,array("tag_rating_id"=>$tag_rating_id)); 0119 if($result && $result['comment_id']) 0120 { 0121 $modelComments = new Default_Model_ProjectComments(); 0122 $modelComments->deactiveComment($result['comment_id']); 0123 } 0124 } 0125 0126 0127 /** 0128 * @param Zend_Db_Table_Row_Abstract $product 0129 * @param string $comment 0130 */ 0131 private function sendNotificationToOwner($project_id, $comment,$comment_type=null) 0132 { 0133 $auth = Zend_Auth::getInstance(); 0134 if ($auth->hasIdentity()) { 0135 $this->_authMember = $auth->getStorage()->read(); 0136 }else{ 0137 return; 0138 } 0139 $tableProject = new Default_Model_Project(); 0140 $product = $tableProject->fetchProductInfo($project_id); 0141 //Don't send email notification for comments from product owner 0142 if ($this->_authMember->member_id == $product->member_id) { 0143 return; 0144 } 0145 0146 $productData = new stdClass(); 0147 $productData->mail = $product->mail; 0148 $productData->username = $product->username; 0149 $productData->username_sender = $this->_authMember->username; 0150 $productData->title = $product->title; 0151 $productData->project_id = $product->project_id; 0152 0153 $queue = Local_Queue_Factory::getQueue(); 0154 if(!empty($comment_type)&& $comment_type=='30') 0155 { 0156 $command = new Backend_Commands_SendCommentNotification('tpl_user_comment_note_'.$comment_type, $productData, $comment); 0157 }else 0158 { 0159 $command = new Backend_Commands_SendCommentNotification('tpl_user_comment_note', $productData, $comment); 0160 } 0161 $queue->send(serialize($command)); 0162 } 0163 0164 0165 }