From 57c9ed78112fb33f8a552e9b76d4fedac14f08d9 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 15:25:13 +0200 Subject: Mark recently added concerts as new again. --- includes/admin/views/giglog_admin_page.php | 26 +++++++++----------------- includes/concert.php | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 0f8fe76..447dcb2 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -180,27 +180,21 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { /** * @return null|string */ - private function getpublishstatus(int $concert_id) + private function getpublishstatus(GiglogAdmin_Concert $concert) : string { - global $wpdb; - $date1 = new DateTime("now"); - $dsql = "select wpgcl_createddate from wpg_concertlogs where wpgcl_concertid=".$concert_id; - $results = $wpdb->get_results($dsql); - foreach ( $results AS $row ) { - //$x = strtotime($row -> filedate); - $x= date('Y-m-d H:i:s', strtotime($row -> wpgcl_createddate)); - $date2 = new DateTime($x, new DateTimeZone('Europe/London')); - $dd = $date2 -> diff($date1) ->format("%a"); + $now = new DateTime(); + $new_entry = $now->diff($concert->created())->days <= 10; + if ($new_entry) { + return 'NEW'; + } + else { + return ''; } - - if ($dd <= 10) return ('NEW'); } private function get_concerts(): string { - global $wpdb; - $content = ''; // $content .= ''; @@ -245,9 +239,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //$content .= DATE_FORMAT($fdate,'%d.%b.%Y'); $content .= ''; - $content .= ''; - - $roles = $concert->roles(); + $content .= ''; $content .= ''; $content .= ''; diff --git a/includes/concert.php b/includes/concert.php index dce15f0..c0c13ee 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -20,6 +20,8 @@ if ( !class_exists('GiglogAdmin_Concert') ) { private ?string $eventlink; private ?int $status; private array $roles; + private ?DateTimeImmutable $created; + private ?DateTimeImmutable $updated; public const STATUS_NONE = 0; public const STATUS_ACCRED_REQ = 1; @@ -43,6 +45,8 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; $this->status = isset($attrs->wpgconcert_status) ? $attrs->wpgconcert_status : 0; $this->roles = isset($attrs->wpgconcert_roles) ? json_decode($attrs->wpgconcert_roles, true) : []; + $this->created = isset($attrs->created) ? new DateTimeImmutable($attrs->created) : NULL; + $this->updated = isset($attrs->updated) ? new DateTimeImmutable($attrs->updated) : NULL; if ( isset( $attrs->venue ) ) { if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) { @@ -74,8 +78,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { global $wpdb; - $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' - . 'FROM wpg_concerts ' + $query = 'SELECT * FROM wpg_concerts ' . 'LEFT JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id); @@ -197,8 +200,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { global $wpdb; - $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' - . 'FROM wpg_concerts ' + $query = 'SELECT * FROM wpg_concerts ' . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '; $where = []; @@ -304,6 +306,14 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { $this->roles = array_filter($this->roles, fn($u) => $u != $username); } + + public function created() : DateTimeImmutable { + return $this->created; + } + + public function updated() : DateTimeImmutable { + return $this->updated; + } } } ?> -- cgit v1.2.3
CITYIDBANDVENUEDATE
' . $newformat . '' . /* $concert->isnew() */ '' . '' . $this->getpublishstatus($concert) . '' . $this->assign_role_for_user_form('photo1', $concert) . '' . $this->assign_role_for_user_form('photo2', $concert) . '