File indexing completed on 2025-02-09 07:14:34

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_DbTable_PploadFilesDownloaded extends Local_Model_Table
0024 {
0025     /** @var  Zend_Cache_Core */
0026     protected $cache;
0027     
0028     protected $_name = "ppload.ppload_files_downloaded_all";
0029 
0030     protected $_keyColumnsForRow = array('id');
0031 
0032     protected $_key = 'id';
0033 
0034     
0035     public function generateId()
0036     {
0037         $id = time() + mt_rand(1, 1000);
0038         while (isset($this->$id)) {
0039             $id = time() + mt_rand(1, 1000);
0040         }
0041         return $id;
0042     }
0043     
0044     public function getNewId()
0045     {
0046         $result = $this->getAdapter()->query('SELECT UUID_SHORT()')->fetch();
0047 
0048         return $result['UUID_SHORT()'];
0049     }
0050 
0051     /**
0052      * @inheritDoc
0053      */
0054     public function init()
0055     {
0056         parent::init(); // TODO: Change the autogenerated stub
0057         $this->cache = Zend_Registry::get('cache');
0058     }
0059     
0060     public function fetchCountDownloadsTodayForProject($collection_id)
0061     {
0062         if(empty($collection_id)) {
0063             return 0;
0064         }
0065         
0066         $today = (new DateTime())->modify('-1 day');
0067         $filterDownloadToday = $today->format("Y-m-d H:i:s");
0068 
0069         $sql = "    SELECT COUNT(1) AS cnt
0070                     FROM ppload.ppload_files_downloaded_all f
0071                     WHERE f.collection_id = " . $collection_id . " 
0072                     AND f.downloaded_timestamp >= '" . $filterDownloadToday . "'               
0073                    ";        
0074         $result = $this->_db->query($sql)->fetchAll();      
0075         return $result[0]['cnt'];
0076     }     
0077     
0078     
0079     public function fetchCountDownloadsForFileAllTime($collectionId, $file_id)
0080     {
0081         if(empty($file_id) || empty($collectionId)) {
0082             return 0;
0083         }
0084         
0085         $sql = "    SELECT count_dl AS cnt
0086                     FROM ppload.ppload_files_downloaded_all f
0087                     WHERE f.collection_id = " . $collectionId . " 
0088                     AND f.file_id = " . $file_id . "
0089                    ";        
0090         $result = $this->_db->query($sql)->fetchAll();      
0091         return $result[0]['cnt'];
0092     }     
0093 
0094         public function fetchCountDownloadsForFileToday($collectionId, $file_id)
0095     {
0096         if(empty($file_id) || empty($collectionId)) {
0097             return 0;
0098         }
0099         
0100         $sql = "    SELECT COUNT(1) AS cnt
0101                     FROM ppload.ppload_files_downloaded_all f
0102                     WHERE f.collection_id = " . $collectionId . " 
0103                     AND f.file_id = " . $file_id . "
0104                     AND f.downloaded_timestamp >= DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:01')  
0105                    ";        
0106         $result = $this->_db->query($sql)->fetchAll();      
0107         return $result[0]['cnt'];
0108     }     
0109     
0110 }