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

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 Backend_ReportProductsController extends Local_Controller_Action_Backend
0024 {
0025 
0026     const RESULT_OK = "OK";
0027     const RESULT_ERROR = "ERROR";
0028 
0029     /** @var Default_Model_DbTable_ReportProducts */
0030     protected $_model;
0031 
0032     protected $_modelName = 'Default_Model_DbTable_ReportProducts';
0033     
0034     /**
0035      *
0036      */
0037     public function init()
0038     {
0039         $this->_model = new $this->_modelName();
0040 
0041         $this->view->pageTitle = 'Manage Reported Products';
0042 
0043         parent::init();
0044         
0045     }
0046 
0047     public function indexAction()
0048     {
0049 
0050     }
0051 
0052     public function createAction()
0053     {
0054         //        $jTableResult = array();
0055         //        try {
0056         //            $newRow = $this->_model->createRow($this->getAllParams());
0057         //            $result = $newRow->save();
0058         //
0059         //            $jTableResult['Result'] = self::RESULT_OK;
0060         //            $jTableResult['Record'] = $newRow->toArray();
0061         //        } catch (Exception $e) {
0062         //            Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0063         //            $translate = Zend_Registry::get('Zend_Translate');
0064         //            $jTableResult['Result'] = self::RESULT_ERROR;
0065         //            $jTableResult['Message'] = $translate->_('Error while processing data.');
0066         //        }
0067         //
0068         //        $this->_helper->json($jTableResult);
0069     }
0070 
0071     public function updateAction()
0072     {
0073         $jTableResult = array();
0074         try {
0075             $record = $this->_model->save($this->getAllParams());
0076 
0077             $jTableResult = array();
0078             $jTableResult['Result'] = self::RESULT_OK;
0079             $jTableResult['Record'] = $record->toArray();
0080         } catch (Exception $e) {
0081             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0082             $translate = Zend_Registry::get('Zend_Translate');
0083             $jTableResult['Result'] = self::RESULT_ERROR;
0084             $jTableResult['Message'] = $translate->_('Error while processing data.');
0085         }
0086 
0087         $this->_helper->json($jTableResult);
0088     }
0089 
0090     public function deleteAction()
0091     {
0092         $reportId = (int)$this->getParam('report_id', null);
0093 
0094         $this->_model->setDelete($reportId);
0095 
0096         $jTableResult = array();
0097         $jTableResult['Result'] = self::RESULT_OK;
0098 
0099         $this->_helper->json($jTableResult);
0100     }
0101 
0102     public function deletereportsAction()
0103     {
0104         $projectId = (int)$this->getParam('p', null);
0105 
0106         $dataModel = new Backend_Model_Reports();
0107 
0108         $result = $dataModel->setDelete($projectId);
0109 
0110         $jTableResult = array();
0111         $jTableResult['Result'] = self::RESULT_OK;
0112 
0113         $this->_helper->json($jTableResult);
0114     }
0115 
0116     public function nospamAction()
0117     {
0118         $projectId = (int)$this->getParam('p', null);
0119 
0120         $dataModel = new Backend_Model_Reports();
0121 
0122         $result = $dataModel->setDelete($projectId);
0123 
0124         $modelProducts = new Default_Model_DbTable_Project();
0125         $modelProducts->setSpamChecked($projectId, Default_Model_DbTable_Project::PROJECT_SPAM_CHECKED);
0126 
0127         $jTableResult = array();
0128         $jTableResult['Result'] = self::RESULT_OK;
0129 
0130         $this->_helper->json($jTableResult);
0131     }
0132     
0133     public function validatereportAction()
0134     {
0135         $reportId = (int)$this->getParam('r', null);
0136 
0137         $dataModel = new Backend_Model_Reports();
0138 
0139         $result = $dataModel->setReportAsValid($reportId);
0140 
0141         $jTableResult = array();
0142         $jTableResult['Result'] = self::RESULT_OK;
0143 
0144         $this->_helper->json($jTableResult);
0145     }
0146     
0147     public function deletereportAction()
0148     {
0149         $reportId = (int)$this->getParam('r', null);
0150 
0151         $dataModel = new Backend_Model_Reports();
0152 
0153         $result = $dataModel->setReportAsDeleted($reportId);
0154 
0155         $jTableResult = array();
0156         $jTableResult['Result'] = self::RESULT_OK;
0157 
0158         $this->_helper->json($jTableResult);
0159     }
0160     
0161     
0162     public function validatemisuseAction()
0163     {
0164         
0165         $projectId = (int)$this->getParam('p', null);
0166         $dataModel = new Backend_Model_Reports();
0167         $result = $dataModel->setDelete($projectId);
0168         
0169         $result = $dataModel->saveNewFraud($projectId, $this->_authMember);
0170 
0171         $jTableResult = array();
0172         $jTableResult['Result'] = self::RESULT_OK;
0173 
0174         $this->_helper->json($jTableResult);
0175     }
0176 
0177     public function listAction()
0178     {
0179         $startIndex = (int)$this->getParam('jtStartIndex');
0180         $pageSize = (int)$this->getParam('jtPageSize');
0181         $sorting = $this->getParam('jtSorting');
0182         $filterDeleted = (int)$this->getParam('filter_deleted', 0);
0183 
0184         $dataModel = new Backend_Model_Reports();
0185 
0186         $jTableResult = array();
0187         $jTableResult['Result'] = self::RESULT_OK;
0188         $jTableResult['Records'] = $dataModel->getReportsForProjects($startIndex, $pageSize, $sorting, $filterDeleted);
0189         $jTableResult['TotalRecordCount'] = $dataModel->getTotalCountForReportedProject($filterDeleted);
0190 
0191         $this->_helper->json($jTableResult);
0192     }
0193 
0194     public function statusAction()
0195     {
0196         $jTableResult = array();
0197         try {
0198             $projectId = (int)$this->getParam('c');
0199 
0200             $model = new Default_Model_DbTable_Project();
0201             $record = $model->find($projectId)->current();
0202             $record->status =
0203                 ($record->status > 40 ? Default_Model_DbTable_Project::PROJECT_FAULTY : Default_Model_DbTable_Project::PROJECT_ACTIVE);
0204             $record->save();
0205 
0206             $jTableResult = array();
0207             $jTableResult['Result'] = self::RESULT_OK;
0208             $jTableResult['Record'] = $record->toArray();
0209         } catch (Exception $e) {
0210             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0211             $translate = Zend_Registry::get('Zend_Translate');
0212             $jTableResult['Result'] = self::RESULT_ERROR;
0213             $jTableResult['Message'] = $translate->_('Error while processing data.');
0214         }
0215 
0216         $this->_helper->json($jTableResult);
0217     }
0218 
0219 }