diff --git a/config/services.yaml b/config/services.yaml
index 6ce490d..b5ee599 100644
--- a/config/services.yaml
+++ b/config/services.yaml
@@ -57,3 +57,7 @@ services:
App\Admin\:
resource: '../src/Admin'
tags: ['sulu.admin', {name: 'sulu.context', context: 'admin'}]
+
+ App\Repository\:
+ resource: '../src/Repository'
+ public: true
diff --git a/config/templates/pages/event_overview.xml b/config/templates/pages/event_overview.xml
index e386244..3f576fa 100644
--- a/config/templates/pages/event_overview.xml
+++ b/config/templates/pages/event_overview.xml
@@ -6,7 +6,7 @@
This is a very good imprint :)
', ], + [ + 'title' => 'Events', + 'navigationContexts' => ['main'], + 'structureType' => 'event_overview', + 'article' => '', + ], ]; $pages = []; diff --git a/src/Repository/EventRepository.php b/src/Repository/EventRepository.php index f406e68..3835b4e 100644 --- a/src/Repository/EventRepository.php +++ b/src/Repository/EventRepository.php @@ -69,6 +69,24 @@ public function findById(int $id, string $locale): ?Event return $event; } + /** + * @return Event[] + */ + public function filterByLocationId(?int $locationId, string $locale): array + { + $criteria = ['enabled' => true]; + if ($locationId) { + $criteria['location'] = $locationId; + } + + $events = $this->findBy($criteria); + foreach ($events as $event) { + $event->setLocale($locale); + } + + return $events; + } + /** * @param mixed[] $filters */ diff --git a/templates/pages/event_overview.html.twig b/templates/pages/event_overview.html.twig index d3a687b..f699e67 100644 --- a/templates/pages/event_overview.html.twig +++ b/templates/pages/event_overview.html.twig @@ -10,7 +10,28 @@{{ event.teaser }}
diff --git a/tests/Functional/Pages/EventOverviewTest.php b/tests/Functional/Pages/EventOverviewTest.php index 26412ae..961f37b 100644 --- a/tests/Functional/Pages/EventOverviewTest.php +++ b/tests/Functional/Pages/EventOverviewTest.php @@ -5,6 +5,7 @@ namespace App\Tests\Functional\Pages; use App\Tests\Functional\Traits\EventTrait; +use App\Tests\Functional\Traits\LocationTrait; use App\Tests\Functional\Traits\PageTrait; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\DocumentManager\DocumentManagerInterface; @@ -15,6 +16,7 @@ class EventOverviewTest extends SuluTestCase { use EventTrait; + use LocationTrait; use PageTrait; /** @@ -26,6 +28,7 @@ protected function setUp(): void { $this->client = $this->createWebsiteClient(); $this->initPhpcr(); + $this->purgeDatabase(); } public function testEventOverview(): void @@ -58,6 +61,56 @@ public function testEventOverview(): void $this->assertStringContainsString($event2->getTitle() ?: '', $content); } + public function testEventOverviewWithLocations(): void + { + $location1 = $this->createLocation('Dornbirn'); + $location2 = $this->createLocation('Berlin'); + + $event1 = $this->createEvent('Sulu is awesome', 'en'); + $event1->setLocation($location1); + $this->enableEvent($event1); + $event2 = $this->createEvent('Symfony Live is awesome', 'en'); + $event2->setLocation($location2); + $this->enableEvent($event2); + $event3 = $this->createEvent('Disabled', 'en'); + + $this->createPage( + 'event_overview', + 'example', + [ + 'title' => 'Symfony Live', + 'url' => '/events', + 'published' => true, + ] + ); + + $crawler = $this->client->request(Request::METHOD_GET, '/en/events'); + + $response = $this->client->getResponse(); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); + $this->assertCount(2, $crawler->filter('.event-title')); + $this->assertNotNull($content = $crawler->filter('.event-title')->eq(0)->html()); + $this->assertStringContainsString($event1->getTitle() ?: '', $content); + $this->assertNotNull($content = $crawler->filter('.event-title')->eq(1)->html()); + $this->assertStringContainsString($event2->getTitle() ?: '', $content); + + $form = $crawler->filter('#location_submit')->form( + [ + 'location' => $location1->getId(), + ] + ); + + $crawler = $this->client->submit($form); + + $response = $this->client->getResponse(); + $this->assertInstanceOf(Response::class, $response); + $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); + $this->assertCount(1, $crawler->filter('.event-title')); + $this->assertNotNull($content = $crawler->filter('.event-title')->eq(0)->html()); + $this->assertStringContainsString($event1->getTitle() ?: '', $content); + } + protected function getDocumentManager(): DocumentManagerInterface { return $this->getContainer()->get('sulu_document_manager.document_manager');