File indexing completed on 2024-12-22 05:33:27

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 class Backend_OperatingsystemController extends Local_Controller_Action_Backend
0024 {
0025 
0026     const RESULT_OK = "OK";
0027     const RESULT_ERROR = "ERROR";
0028     const DATA_ID_NAME = 'os_id';
0029 
0030     /** @var Default_Model_DbTable_ConfigOperatingSystem */
0031     protected $_model;
0032 
0033     protected $_modelName = 'Default_Model_DbTable_ConfigOperatingSystem';
0034     protected $_pageTitle = 'Manage Operating Systems';
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             $this->cacheClear();
0058 
0059             $jTableResult['Result'] = self::RESULT_OK;
0060             $jTableResult['Record'] = $newRow->toArray();
0061         } catch (Exception $e) {
0062             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0063             $translate = Zend_Registry::get('Zend_Translate');
0064             $jTableResult['Result'] = self::RESULT_ERROR;
0065             $jTableResult['Message'] = $translate->_('Error while processing data.');
0066         }
0067 
0068         $this->_helper->json($jTableResult);
0069     }
0070 
0071     protected function cacheClear()
0072     {
0073         /** @var Zend_Cache_Core $cache */
0074         $cache = Zend_Registry::get('cache');
0075 
0076         if ($cache->test('fetchOperatingSystems')) {
0077             $cache->remove('fetchOperatingSystems');
0078         }
0079     }
0080 
0081     public function updateAction()
0082     {
0083         $jTableResult = array();
0084         try {
0085             $values = $this->getAllParams();
0086 
0087             foreach ($values as $key => $value) {
0088                 if ($value == '') {
0089                     $values[$key] = new Zend_Db_Expr('NULL');
0090                 }
0091             }
0092 
0093             $record = $this->_model->save($values);
0094 
0095             $this->cacheClear();
0096 
0097             $jTableResult = array();
0098             $jTableResult['Result'] = self::RESULT_OK;
0099             $jTableResult['Record'] = $record->toArray();
0100         } catch (Exception $e) {
0101             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0102             $translate = Zend_Registry::get('Zend_Translate');
0103             $jTableResult['Result'] = self::RESULT_ERROR;
0104             $jTableResult['Message'] = $translate->_('Error while processing data.');
0105         }
0106 
0107         $this->_helper->json($jTableResult);
0108     }
0109 
0110     public function deleteAction()
0111     {
0112         $dataId = (int)$this->getParam(self::DATA_ID_NAME, null);
0113 
0114         $this->_model->deleteId($dataId);
0115 
0116         $this->cacheClear();
0117 
0118         $jTableResult = array();
0119         $jTableResult['Result'] = self::RESULT_OK;
0120 
0121         $this->_helper->json($jTableResult);
0122     }
0123 
0124     public function listAction()
0125     {
0126         $startIndex = (int)$this->getParam('jtStartIndex');
0127         $pageSize = (int)$this->getParam('jtPageSize');
0128         $sorting = $this->getParam('jtSorting');
0129         $filter['name'] = $this->getParam('filter_name');
0130 
0131         $select = $this->_model->select()->order($sorting)->limit($pageSize, $startIndex);
0132         foreach ($filter as $key => $value) {
0133             if (false === empty($value)) {
0134                 $select->where("{$key} like ?", $value);
0135             }
0136         }
0137 
0138         $reports = $this->_model->fetchAll($select);
0139 
0140         $reportsAll = $this->_model->fetchAll($select->limit(null, null));
0141 
0142         $jTableResult = array();
0143         $jTableResult['Result'] = self::RESULT_OK;
0144         $jTableResult['Records'] = $reports->toArray();
0145         $jTableResult['TotalRecordCount'] = $reportsAll->count();
0146 
0147         $this->_helper->json($jTableResult);
0148     }
0149 
0150     public function osNamesAction()
0151     {
0152         $result = true;
0153         $id = (int)$this->getParam('c');
0154 
0155         try {
0156             $records = $this->_model->fetchOsNamesForJTable($id);
0157         } catch (Exception $e) {
0158             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0159             $result = false;
0160             $records = array();
0161         }
0162 
0163         $jTableResult = array();
0164         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0165         $jTableResult['Options'] = $records;
0166 
0167         $this->_helper->json($jTableResult);
0168     }
0169 
0170 
0171 }