File indexing completed on 2024-05-12 05:58:33

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_TagsController 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_TagGroup';
0033 
0034     /**
0035      *
0036      */
0037     public function init()
0038     {
0039         $this->_model = new $this->_modelName();
0040 
0041         $this->view->pageTitle = 'Manage Tags';
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             // patch checkbox is_multi_select get no parameter when is_multi_select = 0
0096             if (!isset($values['is_multi_select'])) {
0097                 $values['is_multi_select'] = 0;
0098             }
0099             $record = $this->_model->save($values);
0100             //$record = $this->_model->save($this->getAllParams());
0101 
0102             $jTableResult = array();
0103             $jTableResult['Result'] = self::RESULT_OK;
0104             $jTableResult['Record'] = $record->toArray();
0105         } catch (Exception $e) {
0106             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0107             $translate = Zend_Registry::get('Zend_Translate');
0108             $jTableResult['Result'] = self::RESULT_ERROR;
0109             $jTableResult['Message'] = $translate->_('Error while processing data.');
0110         }
0111 
0112         $this->_helper->json($jTableResult);
0113     }
0114 
0115     public function deleteAction()
0116     {
0117         $groupId = (int)$this->getParam('group_id', null);
0118 
0119         $this->_model->delete(array('group_id = ?' => $groupId));
0120 
0121         $jTableResult = array();
0122         $jTableResult['Result'] = self::RESULT_OK;
0123 
0124         $this->_helper->json($jTableResult);
0125     }
0126 
0127     public function childlistAction()
0128     {
0129         $groupId = (int)$this->getParam('GroupId');
0130 
0131         $modelTagGroup = new Default_Model_TagGroup();
0132         $resultSet = $modelTagGroup->fetchGroupItems($groupId);
0133         $numberResults = count($resultSet);
0134 
0135         $jTableResult = array();
0136         $jTableResult['Result'] = self::RESULT_OK;
0137         $jTableResult['Records'] = $resultSet;
0138         $jTableResult['TotalRecordCount'] = $numberResults;
0139 
0140         $this->_helper->json($jTableResult);
0141     }
0142 
0143     public function childcreateAction()
0144     {
0145         $jTableResult = array();
0146         try {
0147             $groupId = (int)$this->getParam('tag_group_id');
0148             $tagName = $this->getParam('tag_name');
0149             $tagFullname = $this->getParam('tag_fullname');
0150             $tagDescription = $this->getParam('tag_description');
0151             $is_active = $this->getParam('is_active');
0152             $modelTagGroup = new Default_Model_TagGroup();
0153             $newRow = $modelTagGroup->assignGroupTag($groupId, $tagName,$tagFullname,$tagDescription,$is_active);
0154 
0155             $jTableResult['Result'] = self::RESULT_OK;
0156             $jTableResult['Record'] = $newRow;
0157         } catch (Exception $e) {
0158             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0159             $translate = Zend_Registry::get('Zend_Translate');
0160             $jTableResult['Result'] = self::RESULT_ERROR;
0161             $jTableResult['Message'] = $translate->_('Error while processing data.');
0162         }
0163 
0164         $this->_helper->json($jTableResult);
0165     }
0166 
0167     public function childupdateAction()
0168     {
0169         $jTableResult = array();
0170         try {
0171             $groupItemId = (int)$this->getParam('tag_group_item_id');
0172             //$tagId = (int)$this->getParam('tag_id');
0173             $tagName = $this->getParam('tag_name');
0174 
0175             $tagFullname = $this->getParam('tag_fullname');            
0176             $tagDescription = $this->getParam('tag_description');
0177             $is_active = $this->getParam('is_active');
0178             $modelTagGroup = new Default_Model_TagGroup();
0179             //load tag
0180             $record = $modelTagGroup->fetchOneGroupItem($groupItemId);
0181             $tagId = $record['tag_id'];
0182             
0183             $modelTagGroup->updateGroupTag($tagId, $tagName,$tagFullname,$tagDescription,$is_active);
0184             $record = $modelTagGroup->fetchOneGroupItem($groupItemId);
0185 
0186             $jTableResult = array();
0187             $jTableResult['Result'] = self::RESULT_OK;
0188             $jTableResult['Record'] = $record;
0189         } catch (Exception $e) {
0190             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0191             $translate = Zend_Registry::get('Zend_Translate');
0192             $jTableResult['Result'] = self::RESULT_ERROR;
0193             $jTableResult['Message'] = $translate->_('Error while processing data.');
0194         }
0195 
0196         $this->_helper->json($jTableResult);
0197     }
0198 
0199     public function childdeleteAction()
0200     {
0201         $groupItemId = (int)$this->getParam('tag_group_item_id', null);
0202 
0203         $modelTagGroup = new Default_Model_TagGroup();
0204         $modelTagGroup->deleteGroupTag($groupItemId);
0205 
0206         $jTableResult = array();
0207         $jTableResult['Result'] = self::RESULT_OK;
0208 
0209         $this->_helper->json($jTableResult);
0210     }
0211 
0212 }