summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-09-06 16:06:51 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-09-06 16:06:51 +0200
commitfc842d4dd0d9af352640316601aaee398be8b636 (patch)
tree6cf1bfd273aa7ccfe8bdc7b9030028f29e29270e
parent1169022cdca0c27deb6fd0ddca96859c578a19b3 (diff)
downloadgigologadmin-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.
-rw-r--r--includes/concert.php29
-rw-r--r--tests/ConcertTest.php16
2 files changed, 40 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);
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
index d81effd..13df320 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -198,4 +198,20 @@ final class ConcertTest extends WP_UnitTestCase
$gigs = GiglogAdmin_Concert::find_concerts();
$this->assertEquals(count(self::$concerts), count($gigs));
}
+
+ public function testFetchConcertByNameVenueAndDate() : void
+ {
+ $gigs = GiglogAdmin_Concert::find_concerts([
+ 'name' => 'a concert',
+ 'venue' => 'a venue',
+ 'date' => date('Y-m-d')
+ ]);
+
+ $this->assertEquals(1, count($gigs));
+
+ $gig = array_shift($gigs);
+ $this->assertEquals('a concert', $gig->cname());
+ $this->assertEquals('a venue', $gig->venue()->name());
+ $this->assertEquals(date('Y-m-d'), $gig->cdate());
+ }
}