-
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
3916d1e
commit abf77bf
Showing
10 changed files
with
172 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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Admin; | ||
|
||
use App\Common\DoctrineListRepresentationFactory; | ||
use App\Entity\EventRegistration; | ||
use FOS\RestBundle\Controller\Annotations\RouteResource; | ||
use FOS\RestBundle\Routing\ClassResourceInterface; | ||
use FOS\RestBundle\View\ViewHandlerInterface; | ||
use Sulu\Component\Rest\AbstractRestController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
|
||
/** | ||
* @RouteResource("event_registration") | ||
*/ | ||
class EventRegistrationController extends AbstractRestController implements ClassResourceInterface | ||
{ | ||
/** | ||
* @var DoctrineListRepresentationFactory | ||
*/ | ||
private $doctrineListRepresentationFactory; | ||
|
||
public function __construct( | ||
DoctrineListRepresentationFactory $doctrineListRepresentationFactory, | ||
ViewHandlerInterface $viewHandler, | ||
?TokenStorageInterface $tokenStorage = null | ||
) { | ||
$this->doctrineListRepresentationFactory = $doctrineListRepresentationFactory; | ||
|
||
parent::__construct($viewHandler, $tokenStorage); | ||
} | ||
|
||
public function cgetAction(int $eventId): Response | ||
{ | ||
$listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation( | ||
EventRegistration::RESOURCE_KEY, | ||
['eventId' => $eventId] | ||
); | ||
|
||
return $this->handleView($this->view($listRepresentation)); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
*/ | ||
class EventRegistration | ||
{ | ||
const RESOURCE_KEY = 'event_registrations'; | ||
|
||
/** | ||
* @var int|null | ||
* | ||
|
54 changes: 54 additions & 0 deletions
54
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,54 @@ | ||
<?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; | ||
|
||
/** | ||
* @var KernelBrowser | ||
*/ | ||
private $client; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->client = $this->createAuthenticatedClient(); | ||
$this->purgeDatabase(); | ||
} | ||
|
||
public function testCGet(): 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->request('GET', '/admin/api/events/' . $event1->getId() . '/registrations'); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertInstanceOf(Response::class, $response); | ||
$result = json_decode($response->getContent() ?: '', true); | ||
$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