|
| 1 | +<?php |
| 2 | +# MantisBT - A PHP based bugtracking system |
| 3 | + |
| 4 | +# MantisBT is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 2 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# MantisBT is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with MantisBT. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Retrieves all tags, unless the users |
| 19 | + * |
| 20 | + * @param string $p_username The user's username |
| 21 | + * @param string $p_password The user's password |
| 22 | + * @param int $p_page_number The page number to return data for |
| 23 | + * @param string $p_per_page The number of issues to return per page |
| 24 | + * @return array The tag data |
| 25 | + */ |
| 26 | +function mc_tag_get_all( $p_username, $p_password, $p_page_number, $p_per_page) { |
| 27 | + $t_user_id = mci_check_login( $p_username, $p_password ); |
| 28 | + if ( $t_user_id === false ) { |
| 29 | + return mci_soap_fault_login_failed(); |
| 30 | + } |
| 31 | + |
| 32 | + if ( !access_has_global_level( config_get( 'tag_view_threshold' ) ) ) |
| 33 | + return mci_soap_fault_access_denied( $t_user_id , 'No rights to view tags'); |
| 34 | + |
| 35 | + if ( $p_per_page == 0 ) |
| 36 | + $p_per_page = 1; |
| 37 | + |
| 38 | + $t_results = array(); |
| 39 | + $t_total_results = tag_count( '' ); |
| 40 | + |
| 41 | + foreach ( tag_get_all('', $p_per_page, $p_per_page * ( $p_page_number - 1 ) ) as $t_tag_row ) { |
| 42 | + $t_results[] = array ( |
| 43 | + 'id' => $t_tag_row['id'], |
| 44 | + 'name' => $t_tag_row['name'], |
| 45 | + 'description' => $t_tag_row['description'], |
| 46 | + 'user_id' => mci_account_get_array_by_id ( $t_tag_row['user_id'] ), |
| 47 | + 'date_created' => timestamp_to_iso8601($t_tag_row['date_created'], false), |
| 48 | + 'date_updated' => timestamp_to_iso8601($t_tag_row['date_updated'], false) |
| 49 | + |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + return array( |
| 54 | + 'results' => $t_results, |
| 55 | + 'total_results' => $t_total_results |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * Creates a tag |
| 61 | + * |
| 62 | + * @param string $p_username The user's username |
| 63 | + * @param string $p_password The user's password |
| 64 | + * @param array $p_tag The tag to create |
| 65 | + * @return soap_fault|integer |
| 66 | + */ |
| 67 | +function mc_tag_add( $p_username, $p_password, $p_tag ) { |
| 68 | + |
| 69 | + $t_user_id = mci_check_login( $p_username, $p_password ); |
| 70 | + |
| 71 | + if ( $t_user_id === false ) { |
| 72 | + return mci_soap_fault_login_failed(); |
| 73 | + } |
| 74 | + |
| 75 | + if ( !access_has_global_level( config_get( 'tag_create_threshold' ) ) ) |
| 76 | + return mci_soap_fault_access_denied( $p_user_id ); Has conversations. Original line has conversations. |
| 77 | + |
| 78 | + $t_valid_matches = array(); |
| 79 | + |
| 80 | + $t_tag_name = $p_tag['name']; |
| 81 | + $t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : ''; |
| 82 | + |
| 83 | + if ( !tag_name_is_valid($t_tag_name, $t_valid_matches)) |
| 84 | + return new soap_fault('client', '', 'Invalid tag name : "' . $t_tag_name .'"' ); |
| 85 | + |
| 86 | + $t_matching_by_name = tag_get_by_name( $t_tag_name); |
| 87 | + if ( $t_matching_by_name != false ) |
| 88 | + return new soap_fault('client', '', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']); |
| 89 | + |
| 90 | + return tag_create($t_tag_name, $t_user_id, $t_tag_description); |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * |
| 95 | + * Deletes a tag |
| 96 | + * |
| 97 | + * @param string $p_username The user's username |
| 98 | + * @param string $p_password The user's password * @param unknown_type $p_tag_id |
| 99 | + * @param int $p_tag_id The id of the tag |
| 100 | + * @return soap_fault|boolean |
| 101 | + */ |
| 102 | +function mc_tag_delete( $p_username, $p_password, $p_tag_id ) { |
| 103 | + |
| 104 | + $t_user_id = mci_check_login( $p_username, $p_password ); |
| 105 | + |
| 106 | + if ( $t_user_id === false ) { |
| 107 | + return mci_soap_fault_login_failed(); |
| 108 | + } |
| 109 | + |
| 110 | + if ( !access_has_global_level( config_get( 'tag_edit_threshold' ) ) ) |
| 111 | + return mci_soap_fault_access_denied( $p_user_id ); Has conversations. Original line has conversations. |
| 112 | + |
| 113 | + if ( ! tag_exists( $p_tag_id ) ) |
| 114 | + return new soap_fault('Client', '', 'No tag with id ' . $p_tag_id); |
| 115 | + |
| 116 | + return tag_delete( $p_tag_id ); |
| 117 | +} |