File indexing completed on 2024-12-22 05:33:27
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_SponsorController 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_Sponsor'; 0033 0034 /** 0035 * 0036 */ 0037 public function init() 0038 { 0039 $this->_model = new $this->_modelName(); 0040 0041 $this->view->pageTitle = 'Manage Sponsors'; 0042 0043 parent::init(); 0044 } 0045 0046 public function indexAction() 0047 { 0048 0049 } 0050 0051 public function listAction() 0052 { 0053 $startIndex = (int)$this->getParam('jtStartIndex'); 0054 $pageSize = (int)$this->getParam('jtPageSize'); 0055 $sorting = $this->getParam('jtSorting'); 0056 0057 $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex); 0058 $result = $this->_model->fetchAll($select); 0059 0060 $resultAll = $this->_model->getAdapter()->fetchRow('SELECT count(*) FROM ' . $this->_model->info('name')); 0061 0062 $jTableResult = array(); 0063 $jTableResult['Result'] = self::RESULT_OK; 0064 $jTableResult['Records'] = $result->toArray(); 0065 $jTableResult['TotalRecordCount'] = array_pop($resultAll); 0066 0067 $this->_helper->json($jTableResult); 0068 } 0069 0070 public function createAction() 0071 { 0072 $jTableResult = array(); 0073 try { 0074 $newRow = $this->_model->createRow($this->getAllParams()); 0075 $newRow->save(); 0076 0077 $jTableResult['Result'] = self::RESULT_OK; 0078 $jTableResult['Record'] = $newRow->toArray(); 0079 } catch (Exception $e) { 0080 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0081 $translate = Zend_Registry::get('Zend_Translate'); 0082 $jTableResult['Result'] = self::RESULT_ERROR; 0083 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0084 } 0085 0086 $this->_helper->json($jTableResult); 0087 } 0088 0089 public function updateAction() 0090 { 0091 $jTableResult = array(); 0092 try { 0093 0094 $values = $this->getAllParams(); 0095 if (!isset($values['is_active'])) { 0096 $values['is_active'] = 0; 0097 } 0098 $record = $this->_model->save($values); 0099 //$record = $this->_model->save($this->getAllParams()); 0100 0101 $jTableResult = array(); 0102 $jTableResult['Result'] = self::RESULT_OK; 0103 $jTableResult['Record'] = $record->toArray(); 0104 } catch (Exception $e) { 0105 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0106 $translate = Zend_Registry::get('Zend_Translate'); 0107 $jTableResult['Result'] = self::RESULT_ERROR; 0108 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0109 } 0110 0111 $this->_helper->json($jTableResult); 0112 } 0113 0114 public function deleteAction() 0115 { 0116 $groupId = (int)$this->getParam('sponsor_id', null); 0117 0118 $this->_model->delete(array('sponsor_id = ?' => $groupId)); 0119 0120 $jTableResult = array(); 0121 $jTableResult['Result'] = self::RESULT_OK; 0122 0123 $this->_helper->json($jTableResult); 0124 } 0125 0126 public function allsponsorsAction() 0127 { 0128 0129 $result = true; 0130 $tagmodel = new Default_Model_DbTable_Sponsor(); 0131 try { 0132 $resultRows = $tagmodel->fetchAll(); 0133 $resultForSelect = array(); 0134 $resultForSelect[] = array('DisplayText' => '', 'Value' => null); 0135 foreach ($resultRows as $row) { 0136 $resultForSelect[] = array('DisplayText' => $row['name'].'['.$row['sponsor_id'].']', 'Value' => $row['sponsor_id']); 0137 } 0138 0139 } catch (Exception $e) { 0140 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0141 $result = false; 0142 $records = array(); 0143 } 0144 0145 $jTableResult = array(); 0146 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0147 $jTableResult['Options'] = $resultForSelect; 0148 0149 $this->_helper->json($jTableResult); 0150 } 0151 0152 }