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 +++++++++++++++++-----------
includes/admin/views/_edit_concert_form.php | 3 +-
includes/concert.php | 21 +++-
includes/css/main.css | 7 --
4 files changed, 133 insertions(+), 86 deletions(-)
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;
+ }
}
}
- }
diff --git a/includes/admin/views/_edit_concert_form.php b/includes/admin/views/_edit_concert_form.php
index 7b0164e..6e4f5e5 100644
--- a/includes/admin/views/_edit_concert_form.php
+++ b/includes/admin/views/_edit_concert_form.php
@@ -52,7 +52,8 @@ if (!class_exists("GiglogAdmin_EditConcertForm"))
.''
.'
'
.'' . $this->get_venue_selector($c->venue()) . '
'
- .'
'
+ //date has to be formatted else it is not red in the date field of html form
+ .'
'
.'
'
.'
'
.'';
diff --git a/includes/concert.php b/includes/concert.php
index 8609694..a67364f 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -208,6 +208,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
];
$where = [];
+ $lmt=[];
foreach( $filter as $key => $value ) {
switch ($key) {
case 'name':
@@ -219,12 +220,20 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
case 'id':
case 'venue_id':
- array_push($where, $wpdb->prepare($keymap[$key] . '=%d', $value));
- break;
+ array_push($where, $wpdb->prepare($keymap[$key] . '=%d', $value));
+ break;
case 'currentuser':
- array_push($where , $wpdb->prepare($keymap[$key] . ' like "%%%s%%"', $value));
- break;
+ array_push($where , $wpdb->prepare($keymap[$key] . ' like "%%%s%%"', $value));
+ break;
+
+ case 'offset':
+ array_push($lmt , $value);
+ break;
+
+ case 'recperpage':
+ array_push($lmt , $value);
+ break;
}
}
@@ -234,6 +243,10 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
$query.= ' ORDER BY wpgconcert_date';
+ if ( ! empty( $lmt ) ) {
+ $query .= ' LIMIT ' . implode(', ', $lmt);
+ }
+
$results = $wpdb->get_results($query);
return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results);
diff --git a/includes/css/main.css b/includes/css/main.css
index 9bb7098..0f166c0 100644
--- a/includes/css/main.css
+++ b/includes/css/main.css
@@ -81,13 +81,6 @@ span.takenbyself
line-height: 2.5em;
}
-table.assignit
-
-{
- white-space: nowrap;
- overflow: hidden;
- border-collapse:collapse;
-}
input[name="unassignitem"]
--
cgit v1.2.3