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_CategorytagController 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  Category_Tag';
0042         $this->view->author = $this->_authMember->username;
0043     }
0044 
0045     public function indexAction()
0046     {
0047         
0048     }
0049 
0050     // public function createAction()
0051     // {
0052 
0053     //     $jTableResult = array();
0054     //     try {
0055     //         $params = $this->getAllParams();
0056     //         if (empty($params['rgt'])) {
0057     //             $root = $this->_model->fetchRoot();
0058     //             $params['rgt'] = $root->rgt - 1;
0059     //         }
0060     //         $resultRow = $this->_model->addNewElement($params)->toArray();
0061 
0062     //         if (false === empty($params['parent'])) {
0063     //             $this->_model->moveToParent($resultRow['project_category_id'], (int)$params['parent'], 'bottom');
0064     //             $resultRow = $this->_model->fetchElement($resultRow['project_category_id']);
0065     //         }
0066 
0067     //         $jTableResult['Result'] = self::RESULT_OK;
0068     //         $jTableResult['Record'] = $resultRow;
0069     //     } catch (Exception $e) {
0070     //         Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0071     //         $translate = Zend_Registry::get('Zend_Translate');
0072     //         $jTableResult['Result'] = self::RESULT_ERROR;
0073     //         $jTableResult['Message'] = $translate->_('Error while processing data.');
0074     //     }
0075 
0076     //     $this->_helper->json($jTableResult);
0077     // }
0078 
0079     // private function startsWith($haystack, $needle) {
0080     //     // search backwards starting from haystack length characters from the end
0081     //     return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
0082     // }
0083 
0084     // private function endsWith($haystack, $needle) {
0085     //     // search forward starting from end minus needle length characters
0086     //     return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
0087     // }
0088 
0089     public function updateAction()
0090     {
0091 
0092         $jTableResult = array();
0093         try {                    
0094             $tagsid = $this->getParam('tags_id', null);
0095             $tagmodel  = new Default_Model_Tags();
0096             $isvalid = $tagmodel->validateCategoryTags((int)$this->getParam('project_category_id', null), $tagsid);
0097             if($isvalid)
0098             {
0099                 $tagmodel->updateTagsPerCategory((int)$this->getParam('project_category_id', null), $tagsid);
0100                 $jTableResult = array();
0101                 $jTableResult['Result'] = self::RESULT_OK;
0102             }else
0103             {
0104                 $jTableResult = array();
0105                 $jTableResult['Result'] = self::RESULT_ERROR;
0106                 $translate = Zend_Registry::get('Zend_Translate');
0107                 $jTableResult['Message'] = $translate->_('duplicated! please check parent/children catgory tags');
0108             }
0109             
0110            // $jTableResult['Record'] = $record->toArray();
0111         } catch (Exception $e) {
0112             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0113             $translate = Zend_Registry::get('Zend_Translate');
0114             $jTableResult['Result'] = self::RESULT_ERROR;
0115             $jTableResult['Message'] = $translate->_('Error while processing data.');
0116         }
0117 
0118         $this->_helper->json($jTableResult);
0119     }
0120 
0121 
0122     public function listAction()
0123     {
0124 
0125         $startIndex = (int)$this->getParam('jtStartIndex');
0126         $pageSize = (int)$this->getParam('jtPageSize');
0127         $sorting = $this->getParam('jtSorting');
0128         $filter_deleted = (int)$this->getParam('filter_deleted', 1);
0129 
0130         $records = $this->_model->fetchTreeWithParentIdAndTags($filter_deleted, null);      
0131 
0132         $pagination = Zend_Paginator::factory($records);
0133         $pagination->setItemCountPerPage($pageSize);
0134         $pagination->setCurrentPageNumber(($startIndex / $pageSize) + 1);
0135 
0136         $jTableResult = array();
0137         $jTableResult['Result'] = self::RESULT_OK;
0138         $jTableResult['Records'] = (array)$pagination->getCurrentItems();
0139         $jTableResult['TotalRecordCount'] = count($records);
0140 
0141         $this->_helper->json($jTableResult);
0142     }
0143 
0144     
0145 
0146     public function treeAction()
0147     {
0148 
0149         $result = true;
0150         $cat_id = (int)$this->getParam('c');
0151 
0152         try {
0153             $records = $this->_model->fetchTreeForJTableStores($cat_id);
0154 
0155 
0156         } catch (Exception $e) {
0157             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0158             $result = false;
0159             $records = array();
0160         }
0161 
0162         $jTableResult = array();
0163         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0164         $jTableResult['Options'] = $records;
0165 
0166         $this->_helper->json($jTableResult);
0167     }
0168 
0169 
0170     public function tagsallAction()
0171     {
0172 
0173         $result = true;
0174         $groupid = 6; // category-tags
0175         $tagmodel  = new Default_Model_Tags();
0176         try {
0177                 $resultRows = $tagmodel->getTagsPerGroup($groupid);
0178                 $resultForSelect = array();
0179                 foreach ($resultRows as $row) {         
0180                     $resultForSelect[] = array('DisplayText' => $row['tag_name'].'['.$row['tag_id'].']', 'Value' => $row['tag_id']);
0181                 }
0182 
0183         } catch (Exception $e) {
0184             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0185             $result = false;
0186             $records = array();
0187         }
0188 
0189         $jTableResult = array();
0190         $jTableResult['Result'] = ($result == true) ? self::RESULT_OK : self::RESULT_ERROR;
0191         $jTableResult['Options'] = $resultForSelect;
0192 
0193         $this->_helper->json($jTableResult);
0194     }
0195 
0196   
0197 
0198 }