Skip to content

Commit e19cf25

Browse files
wachterjohannesluca-rath
authored andcommitted
07 - Display the registrations for each event in the admin interface
1 parent 74bf399 commit e19cf25

File tree

10 files changed

+160
-0
lines changed

10 files changed

+160
-0
lines changed

config/lists/event_registrations.xml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" ?>
2+
<list xmlns="http://schemas.sulu.io/list-builder/list">
3+
<key>event_registrations</key>
4+
5+
<properties>
6+
<property name="id" visibility="no" translation="sulu_admin.id">
7+
<field-name>id</field-name>
8+
<entity-name>App\Entity\EventRegistration</entity-name>
9+
</property>
10+
11+
<property name="firstName" visibility="always" searchability="yes" translation="sulu_contact.first_name">
12+
<field-name>firstName</field-name>
13+
<entity-name>App\Entity\EventRegistration</entity-name>
14+
</property>
15+
16+
<property name="lastName" visibility="always" searchability="yes" translation="sulu_contact.last_name">
17+
<field-name>lastName</field-name>
18+
<entity-name>App\Entity\EventRegistration</entity-name>
19+
</property>
20+
21+
<property name="email" visibility="always" searchability="yes" translation="sulu_contact.email">
22+
<field-name>email</field-name>
23+
<entity-name>App\Entity\EventRegistration</entity-name>
24+
</property>
25+
26+
<identity-property name="eventId" visibility="never">
27+
<field-name>event</field-name>
28+
<entity-name>App\Entity\EventRegistration</entity-name>
29+
</identity-property>
30+
</properties>
31+
</list>

config/packages/sulu_admin.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ sulu_admin:
1414
list: app.get_events
1515
detail: app.get_event
1616

17+
event_registrations:
18+
routes:
19+
list: app.get_event_registrations
20+
1721
# Registering Selection Field Types in this section
1822
field_type_options:
1923
selection:

config/routes_admin.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ app_events:
77
name_prefix: app.
88
options:
99
expose: true
10+
11+
app_event_registrationss:
12+
type: rest
13+
resource: App\Controller\Admin\EventRegistrationController
14+
prefix: /admin/api
15+
name_prefix: app.
16+
options:
17+
expose: true

src/Admin/EventAdmin.php

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Admin;
66

77
use App\Entity\Event;
8+
use App\Entity\EventRegistration;
89
use Sulu\Bundle\AdminBundle\Admin\Admin;
910
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
1011
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
@@ -22,6 +23,8 @@ class EventAdmin extends Admin
2223

2324
const EVENT_LIST_VIEW = 'app.events_list';
2425

26+
const EVENT_REGISTRATION_LIST_KEY = 'event_registrations';
27+
2528
const EVENT_ADD_FORM_VIEW = 'app.event_add_form';
2629

2730
const EVENT_EDIT_FORM_VIEW = 'app.event_edit_form';
@@ -119,5 +122,16 @@ public function configureViews(ViewCollection $viewCollection): void
119122
->addToolbarActions($formToolbarActions)
120123
->setParent(static::EVENT_EDIT_FORM_VIEW);
121124
$viewCollection->add($editDetailsFormView);
125+
126+
$editDetailsFormView = $this->viewBuilderFactory->createListViewBuilder(static::EVENT_EDIT_FORM_VIEW . '.registrations', '/registrations')
127+
->setResourceKey(EventRegistration::RESOURCE_KEY)
128+
->setListKey(self::EVENT_REGISTRATION_LIST_KEY)
129+
->setTabTitle('app.registrations')
130+
->addRouterAttributesToListRequest(['id' => 'eventId'])
131+
->addListAdapters(['table'])
132+
->addToolbarActions([])
133+
->setUserSettingsKey(EventRegistration::RESOURCE_KEY)
134+
->setParent(static::EVENT_EDIT_FORM_VIEW);
135+
$viewCollection->add($editDetailsFormView);
122136
}
123137
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller\Admin;
6+
7+
use App\Admin\DoctrineListRepresentationFactory;
8+
use App\Entity\EventRegistration;
9+
use FOS\RestBundle\Routing\ClassResourceInterface;
10+
use Sulu\Component\Rest\RestController;
11+
use Symfony\Component\HttpFoundation\Response;
12+
13+
class EventRegistrationController extends RestController implements ClassResourceInterface
14+
{
15+
/**
16+
* @var DoctrineListRepresentationFactory
17+
*/
18+
private $doctrineListRepresentationFactory;
19+
20+
public function __construct(DoctrineListRepresentationFactory $doctrineListRepresentationFactory)
21+
{
22+
$this->doctrineListRepresentationFactory = $doctrineListRepresentationFactory;
23+
}
24+
25+
public function cgetAction(int $eventId): Response
26+
{
27+
$listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation(
28+
EventRegistration::RESOURCE_KEY,
29+
['eventId' => $eventId]
30+
);
31+
32+
return $this->handleView($this->view($listRepresentation));
33+
}
34+
}

