Skip to content

Commit

Permalink
Fix #6809: 0005598: Using an 'Or' filter logic
Browse files Browse the repository at this point in the history
Conflicts:
	config_filter_defaults_inc.php
	core/filter_api.php
	lang/strings_english.txt
	view_all_set.php
  • Loading branch information
rombert committed Sep 22, 2012
1 parent af25679 commit 6c6c3d7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/constant_inc.php
Expand Up @@ -436,6 +436,10 @@
define( 'FILTER_TYPE_MULTI_STRING', 3 );
define( 'FILTER_TYPE_MULTI_INT', 4 );

# Filter match types
define( 'FILTER_MATCH_ALL', 0);
define( 'FILTER_MATCH_ANY', 1);

# Versions
define( 'VERSION_ALL', null );
define( 'VERSION_FUTURE', 0 );
Expand Down
64 changes: 60 additions & 4 deletions core/filter_api.php
Expand Up @@ -563,6 +563,9 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
if( !isset( $p_filter_arr[FILTER_PROPERTY_TAG_SELECT] ) ) {
$p_filter_arr[FILTER_PROPERTY_TAG_SELECT] = gpc_get_string( FILTER_PROPERTY_TAG_SELECT, '' );
}
if( !isset( $p_filter_arr[FILTER_PROPERTY_MATCH_TYPE] ) ) {
$p_filter_arr[FILTER_PROPERTY_MATCH_TYPE] = gpc_get_int( FILTER_PROPERTY_MATCH_TYPE, FILTER_MATCH_ALL );
}

# initialize plugin filters
$t_plugin_filters = filter_get_plugin_filters();
Expand Down Expand Up @@ -796,6 +799,7 @@ function filter_get_default() {
FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated',
FILTER_PROPERTY_SORT_DIRECTION => 'DESC',
FILTER_PROPERTY_ISSUES_PER_PAGE => config_get( 'default_limit_view' ),
FILTER_PROPERTY_MATCH_TYPE => FILTER_MATCH_ALL
);

return filter_ensure_valid_filter( $t_filter );
Expand Down Expand Up @@ -1018,7 +1022,12 @@ function filter_get_bug_count( $p_query_clauses ) {
$t_select_string = "SELECT Count( DISTINCT $t_bug_table.id ) as idcnt ";
$t_from_string = " FROM " . implode( ', ', $p_query_clauses['from'] );
$t_join_string = (( count( $p_query_clauses['join'] ) > 0 ) ? implode( ' ', $p_query_clauses['join'] ) : '' );
$t_where_string = (( count( $p_query_clauses['where'] ) > 0 ) ? 'WHERE ' . implode( ' AND ', $p_query_clauses['where'] ) : '' );
$t_where_string = count( $p_query_clauses['project_where']) > 0 ? 'WHERE '. implode( ' AND ', $p_query_clauses['project_where'] ) : '';
if ( count( $p_query_clauses['where'] ) > 0 ) {
$t_where_string .= ' AND ( ';
$t_where_string .= implode( $p_query_clauses['operator'], $p_query_clauses['where'] );
$t_where_string .= ' ) ';
}
$t_result = db_query_bound( "$t_select_string $t_from_string $t_join_string $t_where_string", $p_query_clauses['where_values'] );
return db_result( $t_result );
}
Expand Down Expand Up @@ -1098,7 +1107,12 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
}

$t_view_type = $t_filter['_view_type'];
$t_where_clauses = array(

// project query clauses must be AND-ed always, irrespective of how the filter
// clauses are requested by the user ( all matching -> AND, any matching -> OR )
$t_where_clauses = array();

$t_project_where_clauses = array(
"$t_project_table.enabled = " . db_param(),
"$t_project_table.id = $t_bug_table.project_id",
);
Expand Down Expand Up @@ -1245,7 +1259,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
}

log_event( LOG_FILTERING, 'project query = ' . $t_project_query );
array_push( $t_where_clauses, $t_project_query );
array_push( $t_project_where_clauses, $t_project_query );
}

# view state
Expand Down Expand Up @@ -2014,6 +2028,14 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
}

# End text search

# Determine join operator
if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY )
$t_join_operator = ' OR ';
else
$t_join_operator = ' AND ';

log_event(LOG_FILTERING, 'Join operator : ' . $t_join_operator);

$t_from_clauses[] = $t_project_table;
$t_from_clauses[] = $t_bug_table;
Expand All @@ -2023,6 +2045,8 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_query_clauses['join'] = $t_join_clauses;
$t_query_clauses['where'] = $t_where_clauses;
$t_query_clauses['where_values'] = $t_where_params;
$t_query_clauses['project_where'] = $t_project_where_clauses;
$t_query_clauses['operator'] = $t_join_operator;
$t_query_clauses = filter_get_query_sort_data( $t_filter, $p_show_sticky, $t_query_clauses );

