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_SectionSupport extends Default_Model_DbTable_SectionSupport
0024 {
0025 
0026      public function fetchAffiliatesForProject($project_id)
0027     {            
0028             
0029         $sql = "
0030                     SELECT 
0031                     f.project_id
0032                     ,m.member_id
0033                     ,s.active_time
0034                     ,m.profile_image_url
0035                     ,m.created_at as member_created_at
0036                     ,m.username
0037                     FROM section_support_paypements p
0038                     INNER JOIN section_support f ON f.section_support_id = p.section_support_id
0039                     INNER JOIN support s ON s.id = f.support_id
0040                     inner join member m on s.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0041                     WHERE  f.project_id = :project_id 
0042                     AND p.yearmonth = date_format((now()),'%Y%m')
0043                     order by s.active_time desc
0044          ";
0045         $resultSet = $this->_db->fetchAll($sql, array('project_id' => $project_id));
0046         return $resultSet;     
0047     }
0048     
0049     
0050     public function isMemberAffiliateForProject($project_id, $member_id)
0051     {            
0052             
0053         $cacheName = __FUNCTION__ . md5(serialize($project_id) .''. serialize($member_id));
0054         $cache = Zend_Registry::get('cache');
0055 
0056         $result = $cache->load($cacheName);
0057 
0058         if ($result) {
0059             return $result;
0060         }
0061         
0062         $isAffiliate = false;
0063         
0064         $sql_object =
0065             "SELECT 1
0066                 FROM section_support_paypements p
0067                     INNER JOIN section_support f ON f.section_support_id = p.section_support_id
0068                     INNER JOIN support s ON s.id = f.support_id
0069                     inner join member m on s.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0070                 WHERE  f.project_id = :project_id 
0071                 AND p.yearmonth = date_format((now()),'%Y%m')
0072                 AND m.member_id = :member_id";
0073         $r = $this->getAdapter()->fetchRow($sql_object, array('project_id' => $project_id, 'member_id' => $member_id));
0074         if ($r) {
0075             $isAffiliate = true;
0076         }   
0077         
0078         $cache->save($isAffiliate, $cacheName);
0079         
0080         return $isAffiliate;
0081     }
0082     
0083     
0084     public function isMemberAffiliateForMember($member_id, $affiliate_member_id)
0085     {            
0086             
0087         $cacheName = __FUNCTION__ . md5(serialize($member_id) .''. serialize($affiliate_member_id));
0088         $cache = Zend_Registry::get('cache');
0089 
0090         $result = $cache->load($cacheName);
0091 
0092         if ($result) {
0093             return $result;
0094         }
0095         
0096         $isAffiliate = false;
0097         
0098         $sql_object =
0099             "SELECT 1
0100                 FROM section_support_paypements pm
0101                 INNER JOIN section_support f ON f.section_support_id = pm.section_support_id
0102                 INNER JOIN project p ON p.project_id = f.project_id
0103                 INNER JOIN support s ON s.id = f.support_id
0104                 inner join member m on s.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0105                 INNER JOIN member m2 on p.member_id = m2.member_id AND m2.is_active=1 AND m2.is_deleted=0 
0106                 WHERE  p.member_id = :member_id
0107                 AND m.member_id = :affiliate_member_id
0108                 AND pm.yearmonth = date_format((now()),'%Y%m')
0109 ";
0110         $r = $this->getAdapter()->fetchRow($sql_object, array('affiliate_member_id' => $affiliate_member_id, 'member_id' => $member_id));
0111         if ($r) {
0112             $isAffiliate = true;
0113         }   
0114         
0115         $cache->save($isAffiliate, $cacheName);
0116         
0117         return $isAffiliate;
0118     }
0119     
0120     
0121     public function wasMemberAffiliateForMember($member_id, $affiliate_member_id)
0122     {            
0123             
0124         $cacheName = __FUNCTION__ . md5(serialize($member_id) .''. serialize($affiliate_member_id));
0125         $cache = Zend_Registry::get('cache');
0126 
0127         $result = $cache->load($cacheName);
0128 
0129         if ($result) {
0130             return $result;
0131         }
0132         
0133         $isAffiliate = false;
0134         
0135         $sql_object =
0136             "SELECT 1
0137                 FROM section_support f
0138                 INNER JOIN project p ON p.project_id = f.project_id
0139                 INNER JOIN support s ON s.id = f.support_id
0140                 inner join member m on s.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0141                 INNER JOIN member m2 on p.member_id = m2.member_id AND m2.is_active=1 AND m2.is_deleted=0 
0142                 WHERE  p.member_id = :member_id
0143                 AND m.member_id = :affiliate_member_id
0144                 AND s.status_id = 99";
0145         $r = $this->getAdapter()->fetchRow($sql_object, array('affiliate_member_id' => $affiliate_member_id, 'member_id' => $member_id));
0146         if ($r) {
0147             $isAffiliate = true;
0148         }   
0149         
0150         $cache->save($isAffiliate, $cacheName);
0151         
0152         return $isAffiliate;
0153     }
0154     
0155     
0156     public function fetchAffiliatesForMember($member_id)
0157     {            
0158             
0159         $cacheName = __FUNCTION__ . md5(serialize($member_id));
0160         $cache = Zend_Registry::get('cache');
0161 
0162         $result = $cache->load($cacheName);
0163 
0164         if ($result) {
0165             return $result;
0166         }
0167         
0168         $isAffiliate = false;
0169         
0170         $sql_object =
0171             "SELECT DISTINCT 
0172                     p.member_id
0173                     ,s.active_time
0174                     ,m.profile_image_url
0175                     ,m.created_at as member_created_at
0176                     ,m.username
0177                     FROM section_support f
0178                     INNER JOIN support s ON s.id = f.support_id
0179                     INNER JOIN project p ON p.project_id = f.project_id
0180                     inner join member m on s.member_id = m.member_id and m.is_active=1 AND m.is_deleted=0 
0181                     WHERE  p.member_id = :member_id 
0182                     AND s.status_id = 2
0183                     order by s.active_time DESC";
0184         $r = $this->getAdapter()->fetchAll($sql_object, array('member_id' => $member_id));
0185         $cache->save($r, $cacheName);
0186         
0187         return $r;
0188     }
0189 }