@@ -540,6 +540,9 @@ function filter_ensure_valid_filter( $p_filter_arr ) {
540
540
if ( !isset ( $ p_filter_arr [FILTER_PROPERTY_TAG_SELECT ] ) ) {
541
541
$ p_filter_arr [FILTER_PROPERTY_TAG_SELECT ] = gpc_get_string ( FILTER_PROPERTY_TAG_SELECT , '' );
542
542
}
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
+ }
543
546
544
547
# initialize plugin filters
545
548
$ t_plugin_filters = filter_get_plugin_filters ();
@@ -773,6 +776,7 @@ function filter_get_default() {
773
776
FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated ' ,
774
777
FILTER_PROPERTY_SORT_DIRECTION => 'DESC ' ,
775
778
FILTER_PROPERTY_ISSUES_PER_PAGE => config_get ( 'default_limit_view ' ),
779
+ FILTER_PROPERTY_MATCH_TYPE => FILTER_MATCH_ALL
776
780
);
777
781
778
782
return filter_ensure_valid_filter ( $ t_filter );
@@ -994,7 +998,12 @@ function filter_get_bug_count( $p_query_clauses ) {
994
998
$ t_select_string = "SELECT Count( DISTINCT $ t_bug_table.id ) as idcnt " ;
995
999
$ t_from_string = " FROM " . implode ( ', ' , $ p_query_clauses ['from ' ] );
996
1000
$ 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
+ }
998
1007
$ t_result = db_query_bound ( "$ t_select_string $ t_from_string $ t_join_string $ t_where_string " , $ p_query_clauses ['where_values ' ] );
999
1008
return db_result ( $ t_result );
1000
1009
}
@@ -1074,7 +1083,12 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
1074
1083
}
1075
1084
1076
1085
$ 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 (
1078
1092
"$ t_project_table.enabled = " . db_param (),
1079
1093
"$ t_project_table.id = $ t_bug_table.project_id " ,
1080
1094
);
@@ -1221,7 +1235,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
1221
1235
}
1222
1236
1223
1237
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 );
1225
1239
}
1226
1240
1227
1241
# view state
@@ -1989,6 +2003,14 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
1989
2003
}
1990
2004
1991
2005
# 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 );
1992
2014
1993
2015
$ t_from_clauses [] = $ t_project_table ;
1994
2016
$ 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
1998
2020
$ t_query_clauses ['join ' ] = $ t_join_clauses ;
1999
2021
$ t_query_clauses ['where ' ] = $ t_where_clauses ;
2000
2022
$ 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 ;
2001
2025
$ t_query_clauses = filter_get_query_sort_data ( $ t_filter , $ p_show_sticky , $ t_query_clauses );
2002
2026
2003
2027
# 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
2015
2039
$ t_from_string = " FROM " . implode ( ', ' , $ t_query_clauses ['from ' ] );
2016
2040
$ t_order_string = " ORDER BY " . implode ( ', ' , $ t_query_clauses ['order ' ] );
2017
2041
$ 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
+
2019
2050
$ 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 );
2020
2051
$ t_row_count = db_num_rows ( $ t_result );
2021
2052
@@ -3358,6 +3389,20 @@ function <?php echo $t_js_toggle_func;?>() {
3358
3389
}
3359
3390
?>
3360
3391
</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"> </td>
3405
+ </tr>
3361
3406
<?php
3362
3407
}
3363
3408
@@ -4269,6 +4314,17 @@ function print_filter_project_id() {
4269
4314
<?php
4270
4315
}
4271
4316
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
+
4272
4328
/**
4273
4329
* Prints a multi-value filter field.
4274
4330
* @param string $p_field_name
0 commit comments