File indexing completed on 2024-12-22 05:33:26
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_CommentsController extends Local_Controller_Action_Backend 0024 { 0025 0026 const RESULT_OK = "OK"; 0027 const RESULT_ERROR = "ERROR"; 0028 const IDENTIFIER = 'comment_id'; 0029 0030 /** @var Default_Model_DbTable_Comments */ 0031 protected $_model; 0032 0033 protected $_modelName = 'Default_Model_DbTable_Comments'; 0034 0035 /** 0036 * 0037 */ 0038 public function init() 0039 { 0040 $this->_model = new $this->_modelName(); 0041 0042 $this->view->pageTitle = 'Manage Comments'; 0043 0044 parent::init(); 0045 } 0046 0047 public function indexAction() 0048 { 0049 0050 } 0051 0052 public function createAction() 0053 { 0054 0055 } 0056 0057 public function updateAction() 0058 { 0059 $jTableResult = array(); 0060 try { 0061 $record = $this->_model->save($this->getAllParams()); 0062 0063 $jTableResult = array(); 0064 $jTableResult['Result'] = self::RESULT_OK; 0065 $jTableResult['Record'] = $record->toArray(); 0066 } catch (Exception $e) { 0067 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0068 $translate = Zend_Registry::get('Zend_Translate'); 0069 $jTableResult['Result'] = self::RESULT_ERROR; 0070 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0071 } 0072 0073 $this->_helper->json($jTableResult); 0074 } 0075 0076 public function deleteAction() 0077 { 0078 $reportId = (int)$this->getParam(self::IDENTIFIER, null); 0079 0080 $this->_model->setDelete($reportId); 0081 0082 $jTableResult = array(); 0083 $jTableResult['Result'] = self::RESULT_OK; 0084 0085 $this->_helper->json($jTableResult); 0086 } 0087 0088 public function listAction() 0089 { 0090 $startIndex = (int)$this->getParam('jtStartIndex'); 0091 $pageSize = (int)$this->getParam('jtPageSize'); 0092 $sorting = $this->getParam('jtSorting'); 0093 0094 $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex); 0095 $comments = $this->_model->fetchAll($select); 0096 0097 $reportsAll = $this->_model->getAdapter()->fetchRow('SELECT count(*) FROM ' . $this->_model->info('name')); 0098 0099 $jTableResult = array(); 0100 $jTableResult['Result'] = self::RESULT_OK; 0101 $jTableResult['Records'] = $comments->toArray(); 0102 $jTableResult['TotalRecordCount'] = array_pop($reportsAll); 0103 0104 $this->_helper->json($jTableResult); 0105 } 0106 0107 function utf8_encode_recursive($array) 0108 { 0109 $result = array(); 0110 foreach ($array as $key => $value) { 0111 if (is_array($value)) { 0112 $result[$key] = $this->utf8_encode_recursive($value); 0113 } else { 0114 if (is_string($value)) { 0115 $result[$key] = utf8_encode($value); 0116 } else { 0117 $result[$key] = $value; 0118 } 0119 } 0120 } 0121 0122 return $result; 0123 } 0124 0125 public function statusAction() 0126 { 0127 $jTableResult = array(); 0128 try { 0129 $commentId = (int)$this->getParam('c'); 0130 0131 $model = new Default_Model_DbTable_Comments(); 0132 $record = $model->find($commentId)->current(); 0133 $record->comment_active = ($record->comment_active ? 0 : 1); 0134 $record->save(); 0135 0136 $jTableResult = array(); 0137 $jTableResult['Result'] = self::RESULT_OK; 0138 $jTableResult['Record'] = $record->toArray(); 0139 } catch (Exception $e) { 0140 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0141 $translate = Zend_Registry::get('Zend_Translate'); 0142 $jTableResult['Result'] = self::RESULT_ERROR; 0143 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0144 } 0145 0146 $this->_helper->json($jTableResult); 0147 } 0148 0149 }