Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5b49186

Browse files
committedSep 22, 2012
Fix #6809: 0005598: Using an 'Or' filter logic
1 parent 9de2566 commit 5b49186

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed
 

‎config_filter_defaults_inc.php

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
define( 'FILTER_PROPERTY_RELATIONSHIP_BUG', 'relationship_bug' );
6464
define( 'FILTER_PROPERTY_TAG_STRING', 'tag_string' );
6565
define( 'FILTER_PROPERTY_TAG_SELECT', 'tag_select' );
66+
define( 'FILTER_PROPERTY_MATCH_TYPE', 'match_type');
6667

6768
###########################################################################
6869
# Filter Query Parameter Names

‎core/constant_inc.php

+4
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@
430430
define( 'FILTER_TYPE_MULTI_STRING', 3 );
431431
define( 'FILTER_TYPE_MULTI_INT', 4 );
432432

433+
# Filter match types
434+
define( 'FILTER_MATCH_ALL', 0);
435+
define( 'FILTER_MATCH_ANY', 1);
436+
433437
# Versions
434438
define( 'VERSION_ALL', null );
435439
define( 'VERSION_FUTURE', 0 );

‎core/filter_api.php

+60-4
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
540540
if( !isset( $p_filter_arr[FILTER_PROPERTY_TAG_SELECT] ) ) {
541541
$p_filter_arr[FILTER_PROPERTY_TAG_SELECT] = gpc_get_string( FILTER_PROPERTY_TAG_SELECT, '' );
542542
}
543+
if( !isset( $p_filter_arr[FILTER_PROPERTY_MATCH_TYPE] ) ) {
544+
$p_filter_arr[FILTER_PROPERTY_MATCH_TYPE] = gpc_get_int( FILTER_PROPERTY_MATCH_TYPE, FILTER_MATCH_ALL );
545+
}
543546

544547
# initialize plugin filters
545548
$t_plugin_filters = filter_get_plugin_filters();
@@ -773,6 +776,7 @@ function filter_get_default() {
773776
FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated',
774777
FILTER_PROPERTY_SORT_DIRECTION => 'DESC',
775778
FILTER_PROPERTY_ISSUES_PER_PAGE => config_get( 'default_limit_view' ),
779+
FILTER_PROPERTY_MATCH_TYPE => FILTER_MATCH_ALL
776780
);
777781

778782
return filter_ensure_valid_filter( $t_filter );
@@ -994,7 +998,12 @@ function filter_get_bug_count( $p_query_clauses ) {
994998
$t_select_string = "SELECT Count( DISTINCT $t_bug_table.id ) as idcnt ";
995999
$t_from_string = " FROM " . implode( ', ', $p_query_clauses['from'] );
9961000
$t_join_string = (( count( $p_query_clauses['join'] ) > 0 ) ? implode( ' ', $p_query_clauses['join'] ) : '' );
997-
$t_where_string = (( count( $p_query_clauses['where'] ) > 0 ) ? 'WHERE ' . implode( ' AND ', $p_query_clauses['where'] ) : '' );
1001+
$t_where_string = count( $p_query_clauses['project_where']) > 0 ? 'WHERE '. implode( ' AND ', $p_query_clauses['project_where'] ) : '';
1002+
if ( count( $p_query_clauses['where'] ) > 0 ) {
1003+
$t_where_string .= ' AND ( ';
1004+
$t_where_string .= implode( $p_query_clauses['operator'], $p_query_clauses['where'] );
1005+
$t_where_string .= ' ) ';
1006+
}
9981007
$t_result = db_query_bound( "$t_select_string $t_from_string $t_join_string $t_where_string", $p_query_clauses['where_values'] );
9991008
return db_result( $t_result );
10001009
}
@@ -1074,7 +1083,12 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
10741083
}
10751084

10761085
$t_view_type = $t_filter['_view_type'];
1077-
$t_where_clauses = array(
1086+
1087+
// project query clauses must be AND-ed always, irrespective of how the filter
1088+
// clauses are requested by the user ( all matching -> AND, any matching -> OR )
1089+
$t_where_clauses = array();
1090+
1091+
$t_project_where_clauses = array(
10781092
"$t_project_table.enabled = " . db_param(),
10791093
"$t_project_table.id = $t_bug_table.project_id",
10801094
);
@@ -1221,7 +1235,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
12211235
}
12221236

12231237
log_event( LOG_FILTERING, 'project query = ' . $t_project_query );
1224-
array_push( $t_where_clauses, $t_project_query );
1238+
array_push( $t_project_where_clauses, $t_project_query );
12251239
}
12261240

12271241
# view state
@@ -1989,6 +2003,14 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
19892003
}
19902004

19912005
# End text search
2006+
2007+
# Determine join operator
2008+
if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY )
2009+
$t_join_operator = ' OR ';
2010+
else
2011+
$t_join_operator = ' AND ';
2012+
2013+
log_event(LOG_FILTERING, 'Join operator : ' . $t_join_operator);
19922014

