/** * Get set of bug rows from given filter * @todo Had to make all these parameters required because we can't use call-time pass by reference anymore. * I really preferred not having to pass all the params in if you didn't want to, but I wanted to get * rid of the errors for now. If we can think of a better way later (maybe return an object) that would be great. * * @param integer &$p_page_number Page number of the page you want to see (set to the actual page on return). * @param integer &$p_per_page The number of bugs to see per page (set to actual on return) * -1 indicates you want to see all bugs * null indicates you want to use the value specified in the filter. * @param integer &$p_page_count You don't need to give a value here, the number of pages will be stored here on return. * @param integer &$p_bug_count You don't need to give a value here, the number of bugs will be stored here on return. * @param mixed $p_custom_filter Custom Filter to use. * @param integer $p_project_id Project id to use in filtering. * @param integer $p_user_id User id to use as current user when filtering. * @param boolean $p_show_sticky True/false - get sticky issues only. * @return boolean|array */ function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null) { # assigning to $p_* for this function writes the values back in case the caller wants to know if ($p_custom_filter === null) { $t_filter = filter_get_bug_rows_filter($p_project_id, $p_user_id); } else { $t_filter = $p_custom_filter; } # Get the query clauses $t_query_clauses = filter_get_bug_rows_query_clauses($t_filter, $p_project_id, $p_user_id, $p_show_sticky); # Get the total number of bugs that meet the criteria. # Keep the db_params in stack for next query $p_bug_count = filter_get_bug_count($t_query_clauses, false); if (0 == $p_bug_count) { # reset the db_param stack that was initialized by "filter_get_bug_rows_query_clauses()" db_param_pop(); return array(); } # Calculate pagination $p_per_page = filter_per_page($t_filter, $p_bug_count, $p_per_page); $p_page_count = filter_page_count($p_bug_count, $p_per_page); $p_page_number = filter_valid_page_number($p_page_number, $p_page_count); $t_offset = filter_offset($p_page_number, $p_per_page); # Execute query $t_result = filter_get_bug_rows_result($t_query_clauses, $p_per_page, $t_offset); # Read results into rows array $t_bug_id_array = array(); while ($t_row = db_fetch_array($t_result)) { $t_bug_id_array[] = (int) $t_row['id']; $t_rows[] = $t_row; } # Return the processed rows: cache data, convert to bug objects return filter_cache_result($t_rows, $t_bug_id_array); }
/** * Creates and executes a query for the history rows related to bugs matched by the provided filter * @param array $p_filter Filter array * @param integer $p_start_time The start time to filter by, or null for all. * @param integer $p_end_time The end time to filter by, or null for all. * @param string $p_history_order The sort order. * @return database result to pass into history_get_event_from_row(). */ function history_get_range_result_filter($p_filter, $p_start_time = null, $p_end_time = null, $p_history_order = null) { if ($p_history_order === null) { $t_history_order = config_get('history_order'); } else { $t_history_order = $p_history_order; } # Note: filter_get_bug_rows_query_clauses() calls db_param_push(); $t_query_clauses = filter_get_bug_rows_query_clauses($p_filter, null, null, null); # if the query can't be formed, there are no results if (empty($t_query_clauses)) { # reset the db_param stack that was initialized by "filter_get_bug_rows_query_clauses()" db_param_pop(); return db_empty_result(); } $t_select_string = 'SELECT DISTINCT {bug}.id '; $t_from_string = ' FROM ' . implode(', ', $t_query_clauses['from']); $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : ' '; $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_query_clauses['operator'], $t_query_clauses['where']); $t_where_string .= ' ) '; } $t_query = 'SELECT * FROM {bug_history} JOIN' . ' ( ' . $t_select_string . $t_from_string . $t_join_string . $t_where_string . ' ) B' . ' ON {bug_history}.bug_id=B.id'; $t_params = $t_query_clauses['where_values']; $t_where = array(); if ($p_start_time !== null) { $t_where[] = 'date_modified >= ' . db_param(); $t_params[] = $p_start_time; } if ($p_end_time !== null) { $t_where[] = 'date_modified < ' . db_param(); $t_params[] = $p_end_time; } if (count($t_where) > 0) { $t_query .= ' WHERE ' . implode(' AND ', $t_where); } $t_query .= ' ORDER BY {bug_history}.date_modified ' . $t_history_order . ', {bug_history}.id ' . $t_history_order; $t_result = db_query($t_query, $t_params); return $t_result; }
require_api('authentication_api.php'); require_api('columns_api.php'); require_api('constant_inc.php'); require_api('csv_api.php'); require_api('file_api.php'); require_api('filter_api.php'); require_api('helper_api.php'); require_api('print_api.php'); auth_ensure_user_authenticated(); helper_begin_long_process(); $t_nl = csv_get_newline(); $t_sep = csv_get_separator(); # Get current filter $t_filter = filter_get_bug_rows_filter(); # Get the query clauses $t_query_clauses = filter_get_bug_rows_query_clauses($t_filter); # Get the total number of bugs that meet the criteria. $p_bug_count = filter_get_bug_count($t_query_clauses, false); if (0 == $p_bug_count) { print_header_redirect('view_all_set.php?type=0'); } # Execute query $t_result = filter_get_bug_rows_result($t_query_clauses); # Get columns to be exported $t_columns = csv_get_columns(); csv_start(csv_get_default_filename()); # export the titles $t_first_column = true; ob_start(); $t_titles = array(); foreach ($t_columns as $t_column) {