summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 22:17:02 +0200
committerAndreaChirulescu <andrea.chirulescu@gmail.com>2021-05-09 22:17:02 +0200
commitbfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8 (patch)
tree2b651eeda54d4c63a90c8beeb3958cc5903e0653
parent5dbd4fdfbda8c7ed165728f5835f9520828b7b2e (diff)
parent61c48191a8e9ab757be4bf845072f4cfdbf9075f (diff)
downloadgigologadmin-bfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8.tar.gz
gigologadmin-bfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8.tar.bz2
gigologadmin-bfe4eb5efd705b64943a0e1c0b7e18bfe0eee4d8.zip
Merge branch 'dev' of https://code.volse.net/wordpress/plugins/gigologadmin.git into andreaschanges
-rw-r--r--includes/concert.php29
-rw-r--r--tests/ConcertTest.php81
2 files changed, 110 insertions, 0 deletions
diff --git a/includes/concert.php b/includes/concert.php
index e3c32e8..050c924 100644
--- a/includes/concert.php
+++ b/includes/concert.php
@@ -170,6 +170,35 @@ if ( !class_exists('GiglogAdmin_Concert') ) {
return $wpdb->get_results($sql);
}
+
+ public static function find_concerts_in(string $city) : 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);
+
+ $results = $wpdb->get_results($query);
+
+ 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 0517ad8..96fc72b 100644
--- a/tests/ConcertTest.php
+++ b/tests/ConcertTest.php
@@ -87,4 +87,85 @@ final class ConcertTest extends WP_UnitTestCase
$this->assertEquals($gig->cname(), $fetched_gig->cname());
$this->assertEquals($venue->id(), $fetched_gig->venue()->id());
}
+
+ public function testOnlyFetchConcertsFromGivenCity() : void
+ {
+ $venue1 = GiglogAdmin_Venue::create("Svene Bedehus", "Svene");
+ $venue2 = GiglogAdmin_Venue::create("Rockefeller Music Hall", "Oslo");
+ $venue3 = GiglogAdmin_Venue::create("Meieriet", "Sogndal");
+
+ 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_in_svene = GiglogAdmin_Concert::find_concerts_in("Svene");
+
+ $this->assertEquals(4, count($gigs_in_svene));
+ while ($gig = array_pop($gigs_in_svene)) {
+ $this->assertEquals("Svene", $gig->venue()->city());
+ }
+
+
+ $gigs_in_oslo = GiglogAdmin_Concert::find_concerts_in("Oslo");
+
+ $this->assertEquals(2, count($gigs_in_oslo));
+ while ($gig = array_pop($gigs_in_oslo)) {
+ $this->assertEquals("Oslo", $gig->venue()->city());
+ }
+
+ $gigs_in_sogndal = GiglogAdmin_Concert::find_concerts_in("Sogndal");
+
+ $this->assertEquals(5, count($gigs_in_sogndal));
+ while ($gig = array_pop($gigs_in_sogndal)) {
+ $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());
+ }
+ }
}