# assigning to $p_* for this function writes the values back in case the caller wants to know
Expand All @@ -2040,7 +2064,14 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_from_string = " FROM " . implode( ', ', $t_query_clauses['from'] );
$t_order_string = " ORDER BY " . implode( ', ', $t_query_clauses['order'] );
$t_join_string = count( $t_query_clauses['join'] ) > 0 ? implode( ' ', $t_query_clauses['join'] ) : '';
$t_where_string = count( $t_query_clauses['where'] ) > 0 ? 'WHERE ' . implode( ' AND ', $t_query_clauses['where'] ) : '';
$t_where_string = 'WHERE '. implode( ' AND ', $t_query_clauses['project_where'] );
if ( count( $t_query_clauses['where'] ) > 0 ) {
$t_where_string .= ' AND ( ';
$t_where_string .= implode( $t_join_operator, $t_query_clauses['where'] );
$t_where_string .= ' ) ';
}


$t_result = db_query_bound( "$t_select_string $t_from_string $t_join_string $t_where_string $t_order_string", $t_query_clauses['where_values'], $p_per_page, $t_offset );
$t_row_count = db_num_rows( $t_result );

Expand Down Expand Up @@ -3353,6 +3384,20 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
}
?>
</tr>
<tr class="row-1">
<td class="small-caption"><a href="<?php echo $t_filters_url . FILTER_PROPERTY_MATCH_TYPE;?>" id="match_type_filter"><?php echo lang_get( 'filter_match_type' )?>:</a></td>
<td class="small-caption" id="match_type_filter_target">
<?php
if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY ) {
echo lang_get ('filter_match_any');
} else if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ALL ) {
echo lang_get ('filter_match_all');
}
?>
<input type="hidden" name="match_type" value="<?php echo $t_filter[FILTER_PROPERTY_MATCH_TYPE]?>"/>
</td>
<td colspan="6">&#160;</td>
</tr>
</table>
<?php
}
Expand Down Expand Up @@ -4243,6 +4288,17 @@ function print_filter_project_id() {
<?php
}

function print_filter_match_type() {
global $t_select_modifier, $t_filter, $f_view_type;
?>
<!-- Project -->
<select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_MATCH_TYPE;?>">
<option value="<?php echo FILTER_MATCH_ALL?>" <?php check_selected( $t_filter[FILTER_PROPERTY_MATCH_TYPE], FILTER_MATCH_ALL );?>>[<?php echo lang_get( 'filter_match_all' )?>]</option>
<option value="<?php echo FILTER_MATCH_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_MATCH_TYPE], FILTER_MATCH_ANY );?>>[<?php echo lang_get( 'filter_match_any' )?>]</option>
</select>
<?php
}

/**
* Prints a multi-value filter field.
* @param string $p_field_name
Expand Down
1 change: 1 addition & 0 deletions core/filter_constants_inc.php
Expand Up @@ -42,6 +42,7 @@
define( 'FILTER_PROPERTY_RELATIONSHIP_BUG', 'relationship_bug' );
define( 'FILTER_PROPERTY_TAG_STRING', 'tag_string' );
define( 'FILTER_PROPERTY_TAG_SELECT', 'tag_select' );
define( 'FILTER_PROPERTY_MATCH_TYPE', 'match_type');

define( 'FILTER_PROPERTY_NOTE_USER_ID', 'note_user_id' );
define( 'FILTER_PROPERTY_MONITOR_USER_ID', 'monitor_user_id' ); # user_monitor
Expand Down
3 changes: 3 additions & 0 deletions lang/strings_english.txt
Expand Up @@ -1131,6 +1131,9 @@ If you requested this verification, visit the following URL to change your passw
'recently_visited' => 'Recently Visited',
'priority_abbreviation' => 'P',
'note_user_id_label' => 'Note By:',
'filter_match_type' => 'Match Type',
'filter_match_all' => 'All Conditions',
'filter_match_any' => 'Any Condition',

# view_all_inc.php
'none' => 'none',
Expand Down
3 changes: 3 additions & 0 deletions view_all_set.php
Expand Up @@ -233,6 +233,8 @@
$f_note_user_id = array( $f_note_user_id );
}

$f_match_type = gpc_get_string ( FILTER_PROPERTY_MATCH_TYPE, FILTER_MATCH_ALL );

# these are only single values, even when doing advanced filtering
$f_per_page = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, -1 );
$f_highlight_changed = gpc_get_int( FILTER_PROPERTY_HIGHLIGHT_CHANGED, config_get( 'default_show_changed' ) );
Expand Down Expand Up @@ -498,6 +500,7 @@
$t_setting_arr[ FILTER_PROPERTY_TAG_STRING ] = $f_tag_string;
$t_setting_arr[ FILTER_PROPERTY_TAG_SELECT ] = $f_tag_select;
$t_setting_arr[ FILTER_PROPERTY_NOTE_USER_ID ] = $f_note_user_id;
$t_setting_arr[ FILTER_PROPERTY_MATCH_TYPE ] = $f_match_type;
$t_setting_arr = array_merge( $t_setting_arr, $f_filter_input );
break;
# Set the sort order and direction
Expand Down

0 comments on commit 6c6c3d7

Please sign in to comment.