File indexing completed on 2024-12-22 05:33:26

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 class Backend_ClaimController extends Local_Controller_Action_Backend
0024 {
0025 
0026     const RESULT_OK = "OK";
0027     const RESULT_ERROR = "ERROR";
0028     const DATA_ID_NAME = 'member_id';
0029 
0030     /** @var Default_Model_Project */
0031     protected $_model;
0032 
0033     protected $_modelName = 'Default_Model_Project';
0034     protected $_pageTitle = 'Administrate Claimed Products';
0035 
0036     public function init()
0037     {
0038         $this->_model = new $this->_modelName();
0039 
0040         $this->view->pageTitle = $this->_pageTitle;
0041 
0042         parent::init();
0043     }
0044 
0045     public function indexAction()
0046     {
0047 
0048     }
0049 
0050     public function createAction()
0051     {
0052         $jTableResult = array();
0053         try {
0054             $newRow = $this->_model->createRow($this->getAllParams());
0055             $result = $newRow->save();
0056 
0057             $jTableResult['Result'] = self::RESULT_OK;
0058             $jTableResult['Record'] = $newRow->toArray();
0059         } catch (Exception $e) {
0060             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0061             $translate = Zend_Registry::get('Zend_Translate');
0062             $jTableResult['Result'] = self::RESULT_ERROR;
0063             $jTableResult['Message'] = $translate->_('Error while processing data.');
0064         }
0065 
0066         $this->_helper->json($jTableResult);
0067     }
0068 
0069     public function updateAction()
0070     {
0071         $jTableResult = array();
0072         try {
0073             $filterInput = new Zend_Filter_Input(array(
0074                 '*'                   => 'StringTrim',
0075                 'project_id'          => 'digits',
0076                 'member_id'           => 'digits',
0077                 'project_category_id' => 'digits',
0078                 'status'              => 'digits',
0079                 'pid'                 => 'digits',
0080                 'type_id'             => 'digits',
0081                 'creator_id'          => 'digits',
0082                 'validated'           => 'digits',
0083                 'featured'            => 'digits',
0084                 'amount'              => 'digits',
0085                 'claimable'           => 'digits',
0086                 'claimed_by_member'   => 'digits',
0087             ), array('*' => array()), $this->getAllParams());
0088 
0089             $record = $this->_model->save($filterInput->getEscaped());
0090 
0091             $jTableResult = array();
0092             $jTableResult['Result'] = self::RESULT_OK;
0093             $jTableResult['Record'] = $record->toArray();
0094         } catch (Exception $e) {
0095             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0096             $translate = Zend_Registry::get('Zend_Translate');
0097             $jTableResult['Result'] = self::RESULT_ERROR;
0098             $jTableResult['Message'] = $translate->_('Error while processing data.');
0099         }
0100 
0101         $this->_helper->json($jTableResult);
0102     }
0103 
0104     public function deleteAction()
0105     {
0106         $dataId = (int)$this->getParam(self::DATA_ID_NAME, null);
0107 
0108         $this->_model->setDeleted($dataId);
0109 
0110         $jTableResult = array();
0111         $jTableResult['Result'] = self::RESULT_OK;
0112 
0113         $this->_helper->json($jTableResult);
0114     }
0115 
0116     public function listAction()
0117     {
0118         $startIndex = (int)$this->getParam('jtStartIndex');
0119         $pageSize = (int)$this->getParam('jtPageSize');
0120         $sorting = $this->getParam('jtSorting');
0121         $filter['title'] = $this->getParam('filter_title');
0122         $filter['project_id'] = $this->getParam('filter_project_id');
0123         $filter['member_id'] = $this->getParam('filter_member_id');
0124 
0125         $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex)->where('claimable = 1');
0126         foreach ($filter as $key => $value) {
0127             if (is_array($value)) {
0128                 $list = '';
0129                 foreach ($value as $element) {
0130                     if (isset($element)) {
0131                         $list = $list . ',' . $element;
0132                     }
0133                 }
0134                 $list = substr($list, 1);
0135 
0136                 $select->where("{$key} in ({$list})");
0137 
0138                 continue;
0139             }
0140             if ((false === empty($value)) AND is_numeric($value)) {
0141                 $select->where("{$key} = ?", $value);
0142             } else {
0143                 if ((false === empty($value)) AND is_string($value)) {
0144                     $select->where("{$key} like ?", '%' . $value . '%');
0145                 }
0146             }
0147         }
0148 
0149         $reports = $this->_model->fetchAll($select);
0150 
0151         $reportsAll = $this->_model->fetchAll($select->limit(null, null));
0152 
0153         $jTableResult = array();
0154         $jTableResult['Result'] = self::RESULT_OK;
0155         $jTableResult['Records'] = $reports->toArray();
0156         $jTableResult['TotalRecordCount'] = $reportsAll->count();
0157 
0158         $this->_helper->json($jTableResult);
0159     }
0160 
0161     public function removeclaimAction()
0162     {
0163         $jTableResult = array();
0164         try {
0165             $projectId = (int)$this->getParam('project_id');
0166 
0167             $record = $this->_model->find($projectId)->current();
0168             $record->claimed_by_member = new Zend_Db_Expr('NULL');
0169             $record->save();
0170 
0171             $jTableResult = array();
0172             $jTableResult['Result'] = self::RESULT_OK;
0173             $jTableResult['Record'] = $record->toArray();
0174         } catch (Exception $e) {
0175             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0176             $translate = Zend_Registry::get('Zend_Translate');
0177             $jTableResult['Result'] = self::RESULT_ERROR;
0178             $jTableResult['Message'] = $translate->_('Error while processing data.');
0179         }
0180 
0181         $this->_helper->json($jTableResult);
0182     }
0183 
0184     public function toggleclaimAction()
0185     {
0186         $jTableResult = array();
0187         try {
0188             $projectId = (int)$this->getParam('project_id');
0189 
0190             $record = $this->_model->find($projectId)->current();
0191             $record->claimable = ($record->claimable ? 0 : 1);
0192             $record->save();
0193 
0194             $jTableResult = array();
0195             $jTableResult['Result'] = self::RESULT_OK;
0196             $jTableResult['Record'] = $record->toArray();
0197         } catch (Exception $e) {
0198             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0199             $translate = Zend_Registry::get('Zend_Translate');
0200             $jTableResult['Result'] = self::RESULT_ERROR;
0201             $jTableResult['Message'] = $translate->_('Error while processing data.');
0202         }
0203 
0204         $this->_helper->json($jTableResult);
0205     }
0206 
0207     public function transferAction()
0208     {
0209         $jTableResult = array();
0210         try {
0211             $projectId = (int)$this->getParam('project_id');
0212 
0213             $this->_model->transferClaimToMember($projectId);
0214             $record = $this->_model->find($projectId)->current();
0215 
0216             $jTableResult = array();
0217             $jTableResult['Result'] = self::RESULT_OK;
0218             $jTableResult['Record'] = $record->toArray();
0219         } catch (Exception $e) {
0220             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0221             $translate = Zend_Registry::get('Zend_Translate');
0222             $jTableResult['Result'] = self::RESULT_ERROR;
0223             $jTableResult['Message'] = $translate->_('Error while processing data.');
0224         }
0225 
0226         $this->_helper->json($jTableResult);
0227     }
0228 
0229     public function fieldAction()
0230     {
0231         $jTableResult = array();
0232         try {
0233             $projectId = (int)$this->getParam('project_id');
0234             $nameField = $this->getParam('fieldname');
0235             $valueField = $this->getParam('fieldvalue');
0236 
0237             $record = $this->_model->find($projectId)->current();
0238             $record->claimable = ($record->claimable ? 0 : 1);
0239             $record->save();
0240 
0241             $jTableResult = array();
0242             $jTableResult['Result'] = self::RESULT_OK;
0243             $jTableResult['Record'] = $record->toArray();
0244         } catch (Exception $e) {
0245             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0246             $translate = Zend_Registry::get('Zend_Translate');
0247             $jTableResult['Result'] = self::RESULT_ERROR;
0248             $jTableResult['Message'] = $translate->_('Error while processing data.');
0249         }
0250 
0251         $this->_helper->json($jTableResult);
0252     }
0253 
0254     public function memberinfoAction()
0255     {
0256         $jTableResult = array();
0257         try {
0258             $memberId = (int)$this->getParam('member_id');
0259 
0260             $modelMember = new  Default_Model_Member();
0261             $record = $modelMember->find($memberId)->current();
0262             $this->view->member = $record;
0263             $view = $this->view->render('claim/member.phtml');
0264 
0265             $jTableResult = array();
0266             $jTableResult['Result'] = self::RESULT_OK;
0267             $jTableResult['Record'] = $record->toArray();
0268             $jTableResult['ViewRecord'] = $view;
0269         } catch (Exception $e) {
0270             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0271             $translate = Zend_Registry::get('Zend_Translate');
0272             $jTableResult['Result'] = self::RESULT_ERROR;
0273             $jTableResult['Message'] = $translate->_('Error while processing data.');
0274         }
0275 
0276         $this->_helper->json($jTableResult);
0277     }
0278 
0279 }