src/Entity/EventRegistration.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
class EventRegistration
1414
{
15+
const RESOURCE_KEY = 'event_registrations';
16+
1517
/**
1618
* @ORM\Id()
1719
* @ORM\GeneratedValue()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Tests\Functional\Controller\Admin;
6+
7+
use App\Tests\Functional\Traits\EventRegistrationTrait;
8+
use App\Tests\Functional\Traits\EventTrait;
9+
use Sulu\Bundle\TestBundle\Testing\SuluTestCase;
10+
use Symfony\Component\HttpFoundation\Response;
11+
12+
class EventRegistrationControllerTest extends SuluTestCase
13+
{
14+
use EventTrait;
15+
use EventRegistrationTrait;
16+
17+
public function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->purgeDatabase();
22+
}
23+
24+
public function testCGet(): void
25+
{
26+
$client = $this->createAuthenticatedClient();
27+
28+
$event1 = $this->createEvent('Sulu is awesome', 'de');
29+
$event2 = $this->createEvent('Symfony live is awesome', 'de');
30+
31+
$registration1 = $this->createEventRegistration($event1, 'Max', 'Mustermann');
32+
$registration2 = $this->createEventRegistration($event2, 'Mira', 'Musterfrau');
33+
34+
$client->request('GET', '/admin/api/events/' . $event1->getId() . '/registrations');
35+
36+
$response = $client->getResponse();
37+
$this->assertInstanceOf(Response::class, $response);
38+
$result = json_decode($response->getContent(), true);
39+
$this->assertHttpStatusCode(200, $response);
40+
41+
$this->assertSame(1, $result['total']);
42+
$this->assertCount(1, $result['_embedded']['event_registrations']);
43+
$items = $result['_embedded']['event_registrations'];
44+
45+
$this->assertSame($registration1->getId(), $items[0]['id']);
46+
47+
$this->assertSame($registration1->getFirstName(), $items[0]['firstName']);
48+
$this->assertSame($registration1->getLastName(), $items[0]['lastName']);
49+
$this->assertArrayHasKey('email', $items[0]);
50+
}
51+
}

tests/Functional/Traits/EventRegistrationTrait.php

+14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111

1212
trait EventRegistrationTrait
1313
{
14+
public function createEventRegistration(Event $event, string $firstName, string $lastName): EventRegistration
15+
{
16+
$event = $this->getEventRegistrationRepository()->create($event);
17+
$event->setFirstName($firstName);
18+
$event->setLastName($lastName);
19+
$event->setEmail($firstName . '@' . $lastName . '.at');
20+
$event->setMessage('');
21+
22+
$this->getEntityManager()->persist($event);
23+
$this->getEntityManager()->flush();
24+
25+
return $event;
26+
}
27+
1428
/**
1529
* @return EventRegistration[]
1630
*/

translations/admin.de.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"app.events": "Veranstaltungen",
3+
"app.registrations": "Registrierungen",
34
"app.teaser": "Kurzbeschreibung",
45
"app.start_date": "Start",
56
"app.end_date": "Ende",

translations/admin.en.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"app.events": "Events",
3+
"app.registrations": "Registrations",
34
"app.teaser": "Teaser",
45
"app.start_date": "Start",
56
"app.end_date": "Ende",

0 commit comments

Comments
 (0)