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

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  * Created: 31.05.2017
0024  */
0025 class DuplicatesController extends Local_Controller_Action_DomainSwitch
0026 {
0027 
0028     /** @var Default_Model_Project */
0029     protected $_model;
0030    
0031     protected $_modelName = 'Default_Model_Project';
0032     protected $_pageTitle = 'Duplicates source_url';
0033     const RESULT_OK = "OK";
0034     const RESULT_ERROR = "ERROR";
0035     public function init()
0036     {
0037         $this->_model = new $this->_modelName();
0038         $this->view->pageTitle = $this->_pageTitle;
0039         parent::init();
0040     }
0041 
0042 
0043     public function indexAction()
0044     {
0045         $this->view->headTitle('Duplicates','SET');
0046         $this->view->page = (int)$this->getParam('page', 1);        
0047     }
0048 
0049     public function listAction()
0050     {
0051       $startIndex = (int)$this->getParam('jtStartIndex');
0052       $pageSize = (int)$this->getParam('jtPageSize');
0053         $sorting = $this->getParam('jtSorting');        
0054         $filter_source_url = $this->getParam('filter_source_url');
0055         $filter_type = $this->getParam('filter_type');
0056         
0057         if($sorting==null)
0058       {
0059         $sorting = 'cnt desc';
0060       }
0061         
0062         if($filter_type=='1' || $filter_type=='2' || $filter_type ==null)
0063         {
0064             // show duplicates
0065             $sql = "
0066             SELECT
0067             `source_url`
0068             ,count(1) AS `cnt`,
0069             GROUP_CONCAT(`p`.`project_id` ORDER BY `p`.`created_at`) `pids`
0070             FROM `stat_projects_source_url` `p`    
0071             ";
0072             if($filter_type=='2' && $filter_source_url)
0073             {
0074                 $sql.=" where source_url like '%".$filter_source_url."%'";
0075             }
0076             $sql .=" GROUP BY `source_url`
0077                 HAVING count(1)>1
0078                 ";
0079             
0080             $sqlTotal = "select count(1) as cnt from (".$sql.") as t";
0081 
0082             if (isset($sorting)) {
0083                 $sql = $sql . '  order by ' . $sorting;
0084             }
0085     
0086             if (isset($pageSize)) {
0087                 $sql .= ' limit ' . (int)$pageSize;
0088             }
0089     
0090             if (isset($startIndex)) {
0091                 $sql .= ' offset ' . (int)$startIndex;
0092             }
0093 
0094             $reports = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql);   
0095             $helperTruncate = new Default_View_Helper_Truncate();   
0096             foreach ($reports as &$r) {                    
0097                     $r['pids'] = $helperTruncate->truncate($r['pids']);
0098                 }
0099             $totalRecord = Zend_Db_Table::getDefaultAdapter()->fetchRow($sqlTotal);
0100             $totalRecordCount = $totalRecord['cnt'];
0101 
0102             $jTableResult = array();
0103             $jTableResult['Result'] = self::RESULT_OK;
0104             $jTableResult['Records'] = $reports;
0105             $jTableResult['TotalRecordCount'] = $totalRecordCount;
0106             $jTableResult['sql'] = $sql;            
0107             $this->_helper->json($jTableResult);
0108         }else if($filter_type=='3')
0109         {
0110             $sql ="
0111                 SELECT left(source_url, POSITION('".$filter_source_url."' IN source_url)) as source_url
0112                 , count(1) AS `cnt`, GROUP_CONCAT(`p`.`project_id` ORDER BY `p`.`created_at`) `pids` 
0113                 FROM `stat_projects_source_url` `p` 
0114                 where source_url like '%".$filter_source_url."%' 
0115                 GROUP BY left(source_url, POSITION('".$filter_source_url."' IN source_url))            
0116             ";
0117             
0118             $sqlTotal = "select count(1) as cnt from (".$sql.") as t";
0119 
0120             if (isset($sorting)) {
0121                 $sql = $sql . '  order by ' . $sorting;
0122             }
0123     
0124             if (isset($pageSize)) {
0125                 $sql .= ' limit ' . (int)$pageSize;
0126             }
0127     
0128             if (isset($startIndex)) {
0129                 $sql .= ' offset ' . (int)$startIndex;
0130             }
0131 
0132             $reports = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql);               
0133             $totalRecord = Zend_Db_Table::getDefaultAdapter()->fetchRow($sqlTotal);
0134             $totalRecordCount = $totalRecord['cnt'];
0135 
0136             $jTableResult = array();
0137             $jTableResult['Result'] = self::RESULT_OK;
0138             $jTableResult['Records'] = $reports;        
0139             $jTableResult['TotalRecordCount'] = $totalRecordCount;
0140             $jTableResult['sql'] = $sql;            
0141             $jTableResult['sqlTotal'] = $sqlTotal;     
0142             $this->_helper->json($jTableResult);
0143         }
0144               
0145     //     $sql = "
0146     //         SELECT
0147     //         `source_url`
0148     //         ,count(1) AS `cnt`,
0149     //         GROUP_CONCAT(`p`.`project_id` ORDER BY `p`.`created_at`) `pids`
0150     //         FROM `stat_projects_source_url` `p`    
0151     //    ";
0152 
0153     //     if($filter_source_url)
0154     //     {
0155     //         $sql.=" where source_url like '%".$filter_source_url."%'";
0156     //     }
0157 
0158     //     $sql .=" GROUP BY `source_url`
0159     //             HAVING count(1)>1
0160     //             ";
0161 
0162     //     $sqlTotal = "select count(1) as cnt from (".$sql.") as t";
0163 
0164     //     if (isset($sorting)) {
0165     //         $sql = $sql . '  order by ' . $sorting;
0166     //     }
0167 
0168     //     if (isset($pageSize)) {
0169     //         $sql .= ' limit ' . (int)$pageSize;
0170     //     }
0171 
0172     //     if (isset($startIndex)) {
0173     //         $sql .= ' offset ' . (int)$startIndex;
0174     //     }
0175      
0176     //     $reports = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql);    
0177 
0178     //     $helperTruncate = new Default_View_Helper_Truncate();   
0179     //     foreach ($reports as &$r) {                    
0180     //                 $r['pids'] = $helperTruncate->truncate($r['pids']);
0181     //             }
0182                 
0183     //     // $totalRecordCount = $mod->getTotalCountDuplicates();
0184         
0185     //     $totalRecord = Zend_Db_Table::getDefaultAdapter()->fetchRow($sqlTotal);
0186     //     $totalRecordCount = $totalRecord['cnt'];
0187         
0188     //  $jTableResult = array();
0189     //  $jTableResult['Result'] = self::RESULT_OK;
0190     //  $jTableResult['Records'] = $reports;
0191     //     $jTableResult['TotalRecordCount'] = $totalRecordCount;
0192     //     $jTableResult['sql'] = $sql;        
0193     //  $this->_helper->json($jTableResult);
0194     }
0195 
0196   
0197       
0198 
0199 }