From f1fced27a60d656c70c0c060f894679773158f9c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 27 Jun 2021 15:21:28 +0200 Subject: Remove some debug output. --- includes/concert.php | 1 - 1 file changed, 1 deletion(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 88a20da..6257fab 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -75,7 +75,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id); $results = $wpdb->get_results($query); - var_dump($results); return $results ? new GiglogAdmin_Concert($results[0]) : NULL; } -- cgit v1.2.3 From 224f0149ea513146b164736f461e6cbba4b86add Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 27 Jun 2021 13:05:08 +0200 Subject: Begin move roles and status field to concerts table. --- includes/concert.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 6257fab..db8d68a 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -274,6 +274,11 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { return $this->roles; } + + public function assign_role( int $role, string $username ) : void + { + $this->roles[$role] = $username; + } } } ?> -- cgit v1.2.3 From fb8d2649e17c94458db247925b796f5ae2141b0d Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Wed, 1 Sep 2021 22:01:42 +0200 Subject: Fix saving and fetching roles from Concerts table. --- includes/concert.php | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index db8d68a..53cd00e 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -76,7 +76,12 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $results = $wpdb->get_results($query); - return $results ? new GiglogAdmin_Concert($results[0]) : NULL; + if ( !$results ) { + $wpdb->print_error( __METHOD__ ); + return null; + } + + return new GiglogAdmin_Concert($results[0]); } public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self @@ -202,34 +207,27 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { global $wpdb; - if ( $this->id !== NULL ) { - $res = $wpdb->update('wpg_concerts', array( - 'id' => $this->id, - 'wpgconcert_name' => $this->cname, - 'venue' => $this->venue->id(), - 'wpgconcert_date' => $this->cdate, - 'wpgconcert_tickets' => $this->tickets, - 'wpgconcert_event' => $this->eventlink, - 'wpgconcert_status' => $this->status, - ), - array( 'id' => $this->id ) ); + $columns = [ + 'wpgconcert_name' => $this->cname, + 'venue' => $this->venue->id(), + 'wpgconcert_date' => $this->cdate, + 'wpgconcert_tickets' => $this->tickets, + 'wpgconcert_event' => $this->eventlink, + 'wpgconcert_status' => $this->status, + 'wpgconcert_roles' => wp_json_encode( $this->roles ), + ]; + if ( $this->id !== NULL ) { + $res = $wpdb->update( 'wpg_concerts', $columns, [ 'id' => $this->id ] ); } else { - $res = $wpdb->insert('wpg_concerts', array( - 'wpgconcert_name' => $this->cname, - 'venue' => $this->venue->id(), - 'wpgconcert_date' => $this->cdate, - 'wpgconcert_tickets' => $this->tickets, - 'wpgconcert_event' => $this->eventlink, - 'wpgconcert_status' => $this->status, - )); + $res = $wpdb->insert('wpg_concerts', $columns); } if ( $res === false ) { $wpdb->print_error( __METHOD__ ); } - else { + elseif ( $this->id === NULL ) { $this->id = $wpdb->insert_id; } } @@ -275,7 +273,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { return $this->roles; } - public function assign_role( int $role, string $username ) : void + public function assign_role( string $role, string $username ) : void { $this->roles[$role] = $username; } -- cgit v1.2.3 From 3668e685566bed2d3623a3cd276d93f79319a008 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 2 Sep 2021 09:10:19 +0200 Subject: psalm: Add type info to attrs and constructor for Concert. Also make sure we explicitly set the venue attribute in the constructor. --- includes/concert.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 53cd00e..cc1efaa 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -5,17 +5,19 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later +require_once __DIR__ . '/venue.php'; + if ( !class_exists('GiglogAdmin_Concert') ) { require_once __DIR__ . '/venue.php'; class GiglogAdmin_Concert { - private $id; - private $cname; - private $venue; - private $cdate; - private $tickets; - private $eventlink; + private int $id; + private string $cname; + private ?GiglogAdmin_Venue $venue; + private string $cdate; + private string $tickets; + private string $eventlink; private int $status; private array $roles; @@ -32,7 +34,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { * so this constructor can be used to construct the object * directly from the database row. */ - public function __construct($attrs = []) + public function __construct(object $attrs) { $this->id = isset($attrs->id) ? $attrs->id : NULL; $this->cname = isset($attrs->wpgconcert_name) ? $attrs->wpgconcert_name : NULL; @@ -56,6 +58,9 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $this->venue = GiglogAdmin_Venue::get($attrs->venue); } } + else { + $this->venue = NULL; + } } @@ -268,7 +273,12 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $this->status = $new_status; } - public function roles() + /** + * Return the roles defined for this concert. + * + * @return array + */ + public function roles() : array { return $this->roles; } -- cgit v1.2.3 From 52980d074809a18d150a88313ab86054870c416e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 2 Sep 2021 09:20:44 +0200 Subject: Fix more type issues in Concert and Venue classes --- includes/concert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index cc1efaa..f2f5535 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -12,7 +12,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { class GiglogAdmin_Concert { - private int $id; + private ?int $id; private string $cname; private ?GiglogAdmin_Venue $venue; private string $cdate; -- cgit v1.2.3 From 18edd0852b02a2027f24e6644e81bf111371c26f Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 09:14:20 +0200 Subject: Allow empty concerts to be created. --- includes/concert.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index f2f5535..26722ed 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -13,12 +13,12 @@ if ( !class_exists('GiglogAdmin_Concert') ) { class GiglogAdmin_Concert { private ?int $id; - private string $cname; + private ?string $cname; private ?GiglogAdmin_Venue $venue; - private string $cdate; - private string $tickets; - private string $eventlink; - private int $status; + private ?string $cdate; + private ?string $tickets; + private ?string $eventlink; + private ?int $status; private array $roles; public const STATUS_NONE = 1; -- cgit v1.2.3 From 742ef8ee58b5b2dd59e17648f31f2f8ed9d4f3d0 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 09:14:56 +0200 Subject: emove dependency on ConcertLogs in gig import code. --- includes/concert.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 26722ed..61959b2 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -118,17 +118,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . ', Ticket LINK ' . $ticketlink . ', Event LINK ' . $eventlink); - GiglogAdmin_Concertlogs::add( $concert->id() ); - /*the last line can be replaced by a trigger - CREATE TRIGGER `insertIntoPhotoLogs` AFTER INSERT ON `wpg_concerts` - FOR EACH ROW INSERT INTO wpg_concertlogs ( - wpg_concertlogs.id, - wpg_concertlogs.wpgcl_concertid, - wpg_concertlogs.wpgcl_status) - - VALUES - (null, new.id, 1) - */ return $concert; } } -- cgit v1.2.3 From 92ee799aab8d9ee41564b346f3a89bb688cf53bd Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 13:08:07 +0200 Subject: Shift value of Concert statuses to be 0-based. This will trip up any existing records in the db, but that should not matter, since we're changing how this entire stuff works now. --- includes/concert.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 61959b2..d6fe7c4 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -21,12 +21,12 @@ if ( !class_exists('GiglogAdmin_Concert') ) { private ?int $status; private array $roles; - public const STATUS_NONE = 1; - public const STATUS_ACCRED_REQ = 2; - public const STATUS_PHOTO_APPROVED = 3; - public const STATUS_TEXT_APPROVED = 4; - public const STATUS_ALL_APPROVED = 5; - public const STATUS_REJECTED = 6; + public const STATUS_NONE = 0; + public const STATUS_ACCRED_REQ = 1; + public const STATUS_PHOTO_APPROVED = 2; + public const STATUS_TEXT_APPROVED = 3; + public const STATUS_ALL_APPROVED = 4; + public const STATUS_REJECTED = 5; /* * Constructs a new concert object from an array of attributes. @@ -41,7 +41,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL; $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL; $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; - $this->status = isset($attrs->wpgconcert_status) ? $attrs->wpgconcert_status : 1; + $this->status = isset($attrs->wpgconcert_status) ? $attrs->wpgconcert_status : 0; $this->roles = isset($attrs->wpgconcert_roles) ? json_decode($attrs->wpgconcert_roles, true) : []; if ( isset( $attrs->venue ) ) { -- cgit v1.2.3 From 74d39366640683914ab44db039ab48959c7dc91b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 3 Sep 2021 19:32:28 +0200 Subject: Editing concerts now work again. --- includes/concert.php | 55 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index d6fe7c4..f0c69c8 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -123,27 +123,50 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function update_concert($id, $cname, $venue, $cdate, $ticketlink, $eventlink) + public function update(object $attrs) : bool { - global $wpdb; + $need_update = false; - $res = $wpdb->update('wpg_concerts', array( - 'wpgconcert_name' => $cname, - 'venue' => $venue, - 'wpgconcert_date' => $cdate, - 'wpgconcert_tickets' => $ticketlink, - 'wpgconcert_event' => $eventlink - ), - array('id' => $id) - ); + if (isset($attrs->wpgconcert_name) && $attrs->wpgconcert_name != $this->cname) { + $this->cname = $attrs->wpgconcert_name; + $need_update = true; + } - if ( $res === false ) { - // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed - error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); - die; + if (isset($attrs->wpgconcert_date) && $attrs->wpgconcert_date != $this->cdate) { + $this->cdate = $attrs->wpgconcert_date; + $need_update = true; + } + + if (isset($attrs->wpgconcert_tickets) && $attrs->wpgconcert_tickets != $this->tickets) { + $this->tickets = $attrs->wpgconcert_tickets; + $need_update = true; + } + + if (isset($attrs->wpgconcert_event) && $attrs->wpgconcert_event != $this->eventlink) { + $this->eventling = $attrs->wpgconcert_eventlink; + $need_update = true; + } + + if (isset($attrs->wpgconcert_status) && $attrs->wpgconcert_status != $this->status) { + $this->status = $attrs->wpgconcert_status; + $need_update = true; + } + + if (isset($attrs->wpgconcert_roles) && $attrs->wpgconcert_roles != $this->roles) { + $this->roles = $attrs->wpgconcert_roles; + $need_update = true; + } + + if (isset($attrs->venue) && $attrs->venue != $this->venue()->id()) { + $this->venue = GiglogAdmin_Venue::get($attrs->venue); + $need_update = true; + } + + if ($need_update) { + $this->save(); } - return ($wpdb->last_error); + return $need_update; } public static function find($cname, $venue, $date) -- cgit v1.2.3 From f57acecbae89a2782acf6f6b539025385c198366 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Sep 2021 10:58:07 +0200 Subject: Make click to unassign from concert work again. As a user can only be assigned to one role at the time, we remove the current user from any role that they may have when clearing the assignment. --- includes/concert.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index f0c69c8..dce15f0 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -299,6 +299,11 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { $this->roles[$role] = $username; } + + public function remove_user_from_roles( string $username ) : void + { + $this->roles = array_filter($this->roles, fn($u) => $u != $username); + } } } ?> -- cgit v1.2.3 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/concert.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'includes/concert.php') 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