Skip to content

Commit

Permalink
Implement mc_user_profiles_get_all
Browse files Browse the repository at this point in the history
Fixes #13646: Support profile fields
  • Loading branch information
rombert committed Dec 6, 2011
1 parent c47e5e1 commit bbde4d4
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 4 deletions.
75 changes: 71 additions & 4 deletions api/soap/mantisconnect.php
Expand Up @@ -595,12 +595,58 @@
'struct',
'all',
'',
array(
'results' => array( 'name' => 'results', 'type' => 'tns:TagDataArray', 'minOccurs' => '0' ),
'total_results' => array( 'name' => 'total_results', 'type' => 'xsd:integer', 'minOccurs' => '0' )
)
array(
'results' => array( 'name' => 'results', 'type' => 'tns:TagDataArray', 'minOccurs' => '0' ),
'total_results' => array( 'name' => 'total_results', 'type' => 'xsd:integer', 'minOccurs' => '0' )
)
);

### ProfileData
$l_oServer->wsdl->addComplexType(
'ProfileData',
'complexType',
'struct',
'all',
'',
array(
'id' => array( 'name' => 'id', 'type' => 'xsd:integer', 'minOccurs' => '0' ),
'user_id' => array( 'name' => 'user_id', 'type' => 'tns:AccountData', 'minOccurs' => '0' ),
'platform' => array( 'name' => 'platform', 'type' => 'xsd:string', 'minOccurs' => '0' ),
'os' => array( 'name' => 'os', 'type' => 'xsd:string', 'minOccurs' => '0' ),
'os_build' => array( 'name' => 'os_build', 'type' => 'xsd:string', 'minOccurs' => '0' ),
'description' => array( 'name' => 'description', 'type' => 'xsd:string', 'minOccurs' => '0' )
)
);

### ProfileDataArray
$l_oServer->wsdl->addComplexType(
'ProfileDataArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:ProfileData[]'
)
),
'tns:ProfileData'
);


### ProfileDataSearchResult
$l_oServer->wsdl->addComplexType(
'ProfileDataSearchResult',
'complexType',
'struct',
'all',
'',
array(
'results' => array( 'name' => 'results', 'type' => 'tns:ProfileDataArray', 'minOccurs' => '0' ),
'total_results' => array( 'name' => 'total_results', 'type' => 'xsd:integer', 'minOccurs' => '0' )
)
);
###
### PUBLIC METHODS
###
Expand Down Expand Up @@ -1543,6 +1589,27 @@
'Get the value for the specified user preference.'
);

###
### PUBLIC METHODS (defined in mc_user_profile_api.php)
###


### mc_user_profiles_get_all
$l_oServer->register( 'mc_user_profiles_get_all',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'page_number' => 'xsd:integer',
'per_page' => 'xsd:integer'
),
array(
'return' => 'tns:ProfileDataSearchResult'
),
$t_namespace,
false, false, false,
'Get profiles available to the current user.'
);

###
### PUBLIC METHODS (defined in mc_tag_api.php)
###
Expand Down
1 change: 1 addition & 0 deletions api/soap/mc_core.php
Expand Up @@ -42,3 +42,4 @@
require_once( $t_current_dir . 'mc_custom_field_api.php' );
require_once( $t_current_dir . 'mc_user_pref_api.php' );
require_once( $t_current_dir . 'mc_tag_api.php' );
require_once( $t_current_dir . 'mc_user_profile_api.php' );
64 changes: 64 additions & 0 deletions api/soap/mc_user_profile_api.php
@@ -0,0 +1,64 @@
<?php
# MantisBT - A PHP based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Returns all the profiles for the user, including the global ones
*
* @param string $p_username The user's username
* @param string $p_password The user's password
* @param integer $p_page_number
* @param integer $p_per_page
*
*/
function mc_user_profiles_get_all( $p_username, $p_password, $p_page_number, $p_per_page ) {
$t_user_id = mci_check_login( $p_username, $p_password );
if ( $t_user_id === false ) {
return mci_soap_fault_login_failed();
}

if ( !mci_has_readonly_access( $t_user_id ) ) {
return mci_soap_fault_access_denied( $t_user_id );
}

$t_results = array();
$t_start = max ( array ( 0, $p_page_number - 1 ) ) * $p_per_page;

foreach ( profile_get_all_for_user( $t_user_id ) as $t_profile_row ) {

$t_result = array(
'id' => $t_profile_row['id'],
'description' => $t_profile_row['description'],
'os' => $t_profile_row['os'],
'os_build' => $t_profile_row['os_build'],
'platform' => $t_profile_row['platform']
);

if ( $t_profile_row['user_id'] != 0 )
$t_result['user_id'] = mci_account_get_array_by_id( $t_profile_row['user_id'] );

$t_results[] = $t_result;
}

// the profile_api does not implement pagination in the backend, so we emulate it here
// we can always push the pagination in the database, but this seems unlikely in the
// near future, as the number of profiles is expected to be small
$t_paged_results = array_slice ( $t_results, $t_start, $p_per_page );

return array (
'total_results' => count ( $t_results),
'results' => $t_paged_results
);
}

0 comments on commit bbde4d4

Please sign in to comment.