From ae72f1b2f0c73ded5277300f0d15914e6e10ecae Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 10 May 2021 10:45:04 +0200 Subject: Make it possible to list all concerts. --- includes/concert.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 050c924..455bc82 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -171,14 +171,17 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function find_concerts_in(string $city) : array + public static function find_concerts_in(?string $city = null) : array { global $wpdb; $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' . 'FROM wpg_concerts ' - . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' - . 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); + . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '; + + if ( $city ) { + $query .= 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); + } $results = $wpdb->get_results($query); -- cgit v1.2.3 From 5af89bca3bd17777fae94e681882d6eabf152303 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 12 Jun 2021 18:24:01 +0200 Subject: Fix misc Psalm issues. --- includes/concert.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 455bc82..56021f5 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -6,6 +6,8 @@ // SPDX-License-Identifier: AGPL-3.0-or-later if ( !class_exists('GiglogAdmin_Concert') ) { + require_once __DIR__ . '/venue.php'; + class GiglogAdmin_Concert { private $id; -- cgit v1.2.3 From 72340c709e50a2383a8c651d72bb4396e9477c9a Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 12 Jun 2021 18:24:37 +0200 Subject: Streamline Concert api. Reduce to one find_concerts function taking a filter to limit the selection. --- includes/concert.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index 56021f5..fcb3934 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -173,7 +173,18 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } - public static function find_concerts_in(?string $city = null) : array + /** + * Return an array of concert objects optionally limited by a specified + * filter. + * + * Valid filters are: + * - 'venue_id' => int : only include concerts at the given venue + * - 'city' => string : only include concerts in the given city + * + * @param array $filter + * @return array + */ + public static function find_concerts(array $filter = []) : array { global $wpdb; @@ -181,23 +192,19 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . 'FROM wpg_concerts ' . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id '; - if ( $city ) { - $query .= 'WHERE wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $city); - } - - $results = $wpdb->get_results($query); + $where = []; - return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results); - } + if ( isset( $filter["city"] ) ) { + array_push($where, 'wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $filter["city"])); + } - public static function find_concerts_at(GiglogAdmin_Venue $venue) : array - { - global $wpdb; + if ( isset( $filter["venue_id"] ) ) { + array_push($where, 'wpg_venues.id = ' . $wpdb->prepare('%s', $filter["venue_id"])); + } - $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' - . 'FROM wpg_concerts ' - . 'INNER JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' - . 'WHERE wpg_concerts.venue = ' . $wpdb->prepare('%d', $venue->id()); + if ( ! empty( $where ) ) { + $query .= 'WHERE ' . implode(' and ', $where); + } $results = $wpdb->get_results($query); -- cgit v1.2.3 From bb353e8e61156b0c9fdab673e2485502a01b8434 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 13 Jun 2021 16:05:48 +0200 Subject: Move method to update Concertlogs to Concertlogs class. --- includes/concert.php | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index fcb3934..6d568c8 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -137,29 +137,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) { return ($wpdb->last_error); } - static function update_concertlog($cid, $ph1, $ph2, $rev1, $rev2) - { - global $wpdb; - - $res = $wpdb->update('wpg_concertlogs', array( - 'wpgcl_photo1' => $ph1, - 'wpgcl_photo2' => $ph2, - 'wpgcl_rev1' => $rev1, - 'wpgcl_rev2' => $rev2 - ), - array('wpgcl_concertid' => $cid) - ); - - if ( !$res ) { - // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed - error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); - die; - } - - return ($wpdb->last_error); - - } - public static function find($cname, $venue, $date) { global $wpdb; -- cgit v1.2.3 From 68652c0546845de2f216d7fb285205e2eddf9d41 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 13 Jun 2021 16:07:12 +0200 Subject: Fix detecting error in update_concert method. --- 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 6d568c8..d370de9 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -128,7 +128,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { array('id' => $id) ); - if ( !$res ) { + if ( $res === false ) { // exit( var_dump( $wpdb->last_query ) ); //for onscreen debugging when needed error_log( __CLASS__ . '::' . __FUNCTION__ . ": {$wpdb->last_error}"); die; -- cgit v1.2.3 From 82c4a8f2c4e5acd80b813829cecc40f621da3b21 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 14 Jun 2021 10:07:55 +0200 Subject: Begin move roles and status field to concerts table. There's no need to have a separate table (concertlogs) for these fields. --- includes/concert.php | 68 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'includes/concert.php') diff --git a/includes/concert.php b/includes/concert.php index d370de9..88a20da 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -16,6 +16,15 @@ if ( !class_exists('GiglogAdmin_Concert') ) { private $cdate; private $tickets; private $eventlink; + 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; /* * Constructs a new concert object from an array of attributes. @@ -30,7 +39,8 @@ 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->roles = isset($attrs->wpgconcert_roles) ? json_decode($attrs->wpgconcert_roles, true) : []; if ( isset( $attrs->venue ) ) { if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) { @@ -65,6 +75,7 @@ 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; } @@ -188,20 +199,40 @@ if ( !class_exists('GiglogAdmin_Concert') ) { return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results); } - public function save(): void + public function save() : void { global $wpdb; - $wpdb->insert('wpg_concerts', array( - 'id' => '', - 'wpgconcert_name' => $this->cname, - 'venue' => $this->venue->id(), - 'wpgconcert_date' => $this->cdate, - 'wpgconcert_tickets' => $this->tickets, - 'wpgconcert_event' => $this->eventlink - )); + 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 ) ); + + } + 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, + )); + } - $this->id = $wpdb->insert_id; + if ( $res === false ) { + $wpdb->print_error( __METHOD__ ); + } + else { + $this->id = $wpdb->insert_id; + } } public function id() @@ -229,6 +260,21 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { return $this->eventlink; } + + public function status() + { + return $this->status; + } + + public function set_status( int $new_status ) + { + $this->status = $new_status; + } + + public function roles() + { + return $this->roles; + } } } ?> -- cgit v1.2.3