File indexing completed on 2024-12-22 05:33:34
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 TagController extends Zend_Controller_Action 0024 { 0025 0026 public function addAction() 0027 { 0028 $this->_helper->layout()->disableLayout(); 0029 0030 //$tag = Default_Model_HtmlPurify::purify($this->getParam('t')); 0031 $tag = $this->getParam('t'); 0032 $projectid = (int) $this->getParam('p'); 0033 0034 if(strlen($tag)>45){ 0035 0036 $this->_helper->json(array( 0037 'status' => 'error', 0038 'message' => 'Max. length 45 chars', 0039 'data' => array('pid' => $projectid, 'tag' => $tag) 0040 )); 0041 0042 return; 0043 } 0044 0045 if (!preg_match('/^[\w-]+$/', $tag)) { 0046 $this->_helper->json(array( 0047 'status' => 'error', 0048 'message' => 'Must be letter or number and can include hyphens', 0049 'data' => array('pid' => $projectid, 'tag' => $tag) 0050 )); 0051 0052 return; 0053 } 0054 0055 $model = new Default_Model_Tags(); 0056 $cnt = $model->getTagsUserCount($projectid,Default_Model_Tags::TAG_TYPE_PROJECT); 0057 if($cnt<5){ 0058 if($model->isTagsUserExisting($projectid,$tag)) 0059 { 0060 $this->_helper->json(array( 0061 'status' => 'existing', 0062 'message' => 'tag existing.', 0063 'data' => array('pid' => $projectid, 'tag' => $tag) 0064 )); 0065 } 0066 else 0067 { 0068 $model->addTagUser($projectid,$tag,Default_Model_Tags::TAG_TYPE_PROJECT); 0069 $this->_helper->json(array( 0070 'status' => 'ok', 0071 'message' => '', 0072 'data' => array('pid' => $projectid, 'tag' => $tag) 0073 )); 0074 } 0075 0076 0077 } 0078 else 0079 { 0080 $this->_helper->json(array( 0081 'status' => 'error', 0082 'message' => 'Max. 5 Tags', 0083 'data' => array('pid' => $projectid, 'tag' => $tag) 0084 )); 0085 } 0086 } 0087 0088 public function delAction() 0089 { 0090 $this->_helper->layout()->disableLayout(); 0091 0092 $projectid = (int) $this->getParam('p'); 0093 $tag = $this->getParam('t'); 0094 0095 $model = new Default_Model_Tags(); 0096 $model->deleteTagUser($projectid,$tag,Default_Model_Tags::TAG_TYPE_PROJECT); 0097 0098 $this->_helper->json(array( 0099 'status' => 'ok', 0100 'message' => 'Removed', 0101 'data' => array('pid' => $projectid, 'tag'=>$tag) 0102 )); 0103 } 0104 0105 public function assignAction() 0106 { 0107 $this->_helper->layout()->disableLayout(); 0108 0109 $objectId = (int) $this->getParam('oid'); 0110 $objectType = (int) $this->getParam('ot', 10); 0111 $tag = Default_Model_HtmlPurify::purify($this->getParam('tag')); 0112 0113 $this->_helper->json(array( 0114 'status' => 'ok', 0115 'message' => '', 0116 'data' => array('oid' => $objectId, 'tag' => $tag, 'type' => $objectType) 0117 )); 0118 } 0119 0120 public function removeAction() 0121 { 0122 $this->_helper->layout()->disableLayout(); 0123 0124 $objectId = (int) $this->getParam('oid'); 0125 $objectType = (int) $this->getParam('ot', 10); 0126 $tag = Default_Model_HtmlPurify::purify($this->getParam('tag')); 0127 0128 $this->_helper->json(array( 0129 'status' => 'ok', 0130 'message' => '', 0131 'data' => array('oid' => $objectId, 'tag' => $tag, 'type' => $objectType) 0132 )); 0133 } 0134 0135 public function filterAction() 0136 { 0137 $this->_helper->layout()->disableLayout(); 0138 $model = new Default_Model_Tags(); 0139 $filter = $this->getParam('q'); 0140 $filter = strtolower($filter); 0141 $tags = $model->filterTagsUser($filter,10); 0142 $result = array(); 0143 foreach ($tags as $tag) { 0144 $result[] =array( 'id' => $tag['tag_name'], 0145 'text' =>$tag['tag_name'], 0146 'tag_id'=>$tag['tag_id'], 0147 'tag_name'=>$tag['tag_name'] 0148 ); 0149 } 0150 0151 $this->_helper->json(array( 0152 'status' => 'ok', 0153 'filter'=>$filter, 0154 'data' => array('tags' => $result) 0155 )); 0156 } 0157 }