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_Dwhdata 
0024 {
0025 
0026       /** @var Zend_Db_Adapter_Pdo_Abstract */
0027       protected $_db;
0028 
0029       public  function __construct()  {         
0030           $options =  Zend_Registry::get('config')->settings->dwh->toArray();
0031           if (isset($options['db'])) {
0032               $this->initDbAdapter($options['db']);
0033           } else {
0034               throw new Exception('configuration parameter for database connection needed');
0035           }
0036       }
0037 
0038       private function initDbAdapter($db)
0039       {
0040           $adapter = $db['adapter'];
0041           $params = $db['params'];
0042           unset($params['adapter'], $params['default'], $params['isDefaultTableAdapter']);
0043           $adapter = Zend_Db::factory($adapter, $params);
0044           $this->_db = $adapter;
0045       }
0046 
0047       public function getDownloadhistory($member_id){           
0048            $sql = "select 
0049                                 m.member_id
0050                                 ,m.collection_id
0051                                 ,m.project_id
0052                                 ,m.file_id
0053                                 ,m.user_id
0054                                 ,m.downloaded_timestamp
0055                                 ,m.downloaded_ip
0056                                 ,p.project_category_id
0057                                 ,(select c.title from category c where p.project_category_id = c.project_category_id) as catTitle
0058                                 ,p.title                               
0059                                 ,p.laplace_score
0060                                 ,p.image_small
0061                                 ,p.count_likes
0062                                 ,p.count_dislikes
0063                                 ,f.name as file_name
0064                                 ,f.type as file_type
0065                                 ,f.size as file_size
0066                                 ,f.ocs_compatible as file_ocs_compatible
0067                                 ,f.downloaded_count as file_downloaded_count
0068                                 ,f.active as file_active
0069                                 ,(select max(d.downloaded_timestamp) from dwh.member_dl_history d where m.project_id = d.project_id and d.user_id = m.user_id) as max_downloaded_timestamp
0070                                 from dwh.member_dl_history m
0071                                 join dwh.project p on p.project_id = m.project_id
0072                                 join dwh.files f on m.file_id = f.id
0073                                 where m.user_id = :member_id
0074                                 order by m.project_id, m.downloaded_timestamp desc
0075                         ";
0076            $result = $this->_db->fetchAll($sql, array("member_id"=>$member_id));
0077           return new Zend_Paginator(new Zend_Paginator_Adapter_Array($result ));
0078           // return $result; 
0079       }
0080 }