summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2022-02-11 09:54:30 +0100
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2022-02-11 09:54:30 +0100
commit5b26e3982846b637993622d9ad6de26ab9d352e6 (patch)
treed5e1985bc910cbeada7e38eff06fd5885e9499fe
parent1ceb9d3a96534f327fa59694c463c258040fe7fe (diff)
downloadgigologadmin-5b26e3982846b637993622d9ad6de26ab9d352e6.tar.gz
gigologadmin-5b26e3982846b637993622d9ad6de26ab9d352e6.tar.bz2
gigologadmin-5b26e3982846b637993622d9ad6de26ab9d352e6.zip
more pagination details fixes
-rw-r--r--includes/admin/views/_concerts_table.php83
-rw-r--r--includes/concert.php4
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 .= '</tr>';
//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 .= '</tr>';
$lastType = $concert->venue()->city();
}
- $content .= '</table></div>';
- // $content .='<div style="padding: 10px 20px 0px; border-top: dotted 1px #CCC;"><strong>Page '.$page_no.' of '.$total_no_of_pages.'</strong></div>';
-
- $content .=' <ul class="cpagination">';
- if($page_no > 1){ $content.= "<span><a href='?page_no=1'>First Page - </a></span>"; }
- $content .="<span "; if($page_no <= 1){ $content .="class='disabled'"; }
- $content.="> ";
- if($page_no > 1){$content.= " <a href='?page_no=".$previous_page."' >Previous - </a></span>";}
- $content .= "<span";
- if($page_no >= $total_no_of_pages){ $content .="class='disabled'";}
- $content.="> ";
- if($page_no < $total_no_of_pages) { $content .= ' <a href="?page_no='.$next_page.'"> Next - </a> ';}
- $content .= "</span>";
+ $content .= '</table>';
+
+ $content.='<div id="pagtextbox">';
+ $content.='<span class="alignleft">';
+ if($page_no > 1){ $content.= "<span><a href='?page_no=1'>First Page </a> - </span>"; }
+ if($page_no <= 1){ $content .="<span> </span>"; }
+ else $content.= "<span> <a href='?page_no=".$previous_page."' >Previous </a> </span>";
+ $content.='</span>';
+ $content.='<span class="aligncenter"><div style="padding: 10px 20px 0px; border-top: dotted 1px #CCC;"><strong>Page '.$page_no.' of '.$total_no_of_pages.'</strong></div></span>';
+ $content.='<span class="alignright">';
+ if($page_no >= $total_no_of_pages){ $content .="<span> </span>";}
+ if($page_no < $total_no_of_pages) { $content .= '<span> <a href="?page_no='.$next_page.'"> Next </a> - </span> ';}
if($page_no < $total_no_of_pages){
$content .= "<span><a href='?page_no=".$total_no_of_pages."'>Last Page </a></span>";}
- $content .="</ul>";
+
+ $content.='</span>';
+ $content.='</div>';
+
+
+
+ //
+
+
+ //from main form that includes filters
+ $content .= '</div></form></p>';
// 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.= '<select name="selectmonth" size="1"><option value="0" selected="selected">- - All - -</option>';
+ for ($i = 0; $i < 12; $i++) {
+ $time = strtotime(sprintf('%d months', $i));
+ $label = date('F', $time);
+ $value = date('n', $time);
+ $select.= "<option value='$value'>$label</option>";
+ }
+
+ $select.='</select>';
+
if(is_admin()) {
//option to select own concerts only
$select .= '<input name="ownconcerts" class="ownconc" type="checkbox" value="1"'
. checked(isset($_POST['ownconcerts']) ? $_POST['ownconcerts'] : false)
. '><label for="ownconcerts">Show own concerts only</label>';
+
}
- $select .= '<input class="applybutton" type="submit" value="Apply Filters"></form></p>';
+ //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function
+ $select .= '<input class="applybutton" type="submit" value="Apply Filters">';
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));