diff --git a/Source/Source.FilterAPI.php b/Source/Source.FilterAPI.php index cc8a71b..873f1b9 100644 --- a/Source/Source.FilterAPI.php +++ b/Source/Source.FilterAPI.php @@ -40,12 +40,18 @@ function __construct( $init = true ) { if ( $init ) { + $this->filters['c.branch'] = new SourceFilterOption(); $this->filters['c.author'] = new SourceFilterOption(); $this->filters['c.message'] = new SourceFilterOption(); - $this->filters['c.repo_id'] = new SourceFilterOption(); + + $this->filters['r.id'] = new SourceFilterOption(); $this->filters['r.type'] = new SourceFilterOption(); + $this->filters['b.bug_id'] = new SourceFilterOption(); + $this->filters['f.filename'] = new SourceFilterOption(); + $this->filters['f.revision'] = new SourceFilterOption(); + $this->filters['f.action'] = new SourceFilterOption(); } } @@ -54,7 +60,7 @@ list ( $t_query_tail, $t_params ) = Source_Process_Filters( $t_filters, $t_filter_params ); $t_count_query = "SELECT COUNT(c.id) $t_query_tail"; - $t_full_query = "SELECT c.* $t_query_tail"; + $t_full_query = "SELECT DISTINCT( c.id ), c.* $t_query_tail"; $t_count = db_result( db_query_bound( $t_count_query, $t_params ) ); @@ -114,11 +120,13 @@ } $t_join = "FROM $t_changeset_table AS c LEFT JOIN $t_repo_table AS r ON c.repo_id=r.id" . - ( $t_join_bug_table ? ' LEFT JOIN $t_bug_table AS b ON c.id=b.change_id' : '' ) . - ( $t_join_file_table ? ' LEFT JOIN $t_file_table AS f ON c.id=f.change_id' : '' ); + ( $t_join_bug_table ? " LEFT JOIN $t_bug_table AS b ON c.id=b.change_id" : '' ) . + ( $t_join_file_table ? " LEFT JOIN $t_file_table AS f ON c.id=f.change_id" : '' ); if ( count( $t_where ) > 0 ) { $t_where = 'WHERE ' . implode( ' AND ', $t_where ); + } else { + $t_where = ''; } $t_order = 'ORDER BY c.timestamp DESC'; @@ -131,74 +139,304 @@ return null; } else { $how = $option->how; - $var = $option->value; + $value = $option->value; } - if ( is_null( $var ) ) { + if ( is_null( $value ) || ( !is_array( $value ) && is_blank( $value ) ) ) { return array( null, null ); } - $value = null; + $sql = null; $text = false; - # Full-text searching - if ( in_array( $key, array( 'c.author', 'c.message', 'c.revision', - 'c.branch', 'f.filename', 'f.revision' ) ) ) { - - if ( !is_array( $var ) ) { - $var = explode( ' ', $var ); - } - - $wc = map( 'db_aparam', $var ); - $wc = map( create_function( '$item','return "' . $key . ' LIKE $item";' ), $wc ); - $var = map( create_function( '$item', 'return "%$item%";' ), $var ); - - $value = '(' . implode( ' OR ', $wc ) . ')'; - - return array( $value, $var ); - } - # Date searching if ( $key == 'date_start' && !is_null( $value ) ) { $wc = db_aparam(); - $value = "c.timestamp >= $wc"; + $sql = "c.timestamp >= $wc"; - return array( $value, $var ); + return array( $sql, $value ); } if ( $key == 'date_end' && !is_null( $value ) ) { $wc = db_aparam(); - $value = "c.timestamp <= $wc"; + $sql = "c.timestamp <= $wc"; - return array( $value, $var ); + return array( $sql, $value ); + } + + # Revision Searching + if ( $key == 'f.revision' && !is_null( $value ) ) { + $wc1 = db_aparam(); + $wc2 = db_aparam(); + $value = "%$value%"; + $sql = "( c.revision LIKE $wc1 OR f.revision LIKE $wc2 )"; + + return array( $sql, array( $value, $value ) ); + } + + # Full-text searching + if ( in_array( $key, array( 'c.author', 'c.message', 'f.filename' ) ) ) { + + if ( !is_array( $value ) ) { + $value = explode( ' ', $value ); + } + + $wc = map( 'db_aparam', $value ); + $wc = map( create_function( '$item','return "' . $key . ' LIKE $item";' ), $wc ); + $value = map( create_function( '$item', 'return "%$item%";' ), $value ); + + $sql = '(' . implode( ' OR ', $wc ) . ')'; + + return array( $sql, $value ); } # Standard values - if ( is_array( $var ) ) { - $wc = map( 'db_aparam', $var ); + if ( is_array( $value ) ) { + $wc = map( 'db_aparam', $value ); - if ( count( $var ) > 1 ) { + if ( count( $value ) > 1 ) { if ( SOURCE_ANY == $how ) { - $value = $key . ' IN (' . implode( ',', $wc ) . ')'; + $sql = $key . ' IN (' . implode( ',', $wc ) . ')'; } else { - $value = $key . ' NOT IN (' . implode( ',', $wc ) . ')'; + $sql = $key . ' NOT IN (' . implode( ',', $wc ) . ')'; } } else { + $wc = $wc[0]; + if ( SOURCE_ANY == $how ) { - $value = "$key = $wc"; + $sql = "$key = $wc"; } else { - $value = "$key != $wc"; + $sql = "$key != $wc"; } } } else { $wc = db_aparam(); if ( SOURCE_ANY == $how ) { - $value = "$key = $wc"; + $sql = "$key = $wc"; } else { - $value = "$key != $wc"; + $sql = "$key != $wc"; } } - return array( $value, $var ); + return array( $sql, $value ); +} + +### Search filter input/link handling + +function Source_Generate_Filter() { + # Get form inputs + $f_repo_type = Source_FilterOption_Permalink( 'repo_type', true ); + $f_repo_id = Source_FilterOption_Permalink( 'repo_id', true ); + $f_branch = Source_FilterOption_Permalink( 'branch', true ); + $f_file_action = Source_FilterOption_Permalink( 'file_action', true ); + $f_user_id = Source_FilterOption_Permalink( 'user_id' ); + + $f_revision = Source_FilterOption_Permalink( 'revision' ); + $f_author = Source_FilterOption_Permalink( 'author' ); + $f_user_id = Source_FilterOption_Permalink( 'user_id' ); + + $f_filename = Source_FilterOption_Permalink( 'filename' ); + $f_message = Source_FilterOption_Permalink( 'message' ); + + # Get permalink + $t_permalink = Source_FilterOption_Permalink(); + + # Create filter + $t_filter = new SourceFilter(); + + $t_filter->filters['c.branch']->value = $f_branch; + $t_filter->filters['c.message']->value = $f_message; + $t_filter->filters['c.author']->value = $f_author; + $t_filter->filters['c.user_id']->value = $f_user_id; + + $t_filter->filters['r.id']->value = $f_repo_id; + $t_filter->filters['r.type']->value = $f_repo_type; + + $t_filter->filters['f.filename']->value = $f_filename; + $t_filter->filters['f.revision']->value = $f_revision; + $t_filter->filters['f.action']->value = $f_file_action; + + return array( $t_filter, $t_permalink ); +} + +function Source_FilterOption_Permalink( $p_string=null, $p_array=false ) { + static $s_permalink = ''; + + if ( is_null( $p_string ) ) { + $t_string = $s_permalink; + $s_permalink = ''; + return $t_string; + } + + if ( $p_array ) { + $t_input = gpc_get_string_array( $p_string, null ); + + if ( is_array( $t_input ) && count( $t_input ) > 0 ) { + foreach( $t_input as $t_value ) { + if ( !is_blank( $t_value ) ) { + $s_permalink .= "&${p_string}[]=$t_value"; + } + } + } + + } else { + $t_input = gpc_get_string( $p_string, null ); + if ( !is_blank( $t_input ) ) { + $s_permalink .= "&$p_string=$t_input"; + } + } + + return $t_input; +} + +### Search filter printing + +function Source_Repo_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_repo_table = plugin_table( 'repository' ); + + $t_query = "SELECT id,name FROM $t_repo_table ORDER BY name ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; +} + +function Source_Type_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_types = SourceTypes(); + $t_repo_table = plugin_table( 'repository' ); + + $t_query = "SELECT DISTINCT( type ) FROM $t_repo_table ORDER BY type ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; +} + +function Source_Branch_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_changeset_table = plugin_table( 'changeset' ); + + $t_query = "SELECT DISTINCT( branch ) FROM $t_changeset_table ORDER BY branch ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; +} + +function Source_Action_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_file_table = plugin_table( 'file' ); + + $t_query = "SELECT DISTINCT( action ) FROM $t_file_table ORDER BY action ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; +} + +function Source_Author_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_changeset_table = plugin_table( 'changeset' ); + $t_user_table = db_get_table( 'mantis_user_table' ); + + $t_query = "SELECT DISTINCT( author ) FROM $t_changeset_table ORDER BY author ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; +} + +function Source_Username_Select( $p_selected=null ) { + if ( !is_array( $p_selected ) ) { + $t_selected = array( $p_selected ); + } else { + $t_selected = $p_selected; + } + + $t_changeset_table = plugin_table( 'changeset' ); + $t_user_table = db_get_table( 'mantis_user_table' ); + + $t_query = "SELECT DISTINCT( c.user_id ), u.username FROM $t_changeset_table AS c + JOIN $t_user_table AS u ON c.user_id=u.id ORDER BY u.username ASC"; + $t_result = db_query_bound( $t_query ); + + echo ''; } diff --git a/Source/pages/index.php b/Source/pages/index.php index fde931c..f48eba8 100644 --- a/Source/pages/index.php +++ b/Source/pages/index.php @@ -26,7 +26,7 @@ - + diff --git a/Source/pages/search.php b/Source/pages/search.php index c5831cb..deceb17 100644 --- a/Source/pages/search.php +++ b/Source/pages/search.php @@ -16,19 +16,16 @@ $f_offset = gpc_get_int( 'offset', 1 ); $f_perpage = 25; -html_page_top1( plugin_lang_get( 'title' ) ); -html_page_top2(); - require_once( config_get( 'plugin_path' ) . 'Source' . DIRECTORY_SEPARATOR . 'Source.FilterAPI.php' ); -$t_filter = new SourceFilter(); - -$t_filter->filters['c.author']->value = "jreese"; -$t_filter->filters['c.message']->value = "test"; - +# Generate listing +list( $t_filter, $t_permalink ) = Source_Generate_Filter(); list( $t_changesets, $t_count ) = $t_filter->find( $f_offset ); $t_repos = SourceRepo::load_by_changesets( $t_changesets ); +html_page_top1( plugin_lang_get( 'title' ) ); +html_page_top2(); + ?>
@@ -36,7 +33,13 @@ - + + + ', $t_page, ''; + echo ' ', $t_page, ''; } if ( $t_page % 15 == 0 ) { diff --git a/Source/pages/search_page.php b/Source/pages/search_page.php new file mode 100644 index 0000000..e0267b9 --- /dev/null +++ b/Source/pages/search_page.php @@ -0,0 +1,87 @@ + + +
+
+ + + + + + + + + + + + + + +> + + + + + + + + + + + + + + +> + + + + + + + +> + + + + +> + + + + + + + + +
+ +
Source ControlRepositoriesBranchesAction
filters['r.type']->value ) ?>filters['r.id']->value ) ?>filters['c.branch']->value ) ?>filters['f.action']->value ) ?>
RevisionAuthorUsername
filters['c.author']->value ) ?>filters['c.user_id']->value ) ?>
Message
Filenames
+
+ +