feat(problemset): add hardness filter and improve query parameter handling
- Added hardness filter dropdown in problemset UI with options 1-8 - Implemented server-side hardness parameter validation and filtering - Refactored query parameter handling to use $filter_params array - Updated SQL queries to use parameter binding for both search and hardness filters - Fixed pagination to include hardness parameter in URL - Improved code organization by centralizing filter parameter management
This commit is contained in:
@@ -41,9 +41,18 @@ $postfix = "";
|
||||
$filter_sql = "";
|
||||
$limit_sql = "";
|
||||
$order_by = " order by problem_id ";
|
||||
$filter_params = array();
|
||||
$hardness = 0;
|
||||
if (isset($_GET['hardness'])) {
|
||||
$hardness = intval($_GET['hardness']);
|
||||
if ($hardness < 1 || $hardness > 8)
|
||||
$hardness = 0;
|
||||
}
|
||||
if (isset($_GET['search']) && trim($_GET['search']) != "") {
|
||||
$search = "%" . ($_GET['search']) . "%";
|
||||
$filter_sql = " ( title like ? or source like ?)";
|
||||
$filter_params[] = $search;
|
||||
$filter_params[] = $search;
|
||||
$limit_sql = " LIMIT " . ($page - 1) * $page_cnt . "," . $page_cnt;
|
||||
$postfix = "&search=" . urlencode($_GET['search']);
|
||||
} else if (isset($_GET['list']) && trim($_GET['list'] != "")) {
|
||||
@@ -61,6 +70,11 @@ if (isset($_GET['search']) && trim($_GET['search']) != "") {
|
||||
$filter_sql = " 1";
|
||||
$limit_sql = " LIMIT " . ($page - 1) * $page_cnt . "," . $page_cnt;
|
||||
}
|
||||
if ($hardness > 0) {
|
||||
$filter_sql .= " and hardness=?";
|
||||
$filter_params[] = $hardness;
|
||||
$postfix .= "&hardness=" . $hardness;
|
||||
}
|
||||
|
||||
//all submit
|
||||
//all acc
|
||||
@@ -103,10 +117,10 @@ pdo_query("SET sort_buffer_size = 1024*1024"); // Out of sort memory, consider
|
||||
$sql = "SELECT `problem_id`,`title`,`source`,`submit`,`accepted`,defunct FROM problem A WHERE $filter_sql $order_by $limit_sql ";
|
||||
$count_sql = "SELECT count(1) from problem where $filter_sql ";
|
||||
//echo htmlentities( $sql);
|
||||
if (isset($_GET['search']) && trim($_GET['search']) != "") {
|
||||
$total = pdo_query($count_sql, $search, $search);
|
||||
if (count($filter_params) > 0) {
|
||||
$total = pdo_query($count_sql, ...$filter_params);
|
||||
$cnt = $total[0][0] / $page_cnt;
|
||||
$result = pdo_query($sql, $search, $search);
|
||||
$result = pdo_query($sql, ...$filter_params);
|
||||
} else {
|
||||
$total = mysql_query_cache($count_sql);
|
||||
$cnt = $total[0][0] / $page_cnt;
|
||||
|
||||
Reference in New Issue
Block a user