Skip to content

Commit

Permalink
Use constants for filter view types
Browse files Browse the repository at this point in the history
Define constants FILTER_VIEW_TYPE_SIMPLE and FILTER_VIEW_TYPE_ADVANCED
to reference filter view types, instead of relying on hardcoded strings
'simple' and 'advanced'.

Fixes #21619
  • Loading branch information
dregad committed Feb 5, 2017
1 parent 1703efe commit 7a663f4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion api/soap/mc_filter_api.php
Expand Up @@ -233,7 +233,7 @@ function mci_filter_search_get_rows( $p_user_id, $p_filter_search, $p_page_numbe
$t_project_id = array( ALL_PROJECTS );
}

$t_filter = array( '_view_type' => 'advanced' );
$t_filter = array( '_view_type' => FILTER_VIEW_TYPE_ADVANCED );
$t_filter['project_id'] = $t_project_id;

// default fields
Expand Down
4 changes: 4 additions & 0 deletions core/constant_inc.php
Expand Up @@ -462,6 +462,10 @@
define( 'META_FILTER_CURRENT', - 3 );
define( 'META_FILTER_ANY', 0 );

# Filter view types
define( 'FILTER_VIEW_TYPE_SIMPLE', 'simple' );
define( 'FILTER_VIEW_TYPE_ADVANCED', 'advanced' );

