diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-09-06 16:06:51 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-09-06 16:06:51 +0200 |
commit | fc842d4dd0d9af352640316601aaee398be8b636 (patch) | |
tree | 6cf1bfd273aa7ccfe8bdc7b9030028f29e29270e /includes/concert.php | |
parent | 1169022cdca0c27deb6fd0ddca96859c578a19b3 (diff) | |
download | gigologadmin-fc842d4dd0d9af352640316601aaee398be8b636.tar.gz gigologadmin-fc842d4dd0d9af352640316601aaee398be8b636.tar.bz2 gigologadmin-fc842d4dd0d9af352640316601aaee398be8b636.zip |
Use find_concerts to check for duplicates on create.
This also adds a number of new filters to find_concerts.
Diffstat (limited to 'includes/concert.php')
-rw-r--r-- | includes/concert.php | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/includes/concert.php b/includes/concert.php index 9413417..f0a9ecd 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -96,12 +96,18 @@ if ( !class_exists('GiglogAdmin_Concert') ) { return new GiglogAdmin_Concert($res); } - public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self + public static function create(string $name, int $venue_id, string $date, string $ticketlink, string $eventlink): ?self { - if ( GiglogAdmin_Concert::find($name, $venue, $date) ) { + $gigs = GiglogAdmin_Concert::find_concerts([ + 'name' => $name, + 'venue_id' => $venue_id, + 'date' => $date + ]); + + if (!empty($gigs)) { error_log( 'DUPLICATE ROW detected: ' . ' CONCERT NAME ' . $name - . ', VENUE ID ' . $venue + . ', VENUE ID ' . $venue_id . ', CONCERTDATE ' . $date); return NULL; @@ -109,7 +115,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { else { $concert = new GiglogAdmin_Concert( (object) [ "wpgconcert_name" => $name, - "venue" => $venue, + "venue" => $venue_id, "wpgconcert_date" => $date, "wpgconcert_tickets" => $ticketlink, "wpgconcert_event" => $eventlink, @@ -120,7 +126,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { error_log( 'NEW CONCERT ADDED: ' . ' ID: ' . $concert -> id() . ' CONCERT NAME ' . $name - . ', VENUE ID ' . $venue + . ', VENUE ID ' . $venue_id . ', CONCERTDATE ' . $date . ', Ticket LINK ' . $ticketlink . ', Event LINK ' . $eventlink); @@ -195,6 +201,14 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $where = []; + if ( isset( $filter['name'] ) ) { + array_push($where, "wpgconcert_name = {$wpdb->prepare('%s', $filter['name'])}"); + } + + if ( isset( $filter['date'] ) ) { + array_push($where, "wpgconcert_date = {$wpdb->prepare('%s', $filter['date'])}"); + } + if ( isset( $filter["city"] ) ) { array_push($where, 'wpg_venues.wpgvenue_city = ' . $wpdb->prepare('%s', $filter["city"])); } @@ -203,6 +217,10 @@ if ( !class_exists('GiglogAdmin_Concert') ) { array_push($where, 'wpg_venues.id = ' . $wpdb->prepare('%s', $filter["venue_id"])); } + if ( isset( $filter['venue'] ) ) { + array_push($where, "wpg_venues.wpgvenue_name = {$wpdb->prepare('%s', $filter['venue'])}"); + } + if ( isset( $filter["currentuser"] ) ) { array_push($where , 'wpgconcert_roles like "%'.$filter["currentuser"].'%"'); } @@ -210,6 +228,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { if ( ! empty( $where ) ) { $query .= 'WHERE ' . implode(' and ', $where); } + $query.= ' ORDER BY wpgconcert_date'; $results = $wpdb->get_results($query); |