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_SectioncategoriesController extends Local_Controller_Action_Backend 0024 { 0025 const RESULT_OK = "OK"; 0026 const RESULT_ERROR = "ERROR"; 0027 0028 /** @var Default_Model_DbTable_ProjectCategory */ 0029 protected $_model; 0030 0031 protected $_authMember; 0032 0033 protected $_modelName = 'Default_Model_DbTable_ProjectCategory'; 0034 0035 0036 public function init() 0037 { 0038 parent::init(); 0039 0040 $this->_model = new $this->_modelName(); 0041 0042 $this->view->pageTitle = 'Manage Section-Categories'; 0043 $this->view->author = $this->_authMember->username; 0044 } 0045 0046 public function indexAction() 0047 { 0048 0049 } 0050 0051 public function updateAction() 0052 { 0053 0054 $jTableResult = array(); 0055 try { 0056 0057 //$this->_model->moveToParent((int)$this->getParam('project_category_id', null), (int)$this->getParam('parent', null)); 0058 //$record = $this->_model->save($this->getAllParams()); 0059 $section_id = $this->getParam('section_id', null); 0060 $tagmodel = new Default_Model_DbTable_SectionCategory(); 0061 $tagmodel->updateSectionPerCategory((int)$this->getParam('project_category_id', null), $section_id); 0062 0063 //Update also SubCategories 0064 $catmodel = new Default_Model_DbTable_ProjectCategory(); 0065 $subCats = $catmodel->fetchChildIds((int)$this->getParam('project_category_id', null), true); 0066 if($subCats) { 0067 foreach ($subCats as $cat) { 0068 $tagmodel->updateSectionPerCategory($cat, $section_id); 0069 } 0070 } 0071 0072 0073 $jTableResult = array(); 0074 $jTableResult['Result'] = self::RESULT_OK; 0075 // $jTableResult['Record'] = $record->toArray(); 0076 } catch (Exception $e) { 0077 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0078 $translate = Zend_Registry::get('Zend_Translate'); 0079 $jTableResult['Result'] = self::RESULT_ERROR; 0080 $jTableResult['Message'] = $translate->_('Error while processing data.'); 0081 } 0082 0083 $this->_helper->json($jTableResult); 0084 } 0085 0086 0087 public function listAction() 0088 { 0089 0090 $startIndex = (int)$this->getParam('jtStartIndex'); 0091 $pageSize = (int)$this->getParam('jtPageSize'); 0092 $sorting = $this->getParam('jtSorting'); 0093 $filter_deleted = (int)$this->getParam('filter_deleted', 1); 0094 0095 $records = $this->_model->fetchTreeWithParentIdAndSections($filter_deleted, null); 0096 0097 $pagination = Zend_Paginator::factory($records); 0098 $pagination->setItemCountPerPage($pageSize); 0099 $pagination->setCurrentPageNumber(($startIndex / $pageSize) + 1); 0100 0101 $jTableResult = array(); 0102 $jTableResult['Result'] = self::RESULT_OK; 0103 $jTableResult['Records'] = (array)$pagination->getCurrentItems(); 0104 $jTableResult['TotalRecordCount'] = count($records); 0105 0106 $this->_helper->json($jTableResult); 0107 } 0108 0109 0110 0111 public function treeAction() 0112 { 0113 0114 $result = true; 0115 $cat_id = (int)$this->getParam('c'); 0116 0117 try { 0118 $records = $this->_model->fetchTreeForJTableSection($cat_id); 0119 0120 0121 } catch (Exception $e) { 0122 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0123 $result = false; 0124 $records = array(); 0125 } 0126 0127 $jTableResult = array(); 0128 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0129 $jTableResult['Options'] = $records; 0130 0131 $this->_helper->json($jTableResult); 0132 } 0133 0134 0135 public function allsectionsAction() 0136 { 0137 0138 $result = true; 0139 $tagmodel = new Default_Model_DbTable_Section(); 0140 try { 0141 $resultRows = $tagmodel->fetchAll(); 0142 $resultForSelect = array(); 0143 $resultForSelect[] = array('DisplayText' => '', 'Value' => null); 0144 foreach ($resultRows as $row) { 0145 $resultForSelect[] = array('DisplayText' => $row['name'].'['.$row['section_id'].']', 'Value' => $row['section_id']); 0146 } 0147 0148 } catch (Exception $e) { 0149 Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true)); 0150 $result = false; 0151 $records = array(); 0152 } 0153 0154 $jTableResult = array(); 0155 $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR; 0156 $jTableResult['Options'] = $resultForSelect; 0157 0158 $this->_helper->json($jTableResult); 0159 } 0160 0161 0162 0163 }