From 5b26e3982846b637993622d9ad6de26ab9d352e6 Mon Sep 17 00:00:00 2001 From: AndreaChirulescu Date: Fri, 11 Feb 2022 09:54:30 +0100 Subject: more pagination details fixes --- includes/admin/views/_concerts_table.php | 83 ++++++++++++++++++++++---------- includes/concert.php | 4 ++ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php index 2c72cf2..0302111 100644 --- a/includes/admin/views/_concerts_table.php +++ b/includes/admin/views/_concerts_table.php @@ -48,18 +48,9 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) $content .= ''; //pagination. Change value as needed - $total_records_per_page = 10; + $total_records_per_page = 15; + - if (isset($_GET['page_no']) && $_GET['page_no']!="") { - $page_no = $_GET['page_no']; - } else { - $page_no = 1; - } - //calculate OFFSET Value and SET other Variables - $offset = ($page_no-1) * $total_records_per_page; - $previous_page = $page_no - 1; - $next_page = $page_no + 1; - $adjacents = "2"; $filter = []; @@ -74,17 +65,34 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) $filter['venue_id'] = $venue; } + $smonth = filter_input( INPUT_POST, 'selectmonth', FILTER_SANITIZE_SPECIAL_CHARS ); + if ($smonth) { + $filter['month'] = $smonth; + } + if(isset($_POST['ownconcerts']) && $_POST['ownconcerts'] == '1') { $filter['currentuser'] = wp_get_current_user()->user_login; } $concerts = GiglogAdmin_Concert::find_concerts($filter); + //get number of pages for pagination $total_records = count($concerts); $total_no_of_pages = ceil($total_records / $total_records_per_page); $second_last = $total_no_of_pages - 1; // total pages minus 1 + if (isset($_GET['page_no']) && $_GET['page_no']!="" && $_GET['page_no']<=$total_no_of_pages) { + $page_no = $_GET['page_no']; + } else { + $page_no = 1; + } + //calculate OFFSET Value and SET other Variables + $offset = ($page_no-1) * $total_records_per_page; + $previous_page = $page_no - 1; + $next_page = $page_no + 1; + $adjacents = "2"; + $filter['offset'] = $offset; $filter['recperpage'] = $total_records_per_page; @@ -138,22 +146,31 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) $content .= ''; $lastType = $concert->venue()->city(); } - $content .= ''; - // $content .='
Page '.$page_no.' of '.$total_no_of_pages.'
'; - - $content .=' "; + + $content.=''; + $content.=''; + + + + // + + + //from main form that includes filters + $content .= '

'; // return the table return $content; @@ -182,13 +199,27 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), "Select venue..."); } + + $select.=' Filter by month: '; + $select.= ''; + if(is_admin()) { //option to select own concerts only $select .= ''; + } - $select .= '

'; + //NOTE that I remvoed

and mvoed them up to render_concerts_table function + $select .= ''; return $select; } diff --git a/includes/concert.php b/includes/concert.php index a67364f..11949f7 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -201,6 +201,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { 'id' => $wpdb->prefix . 'giglogadmin_concerts.id', 'name' => 'wpgconcert_name', 'date' => 'wpgconcert_date', + 'month'=> 'MONTH(wpgconcert_date)', 'venue_id' => $wpdb->prefix . 'giglogadmin_venues.id', 'venue' => $wpdb->prefix . 'giglogadmin_venues.wpgvenue_name', 'city' => $wpdb->prefix . 'giglogadmin_venues.wpgvenue_city', @@ -213,6 +214,9 @@ if ( !class_exists('GiglogAdmin_Concert') ) { switch ($key) { case 'name': case 'date': + case 'month': + array_push($where, $wpdb->prepare($keymap[$key] . '=%s', $value)); + break; case 'venue': case 'city': array_push($where, $wpdb->prepare($keymap[$key] . '=%s', $value)); -- cgit v1.2.3