File indexing completed on 2025-03-09 05:22:36
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 NewproductsController 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 = 'New Products'; 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('New Products','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 if($sorting==null) 0055 { 0056 $sorting = 'cnt desc'; 0057 } 0058 $filterMonth= $this->getParam('filterMonth'); 0059 $nonwallpaper = $this->getParam('nonwallpaper'); 0060 if($filterMonth == null) 0061 { 0062 $now = new DateTime('now'); 0063 $ymd = $now->format('Y-m'); 0064 }else 0065 { 0066 $ymd = DateTime::createFromFormat('Ym', $filterMonth)->format('Y-m'); 0067 } 0068 0069 $time_begin = $ymd.'-01 00:00:00'; 0070 $time_end = $ymd.'-31 23:59:59'; 0071 0072 $sql="select 0073 p.member_id, 0074 m.username, 0075 count(1) as cnt , 0076 m.created_at, 0077 (select count(1) from stat_projects pp where pp.member_id = p.member_id and pp.status=100 and pp.created_at < :time_begin) as cntOther 0078 from stat_projects p 0079 join stat_cat_tree t on p.project_category_id = t.project_category_id 0080 join member m on p.member_id = m.member_id 0081 where p.status = 100 0082 "; 0083 0084 $lft = 0; 0085 $rgt = 0; 0086 0087 if($nonwallpaper==1) 0088 { 0089 //get wallpaper category lft rgt 0090 $tmpsql = "select lft, rgt from stat_cat_tree where project_category_id=295"; 0091 $wal = Zend_Db_Table::getDefaultAdapter()->fetchRow($tmpsql); 0092 0093 $lft = $wal['lft']; 0094 $rgt = $wal['rgt']; 0095 $sql = $sql.' and (t.lft<'.$lft.' or t.rgt>'.$rgt.') '; 0096 } 0097 0098 $sql = $sql.' and p.created_at between :time_begin and :time_end 0099 group by member_id'; 0100 0101 0102 if(isset($sorting)){ 0103 $sql = $sql.' order by '.$sorting; 0104 } 0105 0106 if (isset($pageSize)) { 0107 $sql .= ' limit ' . (int)$pageSize; 0108 } 0109 0110 if (isset($startIndex)) { 0111 $sql .= ' offset ' . (int)$startIndex; 0112 } 0113 0114 0115 0116 $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array( 'time_begin' => $time_begin, 'time_end'=>$time_end) ); 0117 0118 $sqlTotal = "select count(1) as cnt from( 0119 select 0120 p.member_id 0121 from stat_projects p 0122 join stat_cat_tree t on p.project_category_id = t.project_category_id 0123 where p.status = 100 0124 0125 "; 0126 0127 if($nonwallpaper==1) 0128 { 0129 $sqlTotal = $sqlTotal.' and (t.lft<'.$lft.' or t.rgt>'.$rgt.') '; 0130 } 0131 0132 $sqlTotal = $sqlTotal.' and p.created_at between :time_begin and :time_end 0133 group by member_id 0134 ) t '; 0135 0136 $resultTotal = Zend_Db_Table::getDefaultAdapter()->fetchRow($sqlTotal, array( 'time_begin' => $time_begin, 'time_end'=>$time_end) ); 0137 0138 $totalRecordCount = $resultTotal['cnt']; 0139 $jTableResult = array(); 0140 $jTableResult['Result'] = self::RESULT_OK; 0141 $jTableResult['Records'] = $resultSet; 0142 $jTableResult['TotalRecordCount'] = $totalRecordCount; 0143 $this->_helper->json($jTableResult); 0144 } 0145 0146 0147 0148 0149 }