# Custom filter types
define( 'FILTER_TYPE_STRING', 0 );
define( 'FILTER_TYPE_INT', 1 );
Expand Down
40 changes: 21 additions & 19 deletions core/filter_api.php
Expand Up @@ -562,12 +562,12 @@ function filter_ensure_valid_filter( array $p_filter_arr ) {
$t_config_view_filters = config_get( 'view_filters' );
$t_view_type = $p_filter_arr['_view_type'];
if( ADVANCED_ONLY == $t_config_view_filters ) {
$t_view_type = 'advanced';
$t_view_type = FILTER_VIEW_TYPE_ADVANCED;
}
if( SIMPLE_ONLY == $t_config_view_filters ) {
$t_view_type = 'simple';
$t_view_type = FILTER_VIEW_TYPE_SIMPLE;
}
if( !in_array( $t_view_type, array( 'simple', 'advanced' ) ) ) {
if( !in_array( $t_view_type, array( FILTER_VIEW_TYPE_SIMPLE, FILTER_VIEW_TYPE_ADVANCED ) ) ) {
$t_view_type = filter_get_default_view_type();
}
$p_filter_arr['_view_type'] = $t_view_type;
Expand Down Expand Up @@ -692,7 +692,7 @@ function filter_ensure_valid_filter( array $p_filter_arr ) {
# If view_type is advanced, and hide_status is present, modify status array
# to remove hidden status. This may happen after switching from simple to advanced.
# Then, remove hide_status property, as it does not apply to advanced filter
if( $p_filter_arr['_view_type'] == 'advanced'
if( $p_filter_arr['_view_type'] == FILTER_VIEW_TYPE_ADVANCED
&& !filter_field_is_none( $p_filter_arr[FILTER_PROPERTY_HIDE_STATUS] ) ) {
if( filter_field_is_any( $p_filter_arr[FILTER_PROPERTY_STATUS] ) ) {
$t_selected_status_array = MantisEnum::getValues( config_get( 'status_enum_string' ) );
Expand All @@ -715,7 +715,7 @@ function filter_ensure_valid_filter( array $p_filter_arr ) {
}

#If view_type is simple, resolve conflicts between show_status and hide_status
if( $p_filter_arr['_view_type'] == 'simple'
if( $p_filter_arr['_view_type'] == FILTER_VIEW_TYPE_SIMPLE
&& !filter_field_is_none( $p_filter_arr[FILTER_PROPERTY_HIDE_STATUS] ) ) {
# get array of hidden status ids
$t_all_status = MantisEnum::getValues( config_get( 'status_enum_string' ) );
Expand Down Expand Up @@ -745,14 +745,14 @@ function filter_ensure_valid_filter( array $p_filter_arr ) {
* Get a filter array with default values
* Optional view type parameter is used to initialize some fields properly,
* as some may differ in the default content.
* @param string $p_view_type "simple" or "advanced"
* @param string $p_view_type FILTER_VIEW_TYPE_SIMPLE or FILTER_VIEW_TYPE_ADVANCED
* @return array Filter array with default values
*/
function filter_get_default_array( $p_view_type = null ) {
static $t_cache_default_array = array();

$t_default_view_type = filter_get_default_view_type();
if( !in_array( $p_view_type, array( 'simple', 'advanced' ) ) ) {
if( !in_array( $p_view_type, array( FILTER_VIEW_TYPE_SIMPLE, FILTER_VIEW_TYPE_ADVANCED ) ) ) {
$p_view_type = $t_default_view_type;
}

Expand All @@ -766,14 +766,14 @@ function filter_get_default_array( $p_view_type = null ) {

$t_config_view_filters = config_get( 'view_filters' );
if( ADVANCED_ONLY == $t_config_view_filters ) {
$t_view_type = 'advanced';
$t_view_type = FILTER_VIEW_TYPE_ADVANCED;
} elseif( SIMPLE_ONLY == $t_config_view_filters ) {
$t_view_type = 'simple';
$t_view_type = FILTER_VIEW_TYPE_SIMPLE;
} else {
$t_view_type = $p_view_type;
}

if( $t_view_type == 'simple' ) {
if( $t_view_type == FILTER_VIEW_TYPE_SIMPLE ) {
$t_hide_status_default = config_get( 'hide_status_default' );
} else {
$t_hide_status_default = META_FILTER_NONE;
Expand Down Expand Up @@ -877,9 +877,9 @@ function filter_get_default_array( $p_view_type = null ) {
*/
function filter_get_default_view_type() {
if( ADVANCED_DEFAULT == config_get( 'view_filters' ) ) {
return 'advanced';
return FILTER_VIEW_TYPE_ADVANCED;
} else {
return 'simple';
return FILTER_VIEW_TYPE_SIMPLE;
}
}

Expand Down Expand Up @@ -1378,7 +1378,7 @@ function filter_get_bug_rows_query_clauses( array $p_filter, $p_project_id = nul
);

# normalize the project filtering into an array $t_project_ids
if( 'simple' == $t_view_type ) {
if( FILTER_VIEW_TYPE_SIMPLE == $t_view_type ) {
log_event( LOG_FILTERING, 'Simple Filter' );
$t_project_ids = array(
$t_project_id,
Expand Down Expand Up @@ -1682,7 +1682,7 @@ function filter_get_bug_rows_query_clauses( array $p_filter, $p_project_id = nul
$t_desired_statuses = $t_filter[FILTER_PROPERTY_STATUS];

# simple filtering: restrict by the hide status value if present
if( 'simple' == $t_filter['_view_type'] ) {
if( FILTER_VIEW_TYPE_SIMPLE == $t_filter['_view_type'] ) {
if( isset( $t_filter[FILTER_PROPERTY_HIDE_STATUS][0] ) && !filter_field_is_none( $t_filter[FILTER_PROPERTY_HIDE_STATUS][0] ) ) {
$t_selected_status_array = $t_filter[FILTER_PROPERTY_STATUS];
# if we have metavalue for "any", expand to all status, to filter them
Expand Down Expand Up @@ -2411,7 +2411,9 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
</h4>
<div class="widget-toolbar">
<?php
$f_switch_view_link = (config_get('use_dynamic_filters')) ? 'view_all_set.php?type=6&amp;view_type=' : 'view_filters_page.php?view_type=';
$f_switch_view_link = (config_get('use_dynamic_filters'))
? 'view_all_set.php?type=6&amp;view_type='
: 'view_filters_page.php?view_type=';
$t_view_filters = config_get('view_filters');

if( ( ( SIMPLE_ONLY != $t_view_filters ) && ( ADVANCED_ONLY != $t_view_filters ) ) ||
Expand All @@ -2425,10 +2427,10 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
<?php
if( ( SIMPLE_ONLY != $t_view_filters ) && ( ADVANCED_ONLY != $t_view_filters ) ) {
echo '<li>';
if( 'advanced' == $t_view_type ) {
echo '<a href="' . $f_switch_view_link, 'simple"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
if( FILTER_VIEW_TYPE_ADVANCED == $t_view_type ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link, 'advanced"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
echo '</li>';
}
Expand Down Expand Up @@ -3441,4 +3443,4 @@ function filter_is_accessible( $p_filter_id, $p_user_id = null ) {
}
}
return false;
}
}
14 changes: 8 additions & 6 deletions core/filter_form_api.php
Expand Up @@ -120,12 +120,12 @@ function filter_form_get_input( array $p_filter, $p_filter_target, $p_show_input


/**
* Return the input modifier to be used when a filter is of type "advanced"
* Return the input modifier to be used for advanced filters.
* @param array $p_filter Filter array to use
* @return string
*/
function filter_select_modifier( array $p_filter ) {
if( 'advanced' == $p_filter['_view_type'] ) {
if( FILTER_VIEW_TYPE_ADVANCED == $p_filter['_view_type'] ) {
return ' multiple="multiple" size="10"';
} else {
return '';
Expand Down Expand Up @@ -2359,7 +2359,9 @@ function filter_form_draw_inputs( $p_filter, $p_for_screen = true, $p_static = f
$t_get_params = $_GET;
$t_get_params['for_screen'] = $p_for_screen;
$t_get_params['static'] = ON;
$t_get_params['view_type'] = ( 'advanced' == $t_view_type ) ? 'advanced' : 'simple';
$t_get_params['view_type'] = ( FILTER_VIEW_TYPE_ADVANCED == $t_view_type )
? FILTER_VIEW_TYPE_ADVANCED
: FILTER_VIEW_TYPE_SIMPLE;
$t_filters_url .= '?' . http_build_query( $t_get_params );

$t_show_product_version = version_should_show_product_version( $t_project_id );
Expand Down Expand Up @@ -2468,7 +2470,7 @@ function filter_form_draw_inputs( $p_filter, $p_for_screen = true, $p_static = f
null /* class */,
'show_category_filter_target' /* content id */
));
if( 'simple' == $t_view_type ) {
if( FILTER_VIEW_TYPE_SIMPLE == $t_view_type ) {
$t_row2->add_item( new TableFieldsItem(
$get_field_header( 'hide_status_filter', lang_get( 'hide_status' ) ),
filter_form_get_input( $t_filter, 'hide_status', $t_show_inputs ),
Expand Down Expand Up @@ -2505,7 +2507,7 @@ function filter_form_draw_inputs( $p_filter, $p_for_screen = true, $p_static = f
null /* class */,
'do_filter_by_last_updated_date_filter_target' /* content id */
));
if( 'advanced' == $t_view_type ) {
if( FILTER_VIEW_TYPE_ADVANCED == $t_view_type ) {
$t_row2->add_item( new TableFieldsItem(
$get_field_header( 'project_id_filter', lang_get( 'email_project' ) ),
filter_form_get_input( $t_filter, 'project_id', $t_show_inputs ),
Expand Down Expand Up @@ -2754,4 +2756,4 @@ protected function render_td_empty_header( $p_colspan ) {
echo '&nbsp;';
echo '</td>';
}
}
}
6 changes: 3 additions & 3 deletions manage_filter_edit_page.php
Expand Up @@ -114,10 +114,10 @@
<?php
$f_switch_view_link = 'manage_filter_edit_page.php?filter_id=' . $f_filter_id . '&view_type=';
if( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
if( 'advanced' == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link, 'simple"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
if( FILTER_VIEW_TYPE_ADVANCED == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link, 'advanced"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
}
?>
Expand Down
Expand Up @@ -49,7 +49,7 @@
$t_page_count = 0;

$t_filter = current_user_get_bug_filter();
$t_filter['_view_type'] = 'advanced';
$t_filter['_view_type'] = FILTER_VIEW_TYPE_ADVANCED;
$t_filter[FILTER_PROPERTY_STATUS] = array(META_FILTER_ANY);
$t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = '';
$t_rows = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true );
Expand Down
2 changes: 1 addition & 1 deletion plugins/MantisGraph/pages/issues_trend_bystatus_table.php
Expand Up @@ -48,7 +48,7 @@
$t_page_count = 0;

$t_filter = current_user_get_bug_filter();
$t_filter['_view_type'] = 'advanced';
$t_filter['_view_type'] = FILTER_VIEW_TYPE_ADVANCED;
$t_filter[FILTER_PROPERTY_STATUS] = array( META_FILTER_ANY );
$t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = '';
$t_rows = filter_get_bug_rows( $f_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_filter, null, null, true );
Expand Down
2 changes: 1 addition & 1 deletion search.php
Expand Up @@ -140,7 +140,7 @@

# Must use advanced filter so that the project_id is applied and multiple
# selections are handled.
$t_my_filter['_view_type'] = 'advanced';
$t_my_filter['_view_type'] = FILTER_VIEW_TYPE_ADVANCED;

$t_setting_arr = filter_ensure_valid_filter( $t_my_filter );

Expand Down
6 changes: 3 additions & 3 deletions view_filters_page.php
Expand Up @@ -134,10 +134,10 @@
}
$f_switch_view_link .= '&view_type=';
if( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
if( 'advanced' == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link, 'simple"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
if( FILTER_VIEW_TYPE_ADVANCED == $t_filter['_view_type'] ) {
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_SIMPLE . '"><i class="ace-icon fa fa-toggle-off"></i>&#160;&#160;' . lang_get('simple_filters') . '</a>';
} else {
echo '<a href="' . $f_switch_view_link, 'advanced"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
echo '<a href="' . $f_switch_view_link . FILTER_VIEW_TYPE_ADVANCED . '"><i class="ace-icon fa fa-toggle-on"></i>&#160;&#160;' . lang_get('advanced_filters') . '</a>';
}
}
?>
Expand Down

0 comments on commit 7a663f4

Please sign in to comment.