function news_get_limited_rows($p_offset, $p_project_id = null) { if ($p_project_id === null) { $p_project_id = helper_get_current_project(); } $c_offset = db_prepare_int($p_offset); $t_projects = current_user_get_all_accessible_subprojects($p_project_id); $t_projects[] = (int) $p_project_id; if (ALL_PROJECTS != $p_project_id) { $t_projects[] = ALL_PROJECTS; } $t_news_table = db_get_table('mantis_news_table'); $t_news_view_limit = config_get('news_view_limit'); $t_news_view_limit_days = config_get('news_view_limit_days') * SECONDS_PER_DAY; switch (config_get('news_limit_method')) { case 0: # BY_LIMIT - Select the news posts $query = "SELECT *\n\t\t\t\t\t\tFROM {$t_news_table}"; if (1 == count($t_projects)) { $c_project_id = $t_projects[0]; $query .= " WHERE project_id='{$c_project_id}'"; } else { $query .= ' WHERE project_id IN (' . join($t_projects, ',') . ')'; } $query .= ' ORDER BY announcement DESC, id DESC'; $result = db_query($query, $t_news_view_limit, $c_offset); break; case 1: # BY_DATE - Select the news posts $query = "SELECT *\n\t\t\t\t\t\tFROM {$t_news_table} WHERE\n\t\t\t\t\t\t( " . db_helper_compare_days(0, 'date_posted', "< {$t_news_view_limit_days}") . "\n\t\t\t\t\t\t OR announcement = " . db_param() . " ) "; $t_params = array(db_now(), 1); if (1 == count($t_projects)) { $c_project_id = $t_projects[0]; $query .= " AND project_id=" . db_param(); $t_params[] = $c_project_id; } else { $query .= ' AND project_id IN (' . join($t_projects, ',') . ')'; } $query .= " ORDER BY announcement DESC, id DESC"; $result = db_query_bound($query, $t_params, $t_news_view_limit, $c_offset); break; } # end switch $t_row_count = db_num_rows($result); $t_rows = array(); for ($i = 0; $i < $t_row_count; $i++) { $row = db_fetch_array($result); array_push($t_rows, $row); } return $t_rows; }
/** * Gets a limited set of news rows to be viewed on one page based on the criteria * defined in the configuration file. * * @param integer $p_offset Offset. * @param integer $p_project_id A project identifier. * @return array */ function news_get_limited_rows($p_offset, $p_project_id = null) { if ($p_project_id === null) { $p_project_id = helper_get_current_project(); } $c_offset = (int) $p_offset; $t_projects = current_user_get_all_accessible_subprojects($p_project_id); $t_projects[] = (int) $p_project_id; if (ALL_PROJECTS != $p_project_id) { $t_projects[] = ALL_PROJECTS; } $t_news_view_limit = config_get('news_view_limit'); $t_news_view_limit_days = config_get('news_view_limit_days') * SECONDS_PER_DAY; switch (config_get('news_limit_method')) { case 0: db_param_push(); # BY_LIMIT - Select the news posts $t_query = 'SELECT * FROM {news}'; if (1 == count($t_projects)) { $c_project_id = $t_projects[0]; $t_query .= ' WHERE project_id=' . db_param(); $t_params = array($c_project_id); } else { $t_query .= ' WHERE project_id IN (' . join($t_projects, ',') . ')'; $t_params = null; } $t_query .= ' ORDER BY announcement DESC, id DESC'; $t_result = db_query($t_query, $t_params, $t_news_view_limit, $c_offset); break; case 1: db_param_push(); # BY_DATE - Select the news posts $t_query = 'SELECT * FROM {news} WHERE ( ' . db_helper_compare_time(db_param(), '<', 'date_posted', $t_news_view_limit_days) . ' OR announcement = ' . db_param() . ' ) '; $t_params = array(db_now(), 1); if (1 == count($t_projects)) { $c_project_id = $t_projects[0]; $t_query .= ' AND project_id=' . db_param(); $t_params[] = $c_project_id; } else { $t_query .= ' AND project_id IN (' . join($t_projects, ',') . ')'; } $t_query .= ' ORDER BY announcement DESC, id DESC'; $t_result = db_query($t_query, $t_params, $t_news_view_limit, $c_offset); break; } $t_rows = array(); while ($t_row = db_fetch_array($t_result)) { array_push($t_rows, $t_row); } return $t_rows; }
function print_category_filter_option_list($p_category_name = '', $p_project_id = null) { $t_category_table = db_get_table('category'); $t_project_table = db_get_table('project'); if (null === $p_project_id) { $c_project_id = helper_get_current_project(); } else { $c_project_id = db_prepare_int($p_project_id); } $t_project_ids = project_hierarchy_inheritance($c_project_id); $t_subproject_ids = array(); foreach ($t_project_ids as $t_project_id) { $t_subproject_ids = array_merge($t_subproject_ids, current_user_get_all_accessible_subprojects($t_project_id)); } $t_project_ids = array_merge($t_project_ids, $t_subproject_ids); $t_project_where = ' project_id IN ( ' . implode(', ', $t_project_ids) . ' ) '; # grab all categories in the project category table $cat_arr = array(); $query = "SELECT DISTINCT name FROM {$t_category_table}\n\t\t\t\tWHERE {$t_project_where}\n\t\t\t\tORDER BY name"; $result = db_query($query); while ($row = db_fetch_array($result)) { $cat_arr[] = $row['name']; } sort($cat_arr); foreach ($cat_arr as $t_name) { $t_name = string_attribute($t_name); echo '<option value="' . $t_name . '"'; check_selected(string_attribute($p_category_name), $t_name); echo '>' . $t_name . '</option>'; } }
/** * Get a distinct array of categories accessible to the current user for * the specified projects. If no project is specified, use the current project. * If the current project is ALL_PROJECTS get all categories for all accessible projects. * For all cases, get global categories and subproject categories according to configured inheritance settings. * @param mixed $p_project_id A specific project or null * @return array A unique array of category names */ function category_get_filter_list( $p_project_id = null ) { if( null === $p_project_id ) { $t_project_id = helper_get_current_project(); } else { $t_project_id = $p_project_id; } if( $t_project_id == ALL_PROJECTS ) { $t_project_ids = current_user_get_accessible_projects(); } else { $t_project_ids = array( $t_project_id ); } $t_subproject_ids = array(); foreach( $t_project_ids as $t_project_id ) { $t_subproject_ids = array_merge( $t_subproject_ids, current_user_get_all_accessible_subprojects( $t_project_id ) ); } $t_project_ids = array_merge( $t_project_ids, $t_subproject_ids ); $t_categories = array(); foreach( $t_project_ids AS $t_id ) { $t_categories = array_merge( $t_categories, category_get_all_rows( $t_id ) ); } $t_unique = array(); foreach( $t_categories AS $t_category ) { if( !in_array( $t_category['name'], $t_unique ) ) { $t_unique[] = $t_category['name']; } } return $t_unique; }
<?php # Copyright (c) 2011 John Reese # Licensed under the MIT license require_once("icon_api.php"); $current_project = helper_get_current_project(); $project_ids = current_user_get_all_accessible_subprojects($current_project); $project_ids[] = $current_project; $resolved_threshold = config_get("bug_resolved_status_threshold"); $bug_table = db_get_table("mantis_bug_table"); $version_table = db_get_table("mantis_project_version_table"); # Fetch list of target versions in use for the given projects $query = "SELECT DISTINCT v.version FROM {$version_table} v JOIN {$bug_table} b ON b.target_version= v.version WHERE v.project_id IN (".join(", ", $project_ids). ") ORDER BY v.date_order DESC"; $result = db_query_bound($query); $versions = array(); while ($row = db_fetch_array($result)) { if ($row["version"]) { $versions[] = $row["version"]; } } # Get the selected target version