File indexing completed on 2024-05-12 05:58:46

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_Pling extends Default_Model_DbTable_Plings
0024 {
0025 
0026     public function fetchTotalAmountSupported()
0027     {
0028         $sql = "
0029                 SELECT
0030                     sum(amount) AS total_sum
0031                 FROM
0032                     plings
0033                 WHERE
0034                     status_id = 2
0035                 ";
0036 
0037         $result = $this->_db->fetchRow($sql);
0038 
0039         return $result['total_sum'];
0040     }
0041 
0042     /**
0043      * @param $limit
0044      *
0045      * @return Zend_Db_Table_Rowset_Abstract
0046      */
0047     public function fetchRecentDonations($limit = null)
0048     {
0049         $sql = "
0050                 SELECT
0051           plings.amount,
0052           plings.create_time,
0053           project.project_id,
0054                     project.member_id AS project_owner_id,
0055           project.title,
0056           member.member_id,
0057           member.username,
0058           member.profile_image_url
0059                 FROM
0060                     project
0061              JOIN
0062                     plings ON (project.project_id = plings.project_id AND plings.status_id = 2)
0063                        JOIN
0064                     member ON plings.member_id = member.member_id
0065         ORDER BY plings.create_time DESC
0066                 ";
0067 
0068         if (null != $limit) {
0069             $sql .= $this->_db->quoteInto(" limit ?", $limit, 'INTEGER');
0070         }
0071 
0072         $result = $this->_db->fetchAll($sql);
0073 
0074         return $this->generateRowSet($result);
0075     }
0076 
0077     /**
0078      * @param $data
0079      *
0080      * @return Zend_Db_Table_Rowset_Abstract
0081      */
0082     protected function generateRowSet($data)
0083     {
0084         $classRowSet = $this->getRowsetClass();
0085 
0086         $returnRowSet = new $classRowSet(array(
0087             'table'    => $this,
0088             'rowClass' => $this->getRowClass(),
0089             'stored'   => true,
0090             'data'     => $data
0091         ));
0092 
0093         return $returnRowSet;
0094     }
0095 
0096     /**
0097      * @param int $member_id
0098      *
0099      * @return Zend_Db_Table_Rowset_Abstract
0100      */
0101     public function fetchRecentDonationsForUser($member_id)
0102     {
0103         $sql = "
0104                 SELECT
0105                     project.member_id AS owner_id,
0106                     sum(plings.amount) AS 'amount',
0107                     count(1) AS 'count',
0108                     year(`pling_time`) AS 'year',
0109                     month(`pling_time`) AS 'month'
0110                 FROM
0111                     plings
0112                         JOIN
0113                     project ON plings.project_id = project.project_id
0114                 WHERE
0115                     project.member_id = ?
0116                         AND plings.status_id = 2
0117                 GROUP BY project.member_id , month(`pling_time`) , year(`pling_time`)
0118                 ORDER BY pling_time DESC
0119                ";
0120 
0121         $sql = $this->_db->quoteInto($sql, $member_id, 'INTEGER');
0122 
0123         $result = $this->_db->fetchAll($sql);
0124 
0125         return $this->generateRowSet($result);
0126     }
0127 
0128     public function setAllPlingsForUserDeleted($member_id)
0129     {
0130         $sql = '
0131                 UPDATE plings
0132                 SET status_id = 99
0133                 WHERE member_id = :member_id
0134                 ;';
0135 
0136         $this->_db->query($sql, array('member_id' => $member_id))->execute();
0137     }
0138 
0139     public function setAllPlingsForUserActivated($member_id)
0140     {
0141         $sql = '
0142                 UPDATE plings
0143                 SET status_id = 99
0144                 WHERE member_id = :member_id
0145                 ;';
0146 
0147         $this->_db->query($sql, array('member_id' => $member_id))->execute();
0148     }
0149 
0150 }