19932015
$t_from_clauses[] = $t_project_table;
19942016
$t_from_clauses[] = $t_bug_table;
@@ -1998,6 +2020,8 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
19982020
$t_query_clauses['join'] = $t_join_clauses;
19992021
$t_query_clauses['where'] = $t_where_clauses;
20002022
$t_query_clauses['where_values'] = $t_where_params;
2023+
$t_query_clauses['project_where'] = $t_project_where_clauses;
2024+
$t_query_clauses['operator'] = $t_join_operator;
20012025
$t_query_clauses = filter_get_query_sort_data( $t_filter, $p_show_sticky, $t_query_clauses );
20022026

20032027
# assigning to $p_* for this function writes the values back in case the caller wants to know
@@ -2015,7 +2039,14 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
20152039
$t_from_string = " FROM " . implode( ', ', $t_query_clauses['from'] );
20162040
$t_order_string = " ORDER BY " . implode( ', ', $t_query_clauses['order'] );
20172041
$t_join_string = count( $t_query_clauses['join'] ) > 0 ? implode( ' ', $t_query_clauses['join'] ) : '';
2018-
$t_where_string = count( $t_query_clauses['where'] ) > 0 ? 'WHERE ' . implode( ' AND ', $t_query_clauses['where'] ) : '';
2042+
$t_where_string = 'WHERE '. implode( ' AND ', $t_query_clauses['project_where'] );
2043+
if ( count( $t_query_clauses['where'] ) > 0 ) {
2044+
$t_where_string .= ' AND ( ';
2045+
$t_where_string .= implode( $t_join_operator, $t_query_clauses['where'] );
2046+
$t_where_string .= ' ) ';
2047+
}
2048+
2049+
20192050
$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 );
20202051
$t_row_count = db_num_rows( $t_result );
20212052

@@ -3358,6 +3389,20 @@ function <?php echo $t_js_toggle_func;?>() {
33583389
}
33593390
?>
33603391
</tr>
3392+
<tr class="row-1">
3393+
<td class="small-caption" valign="top"><a href="<?php echo $t_filters_url . FILTER_PROPERTY_MATCH_TYPE;?>" id="match_type_filter"><?php echo lang_get( 'filter_match_type' )?>:</a></td>
3394+
<td class="small-caption" valign="top" id="match_type_filter_target">
3395+
<?php
3396+
if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY ) {
3397+
echo lang_get ('filter_match_any');
3398+
} else if ( $t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ALL ) {
3399+
echo lang_get ('filter_match_all');
3400+
}
3401+
?>
3402+
<input type="hidden" name="match_type" value="<?php echo $t_filter[FILTER_PROPERTY_MATCH_TYPE]?>"/>
3403+
</td>
3404+
<td colspan="6">&#160;</td>
3405+
</tr>
33613406
<?php
33623407
}
33633408

@@ -4269,6 +4314,17 @@ function print_filter_project_id() {
42694314
<?php
42704315
}
42714316

4317+
function print_filter_match_type() {
4318+
global $t_select_modifier, $t_filter, $f_view_type;
4319+
?>
4320+
<!-- Project -->
4321+
<select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_MATCH_TYPE;?>">
4322+
<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>
4323+
<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>
4324+
</select>
4325+
<?php
4326+
}
4327+
42724328
/**
42734329
* Prints a multi-value filter field.
42744330
* @param string $p_field_name

‎lang/strings_english.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,9 @@ $s_issue_id = 'Issue #';
12081208
$s_recently_visited = 'Recently Visited';
12091209
$s_priority_abbreviation = 'P';
12101210
$s_note_user_id = 'Note By';
1211+
$s_filter_match_type = 'Match Type';
1212+
$s_filter_match_all = 'All Conditions';
1213+
$s_filter_match_any = 'Any Condition';
12111214

12121215
# view_all_inc.php
12131216
$s_none = 'none';

‎view_all_set.php

+3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
$f_note_user_id = gpc_get_string( FILTER_PROPERTY_NOTE_USER_ID, META_FILTER_ANY );
202202
$f_note_user_id = array( $f_note_user_id );
203203
}
204+
205+
$f_match_type = gpc_get_string ( FILTER_PROPERTY_MATCH_TYPE, FILTER_MATCH_ALL );
204206

205207
# these are only single values, even when doing advanced filtering
206208
$f_per_page = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, -1 );
@@ -474,6 +476,7 @@
474476
$t_setting_arr[ FILTER_PROPERTY_TAG_STRING ] = $f_tag_string;
475477
$t_setting_arr[ FILTER_PROPERTY_TAG_SELECT ] = $f_tag_select;
476478
$t_setting_arr[ FILTER_PROPERTY_NOTE_USER_ID ] = $f_note_user_id;
479+
$t_setting_arr[ FILTER_PROPERTY_MATCH_TYPE ] = $f_match_type;
477480
$t_setting_arr = array_merge( $t_setting_arr, $f_filter_input );
478481
break;
479482
# Set the sort order and direction

0 commit comments

Comments
 (0)
Please sign in to comment.