From 361790ff7e4e4682c893e4274de286dcb4bd7831 Mon Sep 17 00:00:00 2001 From: buknon Date: Wed, 10 Jun 2009 16:14:04 +0200 Subject: [PATCH] Add full text search in profile related fields with autocomplete --- bug_report.php | 20 ++++++++++++++++++++ bug_report_advanced_page.php | 13 ++++++++++--- config_defaults_inc.php | 6 ++++++ core/projax_api.php | 18 ++++++++++++++++++ core/xmlhttprequest_api.php | 22 ++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/bug_report.php b/bug_report.php index 747af4f..30fcabe 100644 --- a/bug_report.php +++ b/bug_report.php @@ -77,6 +77,9 @@ $t_bug_data->target_version = access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_bug_data->project_id ) ? gpc_get_string( 'target_version', '' ) : ''; # if a profile was selected then let's use that information + + $t_profile = gpc_get_string('profile',""); + if ( 0 != $t_bug_data->profile_id ) { if ( profile_is_global( $t_bug_data->profile_id ) ) { $row = user_get_profile_row( ALL_USERS, $t_bug_data->profile_id ); @@ -93,7 +96,24 @@ if ( is_blank( $t_bug_data->os_build ) ) { $t_bug_data->os_build = $row['os_build']; } + } elseif ( $t_profile != "") { + if (!eregi("^[a-z0-9\.\-]*[_]{1}[a-z0-9\.\-]*[_]{1}[a-z0-9\.\-]*$", $t_profile)) { + error_parameters( lang_get_defaulted( 'Profil' )) ; + trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); + } else { + $t_profile_array=explode("_",$t_profile); + if ( is_blank( $t_bug_data->platform )) { + $t_bug_data->platform = $t_profile_array[0]; + } + if ( is_blank( $t_bug_data->os )) { + $t_bug_data->os = $t_profile_array[1]; + } + if ( is_blank( $t_bug_data->os_build )) { + $t_bug_data->os_build = $t_profile_array[2]; + } + } } + helper_call_custom_function( 'issue_create_validate', array( $t_bug_data ) ); # Validate the custom fields before adding the bug. diff --git a/bug_report_advanced_page.php b/bug_report_advanced_page.php index 9e1f1cb..103387c 100644 --- a/bug_report_advanced_page.php +++ b/bug_report_advanced_page.php @@ -237,11 +237,18 @@ - 0) { ?> + + $f_profile, 'size' => '32', 'maxlength' => '32', 'tabindex' => helper_get_tab_index_value() ) ); + } elseif (count(profile_get_all_for_user( auth_get_current_user_id() )) > 0) { + ?> - + > diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 2244b0f..e8cb2ea 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -3476,6 +3476,12 @@ * @global int $g_allow_freetext_in_profile_fields */ $g_allow_freetext_in_profile_fields = ON; + + /** + * Enable the full text search in profile related fields with autocomplete + * Work only when allow_freetext_in_profile_fields is enabled + */ + $g_allow_full_text_search_in_profile_fields = ON; /******************** * Twitter Settings * diff --git a/core/projax_api.php b/core/projax_api.php index 1ea3072..3f3e939 100644 --- a/core/projax_api.php +++ b/core/projax_api.php @@ -65,6 +65,24 @@ function projax_array_filter_by_prefix( $p_array, $p_prefix ) { return $t_matches; } +# Filters the provided array of strings and only returns the ones that containing $p_text. +# The comparison is not case sensitive. +# Returns the array of the filtered strings, or an empty array. If the input array has non-unique +# entries, then the output one may contain duplicates. +function projax_array_filter_full_text( $p_array, $p_text ) { + $t_matches = array(); + + foreach( $p_array as $t_entry ) { + if( strpos(strtolower($t_entry), $p_text ) !== FALSE ) { + $t_matches[] = $t_entry; + } + } + + return $t_matches; +} + + + # Serializes the provided array of strings into the format expected by the auto-complete library. function projax_array_serialize_for_autocomplete( $p_array ) { $t_matches = '