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_MemberpaypaladdressController extends Local_Controller_Action_Backend
0024 {
0025 
0026     const RESULT_OK = "OK";
0027     const RESULT_ERROR = "ERROR";
0028     const DATA_ID_NAME = 'id';
0029 
0030     /** @var Default_Model_Member */
0031     protected $_model;
0032 
0033     protected $_modelName = 'Default_Model_DbTable_MemberPaypalAddress';
0034     protected $_pageTitle = 'Manage Paypal Addresses';
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             $values = $this->getAllParams();
0074 
0075             foreach ($values as $key => $value) {
0076                 if ($value == '') {
0077                     $values[$key] = new Zend_Db_Expr('NULL');
0078                 }
0079             }
0080 
0081             $record = $this->_model->save($values);
0082 
0083             $jTableResult = array();
0084             $jTableResult['Result'] = self::RESULT_OK;
0085             $jTableResult['Record'] = $record->toArray();
0086         } catch (Exception $e) {
0087             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0088             $translate = Zend_Registry::get('Zend_Translate');
0089             $jTableResult['Result'] = self::RESULT_ERROR;
0090             $jTableResult['Message'] = $translate->_('Error while processing data.');
0091         }
0092 
0093         $this->_helper->json($jTableResult);
0094     }
0095 
0096     public function deleteAction()
0097     {
0098         $dataId = (int)$this->getParam(self::DATA_ID_NAME, null);
0099 
0100         $this->_model->setDeleted($dataId);
0101 
0102         $jTableResult = array();
0103         $jTableResult['Result'] = self::RESULT_OK;
0104 
0105         $this->_helper->json($jTableResult);
0106     }
0107 
0108     public function listAction()
0109     {
0110         $startIndex = (int)$this->getParam('jtStartIndex');
0111         $pageSize = (int)$this->getParam('jtPageSize');
0112         $sorting = $this->getParam('jtSorting');
0113         $filter['last_payment_status'] = $this->getParam('filter_status');
0114         $filter['member_id'] = $this->getParam('filter_member_id');
0115         $filter['paypal_address'] = $this->getParam('filter_paypal_mail');
0116 
0117         $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex);
0118         $metadata = $this->_model->info(Zend_Db_Table_Abstract::METADATA);
0119 
0120         foreach ($filter as $key => $value) {
0121             if (is_array($value)) {
0122                 $list = '';
0123                 foreach ($value as $element) {
0124                     if (isset($element)) {
0125                         $list = $list . ',' . $element;
0126                     }
0127                 }
0128 
0129                 if (empty($list)) {
0130                     continue;
0131                 }
0132 
0133                 $list = substr($list, 1);
0134 
0135                 $select->where("{$key} in ({$list})");
0136 
0137                 continue;
0138             }
0139             if (false === empty($value)) {
0140                 $data_type = $metadata[$key]['DATA_TYPE'];
0141                 if (($data_type == 'varchar') OR ($data_type == 'text')) {
0142                     $select->where("{$key} like ?", '%' . $value . '%');
0143                 } else {
0144                     $select->where("{$key} = ?", $value);
0145                 }
0146             }
0147         }
0148 
0149         $reports = $this->_model->fetchAll($select);
0150 
0151         $reportsAll = $this->_model->fetchAll($select->limit(null, null)->reset('columns')
0152                                                      ->columns(array('countAll' => new Zend_Db_Expr('count(*)'))));
0153 
0154         $jTableResult = array();
0155         $jTableResult['Result'] = self::RESULT_OK;
0156         $jTableResult['Records'] = $reports->toArray();
0157         $jTableResult['TotalRecordCount'] = $reportsAll->current()->countAll;
0158 
0159         $this->_helper->json($jTableResult);
0160     }
0161 
0162 
0163 }