File indexing completed on 2025-02-09 07:14:34

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_ProjectFollower extends Zend_Db_Table_Abstract
0023 {
0024 
0025     protected $_name = "project_follower";    
0026 
0027     public function countLikesHeGave($memberId)
0028     {        
0029         $sql ="
0030                 SELECT count(*) AS count 
0031                 FROM project_follower f  
0032                 inner join member m on f.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0   
0033                 inner join project p on p.project_id = f.project_id and p.status = 100 
0034                 WHERE  f.member_id =:memberId
0035         ";
0036         $resultRow = $this->_db->fetchRow($sql, array('memberId' => $memberId));
0037         return $resultRow['count'];
0038     }
0039 
0040     public function countLikesHeGot($memberId)
0041     {       
0042         $sql ="
0043                 SELECT count(*) AS count 
0044                 FROM project_follower f  
0045                 inner join member m on f.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0   
0046                 inner join project p on p.project_id = f.project_id and p.status = 100 
0047                 WHERE  p.member_id =:memberId
0048         ";
0049         $resultRow = $this->_db->fetchRow($sql, array('memberId' => $memberId));
0050         return $resultRow['count'];
0051     }
0052 
0053      public function countForProject($project_id)
0054     {
0055             $selectArr = $this->_db->fetchRow('SELECT count(*) AS count FROM project_follower f  inner join member m on f.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0   WHERE  project_id = ' . $project_id);
0056             return $selectArr ['count'];      
0057     }
0058 
0059      public function fetchLikesForMember($memberId)
0060     {            
0061              $sql = "   
0062                         SELECT 
0063                         f.project_id
0064                         ,f.member_id
0065                         ,f.created_at
0066                         ,p.member_id as project_member_id
0067                         ,m.username as project_username
0068                         ,p.project_category_id
0069                         ,p.status
0070                         ,p.title
0071                         ,p.description
0072                         ,p.image_small
0073                         ,p.created_at as project_created_at
0074                         ,p.changed_at as project_changed_at                       
0075                         ,c.title as cat_title                                               
0076                         ,pr.likes AS count_likes
0077                         ,pr.dislikes AS count_dislikes
0078                         ,IFNULL(pr.score_with_pling, 500) AS laplace_score
0079                         FROM project_follower f                        
0080                         INNER JOIN project p ON p.project_id = f.project_id 
0081                         LEFT join  stat_rating_project AS pr  ON p.project_id = pr.project_id
0082                         inner join member m on p.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0083                         inner join project_category c on p.project_category_id = c.project_category_id
0084                         WHERE (p.status = 100) AND (f.member_id = :member_id) 
0085                         order by f.created_at desc                      
0086              ";
0087 
0088             $resultSet = $this->_db->fetchAll($sql, array('member_id' => $memberId));
0089             return new Zend_Paginator(new Zend_Paginator_Adapter_Array($resultSet ));     
0090     }
0091 
0092      public function fetchLikesForProject($project_id)
0093     {            
0094             $sql = "
0095                          SELECT 
0096                         f.project_id
0097                         ,f.member_id
0098                         ,f.created_at
0099                         ,m.profile_image_url
0100                         ,m.created_at as member_created_at
0101                         ,m.username
0102                         FROM project_follower f
0103                         inner join member m on f.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0104                         WHERE  f.project_id = :project_id
0105                         order by f.created_at desc
0106              ";
0107             $resultSet = $this->_db->fetchAll($sql, array('project_id' => $project_id));
0108             return $resultSet;     
0109     }
0110 
0111 }