summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-05-09 22:12:21 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-05-09 22:12:21 +0200
commit61c48191a8e9ab757be4bf845072f4cfdbf9075f (patch)
treed26c746ff3ce8b5e7c176aada8e26adccb25e918
parente570c572b8ccc377a74ab168f2698ac706400141 (diff)
downloadgigologadmin-61c48191a8e9ab757be4bf845072f4cfdbf9075f.tar.gz
gigologadmin-61c48191a8e9ab757be4bf845072f4cfdbf9075f.tar.bz2
gigologadmin-61c48191a8e9ab757be4bf845072f4cfdbf9075f.zip
Method to find concerts at given venue
-rw-r--r--includes/concert.php14
-rw-r--r--tests/ConcertTest.php40
2 files changed, 54 insertions, 0 deletions
diff --git a/includes/concert.php b/includes/concert.php
index c773c12..050c924 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -185,6 +185,20 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results);
}
+ public static function find_concerts_at(GiglogAdmin_Venue $venue) : 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_concerts.venue = ' . $wpdb->prepare('%d', $venue->id());
+
+ $results = $wpdb->get_results($query);
+
+ return array_map(function($c) { return new GiglogAdmin_Concert($c); }, $results);
+ }
+
public function save(): void
{
global $wpdb;
diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php
index dc82839..96fc72b 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -128,4 +128,44 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertEquals("Sogndal", $gig->venue()->city());
}
}
+
+ public function testOnlyFetchConcertsAtGivenVenue() : void
+ {
+ $venue1 = GiglogAdmin_Venue::create("Sentrum Scene", "Oslo");
+ $venue2 = GiglogAdmin_Venue::create("Rockefeller Music Hall", "Oslo");
+ $venue3 = GiglogAdmin_Venue::create("Revolver", "Oslo");
+
+ for ($i = 0; $i < 4; $i++) {
+ GiglogAdmin_Concert::create('Concert ' . $i, $venue1->id(), '', '', '');
+ }
+
+ for ($i = 4; $i < 6; $i++) {
+ GiglogAdmin_Concert::create('Concert ' . $i, $venue2->id(), '', '', '');
+ }
+
+ for ($i = 6; $i < 11; $i++) {
+ GiglogAdmin_Concert::create('Concert ' . $i, $venue3->id(), '', '', '');
+ }
+
+ $gigs_at_ss = GiglogAdmin_Concert::find_concerts_at($venue1);
+
+ $this->assertEquals(4, count($gigs_at_ss));
+ while ($gig = array_pop($gigs_at_ss)) {
+ $this->assertEquals("Sentrum Scene", $gig->venue()->name());
+ }
+
+ $gigs_at_rmh = GiglogAdmin_Concert::find_concerts_at($venue2);
+
+ $this->assertEquals(2, count($gigs_at_rmh));
+ while ($gig = array_pop($gigs_at_rmh)) {
+ $this->assertEquals("Rockefeller Music Hall", $gig->venue()->name());
+ }
+
+ $gigs_at_r = GiglogAdmin_Concert::find_concerts_at($venue3);
+
+ $this->assertEquals(5, count($gigs_at_r));
+ while ($gig = array_pop($gigs_at_r)) {
+ $this->assertEquals("Revolver", $gig->venue()->name());
+ }
+ }
}