From 1ceb9d3a96534f327fa59694c463c258040fe7fe Mon Sep 17 00:00:00 2001
From: AndreaChirulescu
Date: Wed, 9 Feb 2022 19:55:39 +0100
Subject: css small fixed for table display added pagination to concert list
---
includes/admin/views/_concerts_table.php | 188 +++++++++++++++++++------------
1 file changed, 114 insertions(+), 74 deletions(-)
(limited to 'includes/admin/views/_concerts_table.php')
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php
index a7d9074..2c72cf2 100644
--- a/includes/admin/views/_concerts_table.php
+++ b/includes/admin/views/_concerts_table.php
@@ -26,7 +26,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
public function render(): string
{
return $this->render_filters()
- . $this->render_concerts_table();
+ . $this->render_concerts_table();
}
private function render_concerts_table() : string
@@ -47,6 +47,20 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
}
$content .= '';
+ //pagination. Change value as needed
+ $total_records_per_page = 10;
+
+ 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 = [];
// Use the submitted "city" if any. Otherwise, use the default/static value.
@@ -66,9 +80,20 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
$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
+
+ $filter['offset'] = $offset;
+ $filter['recperpage'] = $total_records_per_page;
+
+ $concertsp = GiglogAdmin_Concert::find_concerts($filter);
+
+
$lastType = '';
- foreach ( $concerts AS $concert ) {
+ foreach ( $concertsp AS $concert ) {
$content .= '';
if ($lastType != '' && $lastType != $concert->venue()->city()) {
@@ -106,24 +131,39 @@ if (!class_exists("GiglogAdmin_ConcertsTable"))
if (current_user_can('administrator')) {
$content .= ''
- . $this->adminactions($concert)
- . ' | ';
+ . $this->adminactions($concert)
+ . '';
}
}
$content .= '
';
$lastType = $concert->venue()->city();
}
$content .= '';
+ // $content .='Page '.$page_no.' of '.$total_no_of_pages.'
';
+
+ $content .=' ";
+
+ // return the table
+ return $content;
+ }
- // return the table
- return $content;
- }
-
- private function render_filters() : string
- {
- $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS);
+ private function render_filters() : string
+ {
+ $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS);
- $select = '
';
+ }
+ $select .= '';
- return $select;
- }
+ return $select;
+ }
- private function adminactions( GiglogAdmin_Concert $concert ) : string
- {
- return
+ private function adminactions( GiglogAdmin_Concert $concert ) : string
+ {
+ return
'';
- }
-
- /**
- * Display a mark on the concert if it is new.
- * I.e. imported/created within the last ten days.
- *
- * @return null|string
- */
- private function mark_new_concert(GiglogAdmin_Concert $concert) : string
- {
- $now = new DateTime();
- $new_entry = $now->diff($concert->created())->days <= 10;
- if ($new_entry) {
- return 'NEW';
+ . ''
+ . ''
+ . '';
}
- else {
- return '';
+
+ /**
+ * Display a mark on the concert if it is new.
+ * I.e. imported/created within the last ten days.
+ *
+ * @return null|string
+ */
+ private function mark_new_concert(GiglogAdmin_Concert $concert) : string
+ {
+ $now = new DateTime();
+ $new_entry = $now->diff($concert->created())->days <= 10;
+ if ($new_entry) {
+ return 'NEW';
+ }
+ else {
+ return '';
+ }
}
- }
- private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string
- {
- $roles = $concert->roles();
- $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
+ private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string
+ {
+ $roles = $concert->roles();
+ $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL;
- //first check if current slot is taken by current user
- if ( $assigned_user == $this->username ) {
- $f = '';
- }
- elseif ( $assigned_user ) { //check if slot is taken by another user
- $f = 'Taken'
- . 'Taken by ' . $assigned_user . '
';
- }
- elseif ( array_search($this->username, $roles) ) {
- // other slots for this concert are taken by user
- $f = '-';
- }
- else { //not taken by anyone
- $f = '';
- }
+ }
- return $f;
+ return $f;
+ }
}
}
- }
--
cgit v1.2.3