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_SectionController extends Local_Controller_Action_Backend 0024 { 0025 0026 const RESULT_OK = "OK"; 0027 const RESULT_ERROR = "ERROR"; 0028 const DATA_ID_NAME = 'section_id'; 0029 0030 /** @var Default_Model_DbTable_ConfigStore */ 0031 protected $_model; 0032 protected $_modelName = 'Default_Model_DbTable_Section'; 0033 protected $_pageTitle = 'Manage Sections'; 0034 0035 0036 public function init() 0037 { 0038 $this->_model = new Default_Model_DbTable_Section(); 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 $allParams = $this->getAllParams(); 0055 $resultWalk = array_walk($allParams, function (&$value) { 0056 $value = strlen($value) == 0 ? null : $value; 0057 }); 0058 if (false === $resultWalk) { 0059 throw new Exception('array_walk through input parameters failed.'); 0060 } 0061 //$newRow = $this->_model->createRow($allParams); 0062 //$result = $newRow->save(); 0063 $newRow = $this->_model->save($allParams); 0064 0065 $jTableResult['Result'] = self::RESULT_OK; 0066 $jTableResult['Record'] = $newRow->toArray(); 0067 } catch (Exception $e) { 0068 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0069 $translate = Zend_Registry::get('Zend_Translate'); 0070 $jTableResult['Result'] = self::RESULT_ERROR; 0071 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0072 } 0073 0074 $this->_helper->json($jTableResult); 0075 } 0076 0077 public function updateAction() 0078 { 0079 $jTableResult = array(); 0080 try { 0081 $values = $this->getAllParams(); 0082 0083 foreach ($values as $key => $value) { 0084 if ($value == '') { 0085 $values[$key] = new Zend_Db_Expr('NULL'); 0086 } 0087 } 0088 0089 $record = $this->_model->save($values); 0090 0091 $jTableResult = array(); 0092 $jTableResult['Result'] = self::RESULT_OK; 0093 } catch (Exception $e) { 0094 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0095 $translate = Zend_Registry::get('Zend_Translate'); 0096 $jTableResult['Result'] = self::RESULT_ERROR; 0097 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0098 } 0099 0100 $this->_helper->json($jTableResult); 0101 } 0102 0103 protected function initCache($store_id) 0104 { 0105 $modelPCat = new Default_Model_ProjectCategory(); 0106 $modelPCat->fetchCategoryTreeForSection($store_id, true); 0107 0108 $this->_model->fetchAllSectionsAndCategories(true); 0109 $this->_model->fetchAllSectionsArray(true); 0110 } 0111 0112 public function deleteAction() 0113 { 0114 $dataId = (int)$this->getParam(self::DATA_ID_NAME, null); 0115 0116 $this->_model->deleteId($dataId); 0117 0118 $this->cacheClear($dataId); 0119 0120 $jTableResult = array(); 0121 $jTableResult['Result'] = self::RESULT_OK; 0122 0123 $this->_helper->json($jTableResult); 0124 } 0125 0126 protected function cacheClear($store_id) 0127 { 0128 /** @var Zend_Cache_Core $cache */ 0129 $cache = Zend_Registry::get('cache'); 0130 $cache->remove(Default_Model_ProjectCategory::CACHE_TREE_STORE . "_{$store_id}"); 0131 $cache->remove(Default_Model_DbTable_ConfigStore::CACHE_STORE_CONFIG . "_{$store_id}"); 0132 $this->_model->fetchAllSectionsAndCategories(true); 0133 $this->_model->fetchAllSectionsArray(true); 0134 } 0135 0136 public function listAction() 0137 { 0138 $startIndex = (int)$this->getParam('jtStartIndex'); 0139 $pageSize = (int)$this->getParam('jtPageSize'); 0140 $sorting = $this->getParam('jtSorting'); 0141 $filter['name'] = $this->getParam('filter_name'); 0142 $filter['category_id'] = $this->getParam('filter_category_id'); 0143 0144 $select = $this->_model->select()->from($this->_model)->order($sorting)->limit($pageSize, $startIndex)->setIntegrityCheck(false) 0145 ; 0146 0147 foreach ($filter as $key => $value) { 0148 if (false === empty($value)) { 0149 $select->where("{$key} like ?", $value); 0150 } 0151 } 0152 0153 $reports = $this->_model->fetchAll($select); 0154 0155 $select = $this->_model->select()->from($this->_model)->setIntegrityCheck(false); 0156 foreach ($filter as $key => $value) { 0157 if (false === empty($value)) { 0158 $select->where("{$key} like ?", $value); 0159 } 0160 } 0161 $reportsAll = $this->_model->fetchAll($select->limit(null, null)->reset('columns') 0162 ->columns(array('countAll' => new Zend_Db_Expr('count(*)')))); 0163 0164 $jTableResult = array(); 0165 $jTableResult['Result'] = self::RESULT_OK; 0166 $jTableResult['Records'] = $reports->toArray(); 0167 $jTableResult['TotalRecordCount'] = $reportsAll->current()->countAll; 0168 0169 $this->_helper->json($jTableResult); 0170 } 0171 0172 public function childlistAction() 0173 { 0174 $sectionId = (int)$this->getParam('SectionId'); 0175 0176 $modelSponsor = new Default_Model_Sponsor(); 0177 $resultSet = $modelSponsor->fetchSectionItems($sectionId); 0178 $numberResults = count($resultSet); 0179 0180 $jTableResult = array(); 0181 $jTableResult['Result'] = self::RESULT_OK; 0182 $jTableResult['Records'] = $resultSet; 0183 $jTableResult['TotalRecordCount'] = $numberResults; 0184 0185 $this->_helper->json($jTableResult); 0186 } 0187 0188 public function childcreateAction() 0189 { 0190 $jTableResult = array(); 0191 try { 0192 $sectionId = (int)$this->getParam('section_id'); 0193 $sponsorId = (int)$this->getParam('sponsor_id'); 0194 $percent = $this->getParam('percent_of_sponsoring'); 0195 $modelSponsor = new Default_Model_Sponsor(); 0196 $newRow = $modelSponsor->assignSponsor($sectionId, $sponsorId, $percent); 0197 0198 $jTableResult['Result'] = self::RESULT_OK; 0199 $jTableResult['Record'] = $newRow; 0200 } catch (Exception $e) { 0201 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0202 $translate = Zend_Registry::get('Zend_Translate'); 0203 $jTableResult['Result'] = self::RESULT_ERROR; 0204 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0205 } 0206 0207 $this->_helper->json($jTableResult); 0208 } 0209 0210 public function childupdateAction() 0211 { 0212 $jTableResult = array(); 0213 try { 0214 $sectionSponsorId = (int)$this->getParam('section_sponsor_id'); 0215 $sectionId = (int)$this->getParam('section_id'); 0216 $sponsorId = (int)$this->getParam('sponsor_id'); 0217 $percent = $this->getParam('percent_of_sponsoring'); 0218 0219 $modelSponsor = new Default_Model_Sponsor(); 0220 $modelSponsor->updateSectionSponsor($sectionSponsorId,$sectionId,$sponsorId,$percent); 0221 $record = $modelSponsor->fetchOneSectionItem($sectionSponsorId); 0222 0223 $jTableResult = array(); 0224 $jTableResult['Result'] = self::RESULT_OK; 0225 $jTableResult['Record'] = $record; 0226 } catch (Exception $e) { 0227 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0228 $translate = Zend_Registry::get('Zend_Translate'); 0229 $jTableResult['Result'] = self::RESULT_ERROR; 0230 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0231 } 0232 0233 $this->_helper->json($jTableResult); 0234 } 0235 0236 public function childdeleteAction() 0237 { 0238 $sectionSponsorId = (int)$this->getParam('section_sponsor_id', null); 0239 0240 $modelSponsor = new Default_Model_Sponsor(); 0241 $modelSponsor->deleteSectionSponsor($sectionSponsorId); 0242 0243 $jTableResult = array(); 0244 $jTableResult['Result'] = self::RESULT_OK; 0245 0246 $this->_helper->json($jTableResult); 0247 } 0248 0249 }