mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 17:13:49 +00:00
Activity Form : display field according to the parameters
This commit is contained in:
@@ -22,11 +22,12 @@
|
||||
|
||||
namespace Chill\ActivityBundle\Controller;
|
||||
|
||||
use Chill\ActivityBundle\Form\ActivitySelectTypeType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@@ -69,7 +70,7 @@ class ActivityController extends AbstractController
|
||||
* Lists all Activity entities.
|
||||
*
|
||||
*/
|
||||
public function listAction($person_id, Request $request)
|
||||
public function listAction($person_id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
@@ -102,31 +103,21 @@ class ActivityController extends AbstractController
|
||||
));
|
||||
}
|
||||
|
||||
public function selectTypeAction(int $person_id, Request $request): Response
|
||||
public function selectTypeAction(int $person_id): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
$person = $em->getRepository(Person::class)->find($person_id);
|
||||
|
||||
if ($person === NULL) {
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$form = $this->createForm(ActivitySelectTypeType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$activityType = $form->get('type')->getData();
|
||||
if ($activityType instanceof \Chill\ActivityBundle\Entity\ActivityType) {
|
||||
return $this->redirectToRoute('chill_activity_activity_new', [
|
||||
'person_id' => $person->getId(),
|
||||
'activityType_id' => $activityType->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
$activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
|
||||
->findBy(['active' => true]);
|
||||
|
||||
return $this->render('ChillActivityBundle:Activity:selectType.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'person' => $person
|
||||
'person' => $person,
|
||||
'activityTypes' => $activityTypes,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -191,20 +182,17 @@ class ActivityController extends AbstractController
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(Activity $entity)
|
||||
private function createCreateForm(Activity $entity): FormInterface
|
||||
{
|
||||
$form = $this->createForm(ActivityType::class, $entity,
|
||||
array(
|
||||
'action' => $this->generateUrl('chill_activity_activity_create', [
|
||||
'person_id' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE')
|
||||
)
|
||||
);
|
||||
|
||||
return $form;
|
||||
return $this->createForm(ActivityType::class, $entity, [
|
||||
'action' => $this->generateUrl('chill_activity_activity_create', [
|
||||
'person_id' => $entity->getPerson()->getId(),
|
||||
]),
|
||||
'method' => 'POST',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_ACTIVITY_CREATE'),
|
||||
'activityType' => $entity->getType(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +212,8 @@ class ActivityController extends AbstractController
|
||||
$activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
|
||||
->find($activityType_id);
|
||||
|
||||
if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType) {
|
||||
if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType ||
|
||||
!$activityType->isActive()) {
|
||||
return $this->redirectToRoute('chill_activity_activity_select_type', [
|
||||
'person_id' => $person->getId(),
|
||||
]);
|
||||
@@ -240,7 +229,7 @@ class ActivityController extends AbstractController
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity);
|
||||
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form = $this->createCreateForm($entity);
|
||||
|
||||
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
||||
'person' => $person,
|
||||
@@ -333,24 +322,21 @@ class ActivityController extends AbstractController
|
||||
* Creates a form to edit a Activity entity.
|
||||
*
|
||||
* @param Activity $entity The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Activity $entity)
|
||||
private function createEditForm(Activity $entity): FormInterface
|
||||
{
|
||||
$form = $this->createForm(ActivityType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_activity_activity_update',
|
||||
array(
|
||||
'id' => $entity->getId(),
|
||||
'person_id' => $entity->getPerson()->getId()
|
||||
)),
|
||||
return $this->createForm(ActivityType::class, $entity, [
|
||||
'action' => $this->generateUrl('chill_activity_activity_update', [
|
||||
'id' => $entity->getId(),
|
||||
'person_id' => $entity->getPerson()->getId()
|
||||
]),
|
||||
'method' => 'PUT',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_ACTIVITY_UPDATE')
|
||||
));
|
||||
|
||||
return $form;
|
||||
'role' => new Role('CHILL_ACTIVITY_UPDATE'),
|
||||
'activityType' => $entity->getType(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits an existing Activity entity.
|
||||
*
|
||||
|
Reference in New Issue
Block a user