-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
07 - Display the registrations for each event in the admin interface
- Loading branch information
1 parent
7784d3e
commit fc28698
Showing
9 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" ?> | ||
<list xmlns="http://schemas.sulu.io/list-builder/list"> | ||
<key>event_registrations</key> | ||
|
||
<properties> | ||
<property name="id" visibility="no" translation="sulu_admin.id"> | ||
<field-name>id</field-name> | ||
<entity-name>App\Entity\EventRegistration</entity-name> | ||
</property> | ||
|
||
<property name="firstName" visibility="always" searchability="yes" translation="sulu_contact.first_name"> | ||
<field-name>firstName</field-name> | ||
<entity-name>App\Entity\EventRegistration</entity-name> | ||
</property> | ||
|
||
<property name="lastName" visibility="always" searchability="yes" translation="sulu_contact.last_name"> | ||
<field-name>lastName</field-name> | ||
<entity-name>App\Entity\EventRegistration</entity-name> | ||
</property> | ||
|
||
<property name="email" visibility="always" searchability="yes" translation="sulu_contact.email"> | ||
<field-name>email</field-name> | ||
<entity-name>App\Entity\EventRegistration</entity-name> | ||
</property> | ||
|
||
<identity-property name="eventId" visibility="never"> | ||
<field-name>event</field-name> | ||
<entity-name>App\Entity\EventRegistration</entity-name> | ||
</identity-property> | ||
</properties> | ||
</list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Admin; | ||
|
||
use App\Common\DoctrineListRepresentationFactory; | ||
use App\Entity\EventRegistration; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class EventRegistrationController extends AbstractController | ||
{ | ||
public function __construct(private readonly DoctrineListRepresentationFactory $doctrineListRepresentationFactory) | ||
{ | ||
} | ||
|
||
#[Route(path: '/admin/api/events/{eventId}/registrations', methods: ['GET'], name: 'app.get_event_registration_list')] | ||
public function getListAction(int $eventId): Response | ||
{ | ||
$listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation( | ||
EventRegistration::RESOURCE_KEY, | ||
['eventId' => (string) $eventId], | ||
); | ||
|
||
return $this->json($listRepresentation->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/Functional/Controller/Admin/EventRegistrationControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Functional\Controller\Admin; | ||
|
||
use App\Tests\Functional\Traits\EventRegistrationTrait; | ||
use App\Tests\Functional\Traits\EventTrait; | ||
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class EventRegistrationControllerTest extends SuluTestCase | ||
{ | ||
use EventRegistrationTrait; | ||
use EventTrait; | ||
|
||
private KernelBrowser $client; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->client = $this->createAuthenticatedClient(); | ||
$this->purgeDatabase(); | ||
} | ||
|
||
public function testGetList(): void | ||
{ | ||
$event1 = $this->createEvent('Sulu is awesome', 'de'); | ||
$event2 = $this->createEvent('Symfony live is awesome', 'de'); | ||
|
||
$registration1 = $this->createEventRegistration($event1, 'Max', 'Mustermann'); | ||
$registration2 = $this->createEventRegistration($event2, 'Mira', 'Musterfrau'); | ||
|
||
$this->client->jsonRequest('GET', '/admin/api/events/' . $event1->getId() . '/registrations'); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertInstanceOf(Response::class, $response); | ||
/** | ||
* @var array{ | ||
* _embedded: array{ | ||
* event_registrations: array<array{ | ||
* id: int, | ||
* firstName: string, | ||
* lastName: string, | ||
* email: string, | ||
* }> | ||
* }, | ||
* total: int, | ||
* } $result | ||
*/ | ||
$result = \json_decode($response->getContent() ?: '', true, 512, \JSON_THROW_ON_ERROR); | ||
$this->assertHttpStatusCode(200, $response); | ||
|
||
$this->assertSame(1, $result['total']); | ||
$this->assertCount(1, $result['_embedded']['event_registrations']); | ||
$items = $result['_embedded']['event_registrations']; | ||
|
||
$this->assertSame($registration1->getId(), $items[0]['id']); | ||
|
||
$this->assertSame($registration1->getFirstName(), $items[0]['firstName']); | ||
$this->assertSame($registration1->getLastName(), $items[0]['lastName']); | ||
$this->assertArrayHasKey('email', $items[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters