File indexing completed on 2025-02-09 07:14:33
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_MemberDownloadHistory extends Zend_Db_Table_Abstract 0023 { 0024 0025 protected $_name = "member_download_history"; 0026 0027 public function countDownloads($memberId) 0028 { 0029 $select = $this->_db->select() 0030 ->from('member_download_history') 0031 ->joinUsing('member', 'member_id') 0032 ->where('member.is_deleted = ?', 0) 0033 ->where('member_download_history.member_id = ?', $memberId); 0034 return count($select->query()->fetchAll()); 0035 } 0036 0037 public function countDownloadsAnonymous($cookie) 0038 { 0039 $sql = "select count(1) as cnt from member_download_history where anonymous_cookie=:cookie"; 0040 $result = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql, array('cookie'=>$cookie)); 0041 return (int)$result['cnt']; 0042 } 0043 0044 public function getAnonymousDLSection($cookie, $member_id=null) 0045 { 0046 $sql_filter = ''; 0047 if($member_id) 0048 { 0049 $sql_filter = " and h.member_id =".$member_id; 0050 }else 0051 { 0052 $sql_filter = " and h.anonymous_cookie ='".$cookie."'"; 0053 } 0054 $sql = "select c.section_id,count(1) as dls 0055 from member_download_history h , project p, section_category s, section c 0056 where h.project_id = p.project_id 0057 and s.section_id = c.section_id 0058 and p.project_category_id = s.project_category_id 0059 ".$sql_filter." 0060 group by c.section_id"; 0061 $result = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); 0062 0063 0064 $sm = new Default_Model_Section(); 0065 $sections = $sm->fetchAllSections(); 0066 foreach ($sections as &$s) { 0067 $o = null; 0068 foreach ($result as $r ) { 0069 if($r['section_id'] == $s['section_id']){ 0070 $o = $r; 0071 break; 0072 } 0073 } 0074 0075 if($o) { 0076 $s['dls'] = $o['dls']; 0077 }else{ 0078 $s['dls'] = 0; 0079 } 0080 } 0081 return $sections; 0082 } 0083 0084 public function getDownloadhistory($member_id){ 0085 $sql = " 0086 select 0087 m.member_id 0088 ,m.project_id 0089 ,m.file_id 0090 ,m.downloaded_timestamp 0091 ,p.project_category_id 0092 ,(select c.title from project_category c where p.project_category_id = c.project_category_id) as catTitle 0093 ,p.member_id as project_member_id 0094 ,p.title 0095 ,p.laplace_score 0096 ,p.image_small 0097 ,p.count_likes 0098 ,p.count_dislikes 0099 ,m.file_name as file_name 0100 ,m.file_type as file_type 0101 ,m.file_size as file_size 0102 from member_download_history m 0103 join stat_projects p on p.project_id = m.project_id 0104 where m.member_id = :member_id 0105 order by m.downloaded_timestamp desc 0106 limit 1000 0107 "; 0108 $result = $this->_db->fetchAll($sql, array("member_id"=>$member_id)); 0109 return new Zend_Paginator(new Zend_Paginator_Adapter_Array($result )); 0110 } 0111 }