Skip to content
Permalink
Browse files

Support getting filter criteria and filter by id

- Support getting a filter by id
- Support getting filter criteria

Fixes #22789
  • Loading branch information...
vboctor committed Dec 3, 2017
1 parent 063c534 commit 13b9aefa55ef9e423b2613f240abd53824d62f0e
@@ -30,6 +30,8 @@
$g_app->group('/filters', function() use ( $g_app ) {
$g_app->get( '', 'rest_filter_get' );
$g_app->get( '/', 'rest_filter_get' );
$g_app->get( '/{id}', 'rest_filter_get' );
$g_app->get( '/{id}/', 'rest_filter_get' );
$g_app->delete( '/{id}', 'rest_filter_delete' );
$g_app->delete( '/{id}/', 'rest_filter_delete' );
});
@@ -45,13 +47,16 @@
* @return SlimResponse The augmented response.
*/
function rest_filter_get( SlimRequest $p_request, SlimResponse $p_response, array $p_args ) {
# Filter id will be null if not provided.
$t_filter_id = isset( $p_args['id'] ) ? $p_args['id'] : $p_request->getParam( 'id' );
$t_project_id = $p_request->getParam( 'project_id', null );
if( $t_project_id !== null && (int)$t_project_id != ALL_PROJECTS && !project_exists( $t_project_id ) ) {
$t_message = "Project '$t_project_id' doesn't exist";
return $p_response->withStatus( HTTP_STATUS_NOT_FOUND, $t_message );
}
$t_filters = mc_filter_get( '', '', $t_project_id );
$t_filters = mc_filter_get( '', '', $t_project_id, $t_filter_id );
$t_result = array( 'filters' => $t_filters );
return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
@@ -72,9 +72,10 @@
* @param string $p_username The name of the user trying to access the filters.
* @param string $p_password The password of the user.
* @param integer $p_project_id The id of the project to retrieve filters for or null to get all filters.
* @param integer|null $p_filter_id null to get all, or integer to get specified filter id.
* @return array that represents a FilterDataArray structure
*/
function mc_filter_get( $p_username, $p_password, $p_project_id ) {
function mc_filter_get( $p_username, $p_password, $p_project_id, $p_filter_id = null ) {
$t_user_id = mci_check_login( $p_username, $p_password );
if( $t_user_id === false ) {
return mci_fault_login_failed();
@@ -92,28 +93,28 @@ function mc_filter_get( $p_username, $p_password, $p_project_id ) {
false ); # Return names only?
foreach( $t_filter_rows as $t_filter_row ) {
$t_filter = array();
$t_filter['id'] = (int)$t_filter_row['id'];
$t_filter['name'] = $t_filter_row['name'];
if( $p_filter_id !== null && (int)$p_filter_id != (int)$t_filter_row['id'] ) {
continue;
}
if( ApiObjectFactory::$soap ) {
$t_filter = array();
$t_filter['id'] = (int)$t_filter_row['id'];
$t_filter['name'] = $t_filter_row['name'];
$t_filter['owner'] = mci_account_get_array_by_id( $t_filter_row['user_id'] );
$t_filter['is_public'] = $t_filter_row['is_public'];
$t_filter['project_id'] = $t_filter_row['project_id'];
$t_filter['filter_string'] = $t_filter_row['filter_string'];
$t_filter['url'] = $t_filter_row['url'];
} else {
# Only include owner if it is different than user retrieving the filters list.
if( (int)$t_filter_row['user_id'] != auth_get_current_user_id() ) {
$t_filter['owner'] = mci_account_get_array_by_id( $t_filter_row['user_id'] );
}
$t_filter['public'] = $t_filter_row['is_public'] == '1' ? true : false;
$t_filter['project'] = mci_project_as_array_by_id( $t_filter_row['project_id'] );
$t_lang = mci_get_user_lang( $t_user_id );
$converter = new FilterConverter( $t_user_id, $t_lang );
$t_filter = $converter->filterToJson( $t_filter_row );
}
$t_filter['url'] = $t_filter_row['url'];
$t_result[] = $t_filter;
}
return $t_result;
}

0 comments on commit 13b9aef

Please sign in to comment.
You can’t perform that action at this time.