mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
Adding validation for the event
This commit is contained in:
commit
0246dadd15
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\EventBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
public function indexAction($name)
|
||||
{
|
||||
return $this->render('ChillEventBundle:Default:index.html.twig', array('name' => $name));
|
||||
}
|
||||
}
|
@ -148,4 +148,94 @@ class ParticipationController extends Controller
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* show an edit form for the participation with the given id.
|
||||
*
|
||||
* @param int $participation_id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
|
||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation
|
||||
*/
|
||||
public function editAction($participation_id)
|
||||
{
|
||||
/* @var $participation Participation */
|
||||
$participation = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillEventBundle:Participation')
|
||||
->find($participation_id);
|
||||
|
||||
if ($participation === NULL) {
|
||||
throw $this->createNotFoundException('The participation is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
'You are not allowed to edit this participation');
|
||||
|
||||
$form = $this->createEditForm($participation);
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
public function updateAction($participation_id, Request $request)
|
||||
{
|
||||
/* @var $participation Participation */
|
||||
$participation = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillEventBundle:Participation')
|
||||
->find($participation_id);
|
||||
|
||||
if ($participation === NULL) {
|
||||
throw $this->createNotFoundException('The participation is not found');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||
'You are not allowed to edit this participation');
|
||||
|
||||
$form = $this->createEditForm($participation);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans(
|
||||
'The participation was updated'
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('event_show', array(
|
||||
'event_id' => $participation->getEvent()->getId()
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'participation' => $participation
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Participation $participation
|
||||
* @return \Symfony\Component\Form\FormInterface
|
||||
*/
|
||||
public function createEditForm(Participation $participation)
|
||||
{
|
||||
$form = $this->createForm(ParticipationType::class, $participation, array(
|
||||
'event_type' => $participation->getEvent()->getType(),
|
||||
'action' => $this->generateUrl('chill_event_participation_update', array(
|
||||
'participation_id' => $participation->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Edit'
|
||||
));
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,3 +5,12 @@ chill_event_participation_new:
|
||||
chill_event_participation_create:
|
||||
path: /create
|
||||
defaults: { _controller: ChillEventBundle:Participation:create }
|
||||
|
||||
chill_event_participation_edit:
|
||||
path: /{participation_id}/edit
|
||||
defaults: { _controller: ChillEventBundle:Participation:edit }
|
||||
|
||||
chill_event_participation_update:
|
||||
path: /{participation_id}/update
|
||||
defaults: { _controller: ChillEventBundle:Participation:update }
|
||||
methods: [POST]
|
||||
|
@ -19,6 +19,7 @@ Associated person: Personne associée
|
||||
Associated event: Événement associé
|
||||
Back to the event: Retour à l'événement
|
||||
The participation was created: La participation a été créée
|
||||
The participation was updated: La participation a été mise à jour
|
||||
|
||||
#search
|
||||
Event search: Recherche d'événements
|
||||
|
@ -1 +0,0 @@
|
||||
Hello {{ name }}!
|
@ -57,14 +57,17 @@
|
||||
<td>{{ person_macro.render(participation.person) }}</td>
|
||||
<td>{{ participation.role.label|localize_translatable_string }}</td>
|
||||
<td>{{ participation.status.label|localize_translatable_string }}</td>
|
||||
<td>{{ participation.lastUpdate|localizeddate("long", "none") }}</td>
|
||||
<td>{{ participation.lastUpdate|time_diff }} <i class="fa fa-calendar-o" title="{{ participation.lastUpdate|localizeddate("long", "medium")|escape('html_attr') }}"></i></td>
|
||||
<td>
|
||||
<ul class="record_actions">
|
||||
{% if is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %}
|
||||
<li>
|
||||
<a href="#" class="sc-button btn-edit">
|
||||
<a href="{{ path('chill_event_participation_edit', { 'participation_id' : participation.id } ) }}"
|
||||
class="sc-button btn-edit">
|
||||
{{ 'Edit'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
41
Resources/views/Participation/edit.html.twig
Normal file
41
Resources/views/Participation/edit.html.twig
Normal file
@ -0,0 +1,41 @@
|
||||
{% extends 'ChillEventBundle::layout.html.twig' %}
|
||||
|
||||
{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %}
|
||||
|
||||
{% block event_content -%}
|
||||
<h1>{{ 'Participation Edit'|trans }}</h1>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{{ 'Associated person'|trans }}</th>
|
||||
<td>{{ person_macro.render(participation.person) }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{ 'Associated event'|trans }} </th>
|
||||
<td>{{ participation.event.label }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{ 'Date'|trans }} </th>
|
||||
<td>{{ participation.event.date|localizeddate('long', 'none') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_row(form.role) }}
|
||||
{{ form_row(form.status) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('event_show', { 'event_id' : participation.event.id } ) }}" class="sc-button btn-cancel">
|
||||
{{ 'Back to the event'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ form_widget(form.submit, { 'attr' : { 'class' : 'sc-button btn-create' } } ) }}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
@ -2,6 +2,8 @@
|
||||
|
||||
{% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %}
|
||||
|
||||
{% block title 'Participation creation'|trans %}
|
||||
|
||||
{% block event_content -%}
|
||||
<h1>{{ 'Participation creation'|trans }}</h1>
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\EventBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user