[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # MantisConnect - A webservice interface to Mantis Bug Tracker 3 # Copyright (C) 2004-2007 Victor Boctor - vboctor@users.sourceforge.net 4 # This program is distributed under dual licensing. These include 5 # GPL and a commercial licenses. Victor Boctor reserves the right to 6 # change the license of future releases. 7 # See docs/ folder for more details 8 9 # -------------------------------------------------------- 10 # $Id: mc_enum_api.php,v 1.1 2007-07-18 06:52:53 vboctor Exp $ 11 # -------------------------------------------------------- 12 13 14 /** 15 * Get all available status. 16 * 17 * @param string $p_username The name of the user trying to access the enumeration. 18 * @param string $p_password The password of the user. 19 * @return Array The requested enumeration 20 */ 21 function mc_enum_status( $p_username, $p_password ) { 22 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'status' ) ); 23 } 24 25 /** 26 * Get all available priorities. 27 * 28 * @param string $p_username The name of the user trying to access the enumeration. 29 * @param string $p_password The password of the user. 30 * @return Array The requested enumeration 31 */ 32 function mc_enum_priorities( $p_username, $p_password ) { 33 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'priority' ) ); 34 } 35 36 /** 37 * Get all available severities. 38 * 39 * @param string $p_username The name of the user trying to access the enumeration. 40 * @param string $p_password The password of the user. 41 * @return Array The requested enumeration 42 */ 43 function mc_enum_severities( $p_username, $p_password ) { 44 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'severity' ) ); 45 } 46 47 /** 48 * Get all available reproducibilities. 49 * 50 * @param string $p_username The name of the user trying to access the enumeration. 51 * @param string $p_password The password of the user. 52 * @return Array The requested enumeration 53 */ 54 function mc_enum_reproducibilities( $p_username, $p_password ) { 55 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'reproducibility' ) ); 56 } 57 58 /** 59 * Get all available projections. 60 * 61 * @param string $p_username The name of the user trying to access the enumeration. 62 * @param string $p_password The password of the user. 63 * @return Array The requested enumeration 64 */ 65 function mc_enum_projections( $p_username, $p_password ) { 66 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'projection' ) ); 67 } 68 69 /** 70 * Get all available etas. 71 * 72 * @param string $p_username The name of the user trying to access the enumeration. 73 * @param string $p_password The password of the user. 74 * @return Array The requested enumeration 75 */ 76 function mc_enum_etas( $p_username, $p_password ) { 77 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'eta' ) ); 78 } 79 80 /** 81 * Get all available resolutions. 82 * 83 * @param string $p_username The name of the user trying to access the enumeration. 84 * @param string $p_password The password of the user. 85 * @return Array The requested enumeration 86 */ 87 function mc_enum_resolutions( $p_username, $p_password ) { 88 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'resolution' ) ); 89 } 90 91 /** 92 * Get all available access levels. 93 * 94 * @param string $p_username The name of the user trying to access the enumeration. 95 * @param string $p_password The password of the user. 96 * @return Array The requested enumeration 97 */ 98 function mc_enum_access_levels( $p_username, $p_password ) { 99 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'access_levels' ) ); 100 } 101 102 /** 103 * Get all available project status. 104 * 105 * @param string $p_username The name of the user trying to access the enumeration. 106 * @param string $p_password The password of the user. 107 * @return Array The requested enumeration 108 */ 109 function mc_enum_project_status( $p_username, $p_password ) { 110 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'project_status' ) ); 111 } 112 113 /** 114 * Get all available project view states. 115 * 116 * @param string $p_username The name of the user trying to access the enumeration. 117 * @param string $p_password The password of the user. 118 * @return Array The requested enumeration 119 */ 120 function mc_enum_project_view_states( $p_username, $p_password ) { 121 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'project_view_state' ) ); 122 } 123 124 /** 125 * Get all available view states. 126 * 127 * @param string $p_username The name of the user trying to access the enumeration. 128 * @param string $p_password The password of the user. 129 * @return Array The requested enumeration 130 */ 131 function mc_enum_view_states( $p_username, $p_password ) { 132 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'view_state' ) ); 133 } 134 135 /** 136 * Get all available custom field types. 137 * 138 * @param string $p_username The name of the user trying to access the enumeration. 139 * @param string $p_password The password of the user. 140 * @return Array The requested enumeration 141 */ 142 function mc_enum_custom_field_types( $p_username, $p_password ) { 143 return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'custom_field_type' ) ); 144 } 145 146 /** 147 * Get an appropriate enumeration. (Should become an internal function.) 148 * 149 * @param string $p_username The name of the user trying to access the enumeration. 150 * @param string $p_password The password of the user. 151 * @param string $p_enumeration The enumeration to get. 152 * @return string The requested enumeration. 153 */ 154 function mc_enum_get( $p_username, $p_password, $p_enumeration ) { 155 $t_user_id = mci_check_login( $p_username, $p_password ); 156 if ( $t_user_id === false ) { 157 return new soap_fault( 'Client', '', 'Access Denied' ); 158 } 159 if ( !mci_has_readonly_access( $t_user_id ) ) { 160 return new soap_fault( 'Client', '', 'Access Denied' ); 161 } 162 $t_lang = mci_get_user_lang( $t_user_id ); 163 return lang_get( $p_enumeration . '_enum_string', $t_lang ); 164 } 165 166 /** 167 * Explode a configuration enumeration string into an array structure that can 168 * be safely converted into an ObjectRef structure. 169 * 170 * @param string $p_config_enum_string The string to convert 171 * @return Array The converted enumeration 172 */ 173 function mci_explode_to_objectref( $p_config_enum_string ) { 174 if( get_class( $p_config_enum_string ) == 'soap_fault' ) { 175 return $p_config_enum_string; 176 } 177 foreach( explode_enum_string( $p_config_enum_string ) as $t_enum_element ) { 178 list($t_id, $t_name) = explode_enum_arr( $t_enum_element ); 179 $t_result[] = array( 180 'id' => $t_id, 181 'name' => $t_name 182 ); 183 }; 184 return $t_result; 185 } 186 187 /** 188 * Get a localized enumeration element. 189 * 190 * @param integer $p_enum_id The id of the enumeration element to retrieve. 191 * @param String $p_enum_type The type of the enumeration element (e.g. 'status', 'reproducibility' etc.). 192 * @param String $p_lang The language for the name field. 193 * @return Array an Array containing the id and the name of the enumeration element. 194 */ 195 function mci_enum_get_array_by_id( $p_enum_id, $p_enum_type, $p_lang ) { 196 $t_result = array(); 197 $t_result['id'] = $p_enum_id; 198 $t_result['name'] = mci_get_enum_element( $p_enum_type, $p_enum_id, $p_lang ); 199 return $t_result; 200 } 201 202 /** 203 * Get the enum id given the enum label. 204 * 205 * @param $p_enum_string The enum string to search in. 206 * @param $p_label The label to search for. 207 * 208 * @return The id corresponding to the given label, or 0 if not found. 209 */ 210 function mci_get_enum_value_from_label( $p_enum_string, $p_label ) { 211 $t_arr = explode_enum_string( $p_enum_string ); 212 $enum_count = count( $t_arr ); 213 214 for ( $i = 0; $i < $enum_count; $i++ ) { 215 $t_s = explode_enum_arr( $t_arr[$i] ); 216 if ( $t_s[1] == $p_label ) { 217 return $t_s[0]; 218 } 219 } 220 221 return 0; 222 } 223 224 /** 225 * Get the enumeration id given an object ref. The id is set based on the following algorithm: 226 * - id from objectref. 227 * - id corresponding to name in object ref. 228 * - default value for the specified enumeration, if exists in configuration. 229 * - first id, if object ref doesn't contain an id or a name. 230 * 231 * @param string $p_enum The name of the enumeration as in the Mantis configuration file 232 * @param ObjectRef $p_object_ref An associate array with "id" and "name" keys. 233 * @return enum id 234 */ 235 function mci_get_enum_id_from_objectref( $p_enum, $p_object_ref ) { 236 if ( (int)$p_object_ref['id'] != 0 ) { 237 $t_id = (int)$p_object_ref['id']; 238 } else { 239 $t_enum = config_get( $p_enum . '_enum_string' ); 240 if ( !is_blank( $p_object_ref['name'] ) ) { 241 $t_id = mci_get_enum_value_from_label( $t_enum, $p_object_ref['name'] ); 242 if ( $t_id == 0 ) { 243 $t_id = config_get( 'mc_' . $p_enum . '_enum_default_when_not_found' ); 244 } 245 } else { 246 $t_default_id = config_get( 'default_bug_' . $p_enum, 0 ); 247 if ( $t_default_id == 0 ) { 248 $t_array = mci_explode_to_objectref( $t_enum ); 249 $t_id = (int)$t_array[0]['id']; 250 } else { 251 $t_id = $t_default_id; 252 } 253 } 254 } 255 256 return $t_id; 257 } 258 ?>
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 |
![]() |