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

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_VcategoriesController 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_VCategory';
0034 
0035     public function init()
0036     {
0037         parent::init();
0038 
0039         $this->_model = new $this->_modelName();
0040 
0041         $this->view->pageTitle = 'Manage Virtual Categories';
0042         $this->view->author = $this->_authMember->username;
0043     }
0044 
0045     public function indexAction()
0046     {
0047 
0048     }
0049 
0050     public function createAction()
0051     {
0052         $jTableResult = array();
0053         try {
0054             $params = $this->getAllParams();
0055             $parent = 0;
0056 
0057             if (empty($params['v_parent_id'])) {
0058                 $params['v_parent_id'] = 0;
0059             } else {
0060                 $params['v_parent_id'] = $params['v_parent_id'];
0061             }
0062             if (!empty($params['v_category_id'])) {
0063                 $params['v_parent_id'] = $params['v_category_id'];
0064             }
0065 
0066             $params['parent'] = null;
0067             $resultRow = $this->_model->addNewElement($params)->toArray();
0068 
0069             /**
0070              * if (false === empty($params['parent'])) {
0071              * $this->_model->moveToParent($resultRow['project_category_id'], (int)$params['parent'], 'bottom');
0072              * $resultRow = $this->_model->fetchElement($resultRow['project_category_id']);
0073              * }**/
0074 
0075             $jTableResult['Result'] = self::RESULT_OK;
0076             $jTableResult['Record'] = $resultRow;
0077         } catch (Exception $e) {
0078             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0079             $translate = Zend_Registry::get('Zend_Translate');
0080             $jTableResult['Result'] = self::RESULT_ERROR;
0081             $jTableResult['Message'] = $translate->_('Error while processing data.');
0082         }
0083 
0084         $this->_helper->json($jTableResult);
0085     }
0086 
0087     public function updateAction()
0088     {
0089         $jTableResult = array();
0090         try {
0091             $params = $this->getAllParams();
0092             $parent = 0;
0093 
0094             if (empty($params['project_category_id'])) {
0095                 $params['project_category_id'] = null;
0096             }
0097 
0098             $record = $this->_model->save($params);
0099 
0100             $jTableResult = array();
0101             $jTableResult['Result'] = self::RESULT_OK;
0102             $jTableResult['Record'] = $record->toArray();
0103         } catch (Exception $e) {
0104             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0105             $translate = Zend_Registry::get('Zend_Translate');
0106             $jTableResult['Result'] = self::RESULT_ERROR;
0107             $jTableResult['Message'] = $translate->_('Error while processing data.');
0108         }
0109 
0110         $this->_helper->json($jTableResult);
0111     }
0112 
0113     public function deleteAction()
0114     {
0115         $identifier = (int)$this->getParam('project_category_id', null);
0116 
0117         $this->_model->setDelete($identifier);
0118         $this->_model->setStatus(0, $identifier);
0119 
0120         $jTableResult = array();
0121         $jTableResult['Result'] = self::RESULT_OK;
0122 
0123         $this->_helper->json($jTableResult);
0124     }
0125 
0126     public function listAction()
0127     {
0128         $startIndex = (int)$this->getParam('jtStartIndex');
0129         $pageSize = (int)$this->getParam('jtPageSize');
0130         $sorting = $this->getParam('jtSorting');
0131         $filter_deleted = (int)$this->getParam('filter_deleted', 1);
0132 
0133         $records = $this->_model->fetchTreeWithParentId($filter_deleted, null);
0134 
0135         $pagination = Zend_Paginator::factory($records);
0136         $pagination->setItemCountPerPage($pageSize);
0137         $pagination->setCurrentPageNumber(($startIndex / $pageSize) + 1);
0138 
0139         $jTableResult = array();
0140         $jTableResult['Result'] = self::RESULT_OK;
0141         $jTableResult['Records'] = (array)$pagination->getCurrentItems();
0142         $jTableResult['TotalRecordCount'] = count($records);
0143 
0144         $this->_helper->json($jTableResult);
0145     }
0146 
0147     public function moveelementAction()
0148     {
0149         $params = $this->getAllParams();
0150         $newPosition = $params['record']['lft'];
0151 
0152         switch ($params['direction']) {
0153             case 'up':
0154                 $sibling = $this->_model->findPreviousSibling($params['record']);
0155                 if (null == $sibling) {
0156                     $newPosition = $params['record']['lft'];
0157                 } else {
0158                     $newPosition = (int)$sibling['lft'];
0159                 }
0160                 break;
0161             case 'down':
0162                 $sibling = $this->_model->findNextSibling($params['record']);
0163                 if (null == $sibling) {
0164                     $newPosition = $params['record']['lft'];
0165                 } else {
0166                     $newPosition = (int)$sibling['rgt'] + 1;
0167                 }
0168                 break;
0169             default:
0170                 ;
0171         }
0172 
0173         $jTableResult = array();
0174         if (count($sibling) == 0) {
0175             $jTableResult['Result'] = self::RESULT_ERROR;
0176             $this->_helper->json($jTableResult);
0177         }
0178 
0179         $element = $this->_model->fetchRow('lft = ' . $params['record']['lft']);
0180 
0181         $result = $this->_model->moveTo($element->toArray(), $newPosition);
0182 
0183         $jTableResult['Result'] = $result == true ? self::RESULT_OK : self::RESULT_ERROR;
0184         $jTableResult['Record'] = $element->toArray();
0185 
0186         $this->_helper->json($jTableResult);
0187     }
0188 
0189     public function dragdropAction()
0190     {
0191         $params = $this->getAllParams();
0192 
0193         if ($params['data']['lft'] <= $params['newPosition'] And $params['data']['rgt'] >= $params['newPosition']) {
0194             $result = false;
0195         } else {
0196             $result = $this->_model->moveTo($params['data'], $params['newPosition']);
0197         }
0198 
0199         $jTableResult = array();
0200         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0201 
0202         $this->_helper->json($jTableResult);
0203     }
0204 
0205     public function treeAction()
0206     {
0207         $result = true;
0208         $cat_id = (int)$this->getParam('c');
0209 
0210         try {
0211             $records = $this->_model->fetchTreeForJTableStores($cat_id);
0212         } catch (Exception $e) {
0213             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0214             $result = false;
0215             $records = array();
0216         }
0217 
0218         $jTableResult = array();
0219         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0220         $jTableResult['Options'] = $records;
0221 
0222         $this->_helper->json($jTableResult);
0223     }
0224 
0225     public function treerealAction()
0226     {
0227         $result = true;
0228         $cat_id = (int)$this->getParam('c');
0229 
0230         try {
0231             $records = $this->_model->fetchTreeRealForJTableStores($cat_id);
0232         } catch (Exception $e) {
0233             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0234             $result = false;
0235             $records = array();
0236         }
0237 
0238         $jTableResult = array();
0239         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0240         $jTableResult['Options'] = $records;
0241 
0242         $this->_helper->json($jTableResult);
0243     }
0244 
0245     public function createaboutAction()
0246     {
0247         $cat_id = (int)$this->getParam('c');
0248         $config = Zend_Registry::get('config');
0249         $static_config = $config->settings->static;
0250         $include_path = $static_config->include_path . 'category_about/';
0251         try {
0252             if (touch($include_path . '/' . $cat_id . '.phtml')) {
0253                 $result = true;
0254             } else {
0255                 $result = false;
0256             }
0257         } catch (Exception $e) {
0258             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0259             $result = false;
0260         }
0261 
0262         $jTableResult = array();
0263         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0264 
0265         $this->_helper->json($jTableResult);
0266     }
0267 
0268     public function readaboutAction()
0269     {
0270         $cat_id = (int)$this->getParam('c');
0271         $config = Zend_Registry::get('config');
0272         $static_config = $config->settings->static;
0273         $include_path = $static_config->include_path . 'category_about/';
0274         $filecontent = '';
0275         $result = true;
0276 
0277         try {
0278             if (file_exists($include_path . '/' . $cat_id . '.phtml')) {
0279                 $filecontent = file_get_contents($include_path . '/' . $cat_id . '.phtml');
0280             }
0281         } catch (Exception $e) {
0282             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0283             $result = false;
0284         }
0285 
0286         $jTableResult = array();
0287         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0288         $jTableResult['c'] = $cat_id;
0289         $jTableResult['CatAbout'] = $filecontent;
0290 
0291         $this->_helper->json($jTableResult);
0292     }
0293 
0294     public function saveaboutAction()
0295     {
0296         $cat_id = (int)$this->getParam('c');
0297         $cat_about = $this->getParam('ca');
0298 
0299         $config = Zend_Registry::get('config');
0300         $static_config = $config->settings->static;
0301         $include_path = $static_config->include_path . 'category_about/';
0302 
0303         try {
0304             file_put_contents($include_path . '/' . $cat_id . '.phtml', $cat_about);
0305             $result = true;
0306         } catch (Exception $e) {
0307             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0308             $result = false;
0309         }
0310 
0311         $jTableResult = array();
0312         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0313 
0314         $this->_helper->json($jTableResult);
0315     }
0316 
0317 }