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

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