[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: category_api.php,v 1.14.22.1 2007-10-13 22:35:15 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### Category API ### 25 26 #=================================== 27 # Boolean queries and ensures 28 #=================================== 29 30 # -------------------- 31 # Check whether the category exists in the project 32 # Return true if the category exists, false otherwise 33 function category_exists( $p_project_id, $p_category ) { 34 $c_project_id = db_prepare_int( $p_project_id ); 35 $c_category = db_prepare_string( $p_category ); 36 37 $t_project_category_table = config_get( 'mantis_project_category_table' ); 38 39 $query = "SELECT COUNT(*) 40 FROM $t_project_category_table 41 WHERE project_id='$c_project_id' AND 42 category='$c_category'"; 43 $result = db_query( $query ); 44 $category_count = db_result( $result ); 45 46 if ( 0 < $category_count ) { 47 return true; 48 } else { 49 return false; 50 } 51 } 52 53 # -------------------- 54 # Check whether the category exists in the project 55 # Trigger an error if it does not 56 function category_ensure_exists( $p_project_id, $p_category ) { 57 if ( !category_exists( $p_project_id, $p_category ) ) { 58 trigger_error( ERROR_CATEGORY_NOT_FOUND, ERROR ); 59 } 60 } 61 62 # -------------------- 63 # Check whether the category is unique within a project 64 # Returns true if the category is unique, false otherwise 65 function category_is_unique( $p_project_id, $p_category ) { 66 return !category_exists( $p_project_id, $p_category ); 67 } 68 69 # -------------------- 70 # Check whether the category is unique within a project 71 # Trigger an error if it is not 72 function category_ensure_unique( $p_project_id, $p_category ) { 73 if ( !category_is_unique( $p_project_id, $p_category ) ) { 74 trigger_error( ERROR_CATEGORY_DUPLICATE, ERROR ); 75 } 76 } 77 78 79 #=================================== 80 # Creation / Deletion / Updating 81 #=================================== 82 83 # -------------------- 84 # Add a new category to the project 85 function category_add( $p_project_id, $p_category ) { 86 $c_project_id = db_prepare_int( $p_project_id ); 87 $c_category = db_prepare_string( $p_category ); 88 89 category_ensure_unique( $p_project_id, $p_category ); 90 91 $t_project_category_table = config_get( 'mantis_project_category_table' ); 92 93 $query = "INSERT INTO $t_project_category_table 94 ( project_id, category ) 95 VALUES 96 ( '$c_project_id', '$c_category' )"; 97 db_query( $query ); 98 99 # db_query() errors on failure so: 100 return true; 101 } 102 103 # -------------------- 104 # Update the name and user associated with the category 105 function category_update( $p_project_id, $p_category, $p_new_category, $p_assigned_to ) { 106 $c_project_id = db_prepare_int( $p_project_id ); 107 $c_category = db_prepare_string( $p_category ); 108 $c_new_category = db_prepare_string( $p_new_category ); 109 $c_assigned_to = db_prepare_int( $p_assigned_to ); 110 111 category_ensure_exists( $p_project_id, $p_category ); 112 113 $t_project_category_table = config_get( 'mantis_project_category_table' ); 114 $t_bug_table = config_get( 'mantis_bug_table' ); 115 116 $query = "UPDATE $t_project_category_table 117 SET category='$c_new_category', 118 user_id=$c_assigned_to 119 WHERE category='$c_category' AND 120 project_id='$c_project_id'"; 121 db_query( $query ); 122 123 if ( $p_category != $p_new_category ) { 124 $query = "UPDATE $t_bug_table 125 SET category='$c_new_category' 126 WHERE category='$c_category' AND 127 project_id='$c_project_id'"; 128 db_query( $query ); 129 } 130 131 # db_query() errors on failure so: 132 return true; 133 } 134 135 # -------------------- 136 # Remove a category from the project 137 function category_remove( $p_project_id, $p_category, $p_new_category='' ) { 138 $c_project_id = db_prepare_int( $p_project_id ); 139 $c_category = db_prepare_string( $p_category ); 140 $c_new_category = db_prepare_string( $p_new_category ); 141 142 category_ensure_exists( $p_project_id, $p_category ); 143 if ( !is_blank( $p_new_category ) ) { 144 category_ensure_exists( $p_project_id, $p_new_category ); 145 } 146 147 $t_project_category_table = config_get( 'mantis_project_category_table' ); 148 $t_bug_table = config_get( 'mantis_bug_table' ); 149 150 $query = "DELETE FROM $t_project_category_table 151 WHERE project_id='$c_project_id' AND 152 category='$c_category'"; 153 db_query( $query ); 154 155 $query = "UPDATE $t_bug_table 156 SET category='$c_new_category' 157 WHERE category='$c_category' AND 158 project_id='$c_project_id'"; 159 db_query( $query ); 160 161 # db_query() errors on failure so: 162 return true; 163 } 164 165 # -------------------- 166 # Remove all categories associated with a project 167 function category_remove_all( $p_project_id ) { 168 $c_project_id = db_prepare_int( $p_project_id ); 169 170 project_ensure_exists( $p_project_id ); 171 172 $t_project_category_table = config_get( 'mantis_project_category_table' ); 173 $t_bug_table = config_get( 'mantis_bug_table' ); 174 175 $query = "DELETE FROM $t_project_category_table 176 WHERE project_id='$c_project_id'"; 177 db_query( $query ); 178 179 $query = "UPDATE $t_bug_table 180 SET category='' 181 WHERE project_id='$c_project_id'"; 182 db_query( $query ); 183 184 # db_query() errors on failure so: 185 return true; 186 } 187 188 189 #=================================== 190 # Data Access 191 #=================================== 192 193 # -------------------- 194 # Return the definition row for the category 195 function category_get_row( $p_project_id, $p_category ) { 196 $c_project_id = db_prepare_int( $p_project_id ); 197 $c_category = db_prepare_string( $p_category ); 198 199 $t_project_category_table = config_get( 'mantis_project_category_table' ); 200 201 $query = "SELECT category, user_id 202 FROM $t_project_category_table 203 WHERE project_id='$c_project_id' AND 204 category='$c_category'"; 205 $result = db_query( $query ); 206 $count = db_num_rows( $result ); 207 if ( 0 == $count ) { 208 trigger_error( ERROR_CATEGORY_NOT_FOUND, ERROR ); 209 } 210 211 return db_fetch_array( $result ); 212 } 213 214 # -------------------- 215 # Return all categories for the specified project id 216 function category_get_all_rows( $p_project_id ) { 217 $c_project_id = db_prepare_int( $p_project_id ); 218 219 $t_project_category_table = config_get( 'mantis_project_category_table' ); 220 221 $query = "SELECT category, user_id 222 FROM $t_project_category_table 223 WHERE project_id='$c_project_id' 224 ORDER BY category"; 225 $result = db_query( $query ); 226 $count = db_num_rows( $result ); 227 $rows = array(); 228 for ( $i = 0 ; $i < $count ; $i++ ) { 229 $row = db_fetch_array( $result ); 230 231 $rows[] = $row; 232 } 233 234 return $rows; 235 } 236 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |