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_ProjectPlings extends Zend_Db_Table_Abstract
0023 {
0024 
0025     protected $_name = "project_plings";
0026 
0027 
0028     public function getPlings($project_id)
0029     {
0030         $statement = $this->select()
0031             ->where('project_id=?', $project_id)
0032             ->where('is_deleted=?', 0);
0033         return $this->fetchAll($statement);
0034     }
0035 
0036 
0037     public function getPling($project_id,$member_id)
0038     {
0039         $statement = $this->select()
0040             ->where('project_id=?', $project_id)
0041             ->where('member_id=?', $member_id)
0042             ->where('is_deleted=?', 0);
0043         return $this->fetchRow($statement);
0044     }
0045 
0046     public function setDelete($id)
0047     {
0048         /*
0049         $updateValues = array(
0050             'is_deleted' => 1,
0051             'deleted_at' => new Zend_Db_Expr('Now()')
0052         );
0053         $this->update($updateValues,  array('project_plings_id = ?' => $id));
0054     */
0055         $sql = "update project_plings set is_deleted = 1, deleted_at = now() where project_plings_id = :id";
0056 
0057         $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('id' => $id))->execute();
0058        
0059         return $result;
0060     }
0061 
0062     public function countPlingsHeGave($member_id)
0063     {        
0064         $sql ="
0065                 SELECT count(*) AS count 
0066                 FROM project_plings f   
0067                 WHERE  f.member_id =:member_id and f.is_deleted = 0 and f.is_active = 1
0068         ";
0069         $resultRow = $this->_db->fetchRow($sql, array('member_id' => $member_id));
0070         return $resultRow['count'];
0071     }
0072 
0073     public function getPlingsAmount($project_id)
0074     {
0075 
0076        $sql ="
0077                 SELECT count(*) AS count 
0078                 FROM project_plings f   
0079                 WHERE  f.project_id =:project_id and f.is_deleted = 0 and f.is_active = 1 
0080         ";
0081         $resultRow = $this->_db->fetchRow($sql, array('project_id' => $project_id));
0082         return $resultRow['count'];
0083     }
0084 
0085     public function countPlingsHeGotAll($member_id)
0086     {       
0087         $sql ="
0088                 SELECT count(*) AS count 
0089                 FROM project_plings f  
0090                 inner join stat_projects p on p.project_id = f.project_id and p.status = 100 
0091                 WHERE  p.member_id =:member_id and f.is_deleted = 0 and f.is_active = 1
0092         ";
0093         $resultRow = $this->_db->fetchRow($sql, array('member_id' => $member_id));
0094         return $resultRow['count'];
0095 
0096     }
0097 
0098     public function countPlingsHeGot($member_id)
0099     {       
0100 
0101        
0102          $sql = "
0103                     select IFNULL(sum(cntplings), 0)  AS count 
0104                     from
0105                     (
0106                         select 
0107                         p.project_id
0108                         ,(select count(1) from project_plings f where f.project_id = p.project_id and f.is_deleted = 0 and f.is_active = 1 ) cntplings
0109                         from stat_projects p where p.member_id =:member_id and p.status = 100
0110                     ) tt
0111          ";       
0112          $resultRow = $this->_db->fetchRow($sql, array('member_id' => $member_id));
0113         return $resultRow['count'];
0114     }
0115 
0116     public function getAllPlingListReceived()
0117     {
0118         $sql = "
0119             select p.member_id
0120             ,m.username
0121             ,count(1) as plings
0122             from project_plings f, project p,  member m
0123             where f.project_id = p.project_id 
0124             and p.member_id = m.member_id and f.is_deleted = 0 and f.is_active = 1
0125             group by p.member_id
0126             order by plings desc,m.username asc
0127             
0128         ";
0129         return  $this->_db->fetchAll($sql);
0130     }
0131 
0132     public function getAllPlingListGiveout()
0133     {
0134         $sql = "
0135                 select f.member_id
0136                 ,m.username
0137                 ,count(1) as plings
0138                 from project_plings f, member m
0139                 where f.member_id = m.member_id and f.is_deleted = 0 and f.is_active = 1
0140                 group by f.member_id
0141                 order by plings desc ,m.username asc    
0142         ";
0143         return  $this->_db->fetchAll($sql);
0144     }
0145 
0146 }