mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add first step to select Activity Type
This commit is contained in:
parent
dad8fd5378
commit
ff450215c6
@ -22,6 +22,7 @@
|
||||
|
||||
namespace Chill\ActivityBundle\Controller;
|
||||
|
||||
use Chill\ActivityBundle\Form\ActivitySelectTypeType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -29,9 +30,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ActivityBundle\Form\ActivityType;
|
||||
|
||||
/**
|
||||
@ -41,27 +42,18 @@ use Chill\ActivityBundle\Form\ActivityType;
|
||||
*/
|
||||
class ActivityController extends AbstractController
|
||||
{
|
||||
protected EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $eventDispatcher;
|
||||
protected AuthorizationHelper $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* ActivityController constructor.
|
||||
*
|
||||
* @param EventDispatcherInterface $eventDispatcher
|
||||
* @param AuthorizationHelper $authorizationHelper
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
@ -89,7 +81,7 @@ class ActivityController extends AbstractController
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$reachableScopes = $this->authorizationHelper
|
||||
->getReachableScopes($this->getUser(), new Role('CHILL_ACTIVITY_SEE'),
|
||||
->getReachableCircles($this->getUser(), new Role('CHILL_ACTIVITY_SEE'),
|
||||
$person->getCenter());
|
||||
|
||||
$activities = $em->getRepository('ChillActivityBundle:Activity')
|
||||
@ -109,6 +101,35 @@ class ActivityController extends AbstractController
|
||||
'person' => $person
|
||||
));
|
||||
}
|
||||
|
||||
public function selectTypeAction(int $person_id, Request $request): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('ChillActivityBundle:Activity:selectType.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'person' => $person
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Activity entity.
|
||||
*
|
||||
@ -126,7 +147,7 @@ class ActivityController extends AbstractController
|
||||
|
||||
$entity = new Activity();
|
||||
$entity->setPerson($person);
|
||||
$form = $this->createCreateForm($entity, $person);
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
@ -190,7 +211,7 @@ class ActivityController extends AbstractController
|
||||
* Displays a form to create a new Activity entity.
|
||||
*
|
||||
*/
|
||||
public function newAction($person_id)
|
||||
public function newAction($person_id, Request $request)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
|
||||
@ -199,16 +220,27 @@ class ActivityController extends AbstractController
|
||||
throw $this->createNotFoundException('Person not found');
|
||||
}
|
||||
|
||||
$activityType_id = $request->get('activityType_id', 0);
|
||||
$activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class)
|
||||
->find($activityType_id);
|
||||
|
||||
if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType) {
|
||||
return $this->redirectToRoute('chill_activity_activity_select_type', [
|
||||
'person_id' => $person->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||
|
||||
$entity = new Activity();
|
||||
$entity->setUser($this->get('security.token_storage')->getToken()->getUser());
|
||||
$entity->setUser($this->getUser());
|
||||
$entity->setPerson($person);
|
||||
$entity->setType($activityType);
|
||||
$entity->setDate(new \DateTime('now'));
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity);
|
||||
|
||||
$form = $this->createCreateForm($entity, $person);
|
||||
$form = $this->createCreateForm($entity);
|
||||
|
||||
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
|
||||
'person' => $person,
|
||||
|
@ -235,6 +235,7 @@ class ActivityType
|
||||
*/
|
||||
public function getName(?string $locale = null)
|
||||
{
|
||||
// TODO
|
||||
if ($locale) {
|
||||
if (isset($this->name[$locale])) {
|
||||
return $this->name[$locale];
|
||||
|
@ -72,22 +72,9 @@ class ActivityTypeCategory
|
||||
*
|
||||
* @return array | string
|
||||
*/
|
||||
public function getName(?string $locale = null)
|
||||
public function getName(): array
|
||||
{
|
||||
if ($locale) {
|
||||
if (isset($this->name[$locale])) {
|
||||
return $this->name[$locale];
|
||||
} else {
|
||||
foreach ($this->name as $name) {
|
||||
if (!empty($name)) {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
return $this->name;
|
||||
}
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\ActivityBundle\Form;
|
||||
|
||||
use Chill\ActivityBundle\Form\Type\TranslatableActivityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class ActivitySelectTypeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('type', TranslatableActivityType::class, array(
|
||||
'placeholder' => 'Choose a type',
|
||||
'active_only' => true,
|
||||
'mapped' => false,
|
||||
));
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTra
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Chill\ActivityBundle\Form\Type\TranslatableActivityType;
|
||||
use Chill\ActivityBundle\Form\Type\TranslatableActivityReason;
|
||||
use Chill\MainBundle\Form\Type\UserPickerType;
|
||||
@ -24,7 +23,6 @@ use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
|
||||
class ActivityType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
* the user running this form
|
||||
*
|
||||
@ -36,7 +34,7 @@ class ActivityType extends AbstractType
|
||||
*
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
protected AuthorizationHelper $authorizationHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -113,10 +111,6 @@ class ActivityType extends AbstractType
|
||||
'multiple' => true,
|
||||
'required' => false,
|
||||
))
|
||||
->add('type', TranslatableActivityType::class, array(
|
||||
'placeholder' => 'Choose a type',
|
||||
'active_only' => true
|
||||
))
|
||||
->add('comment', CommentType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
|
@ -21,7 +21,7 @@
|
||||
{% block title 'Activity creation' |trans %}
|
||||
|
||||
{% block personcontent %}
|
||||
<h2 class="chill-red">{{ "Activity creation"|trans }}</h1>
|
||||
<h2 class="chill-red">{{ "Activity creation"|trans }}</h2>
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
@ -32,14 +32,13 @@
|
||||
|
||||
{{ form_row(form.date) }}
|
||||
{{ form_row(form.durationTime) }}
|
||||
{{ form_row(form.type) }}
|
||||
{{ form_row(form.attendee) }}
|
||||
{{ form_row(form.reasons) }}
|
||||
{{ form_row(form.comment) }}
|
||||
|
||||
<div class="grid-12 centered sticky-form-buttons">
|
||||
<button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Add a new activity'|trans }}</button>
|
||||
</div>
|
||||
<div class="grid-12 centered sticky-form-buttons">
|
||||
<button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Add a new activity'|trans }}</button>
|
||||
</div>
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
{% extends "@ChillPerson/layout.html.twig" %}
|
||||
|
||||
{% set activeRouteKey = 'chill_activity_activity_new' %}
|
||||
|
||||
{% block title 'Activity creation'|trans %}
|
||||
|
||||
{% block personcontent %}
|
||||
<h2 class="chill-red">{{ "Activity creation"|trans }}</h2>
|
||||
|
||||
{{ form_start(form) }}
|
||||
|
||||
{{ form_row(form.type) }}
|
||||
|
||||
<div class="grid-12 centered sticky-form-buttons">
|
||||
<button class="sc-button green margin-10" type="submit"><i class="fa fa-save"></i> {{ 'Next Step'|trans }}</button>
|
||||
</div>
|
||||
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
@ -6,6 +6,10 @@ chill_activity_activity_show:
|
||||
path: /{_locale}/person/{person_id}/activity/{id}/show
|
||||
controller: Chill\ActivityBundle\Controller\ActivityController::showAction
|
||||
|
||||
chill_activity_activity_select_type:
|
||||
path: /{_locale}/person/{person_id}/activity/select-type
|
||||
controller: Chill\ActivityBundle\Controller\ActivityController::selectTypeAction
|
||||
|
||||
chill_activity_activity_new:
|
||||
path: /{_locale}/person/{person_id}/activity/new
|
||||
controller: Chill\ActivityBundle\Controller\ActivityController::newAction
|
||||
|
Loading…
x
Reference in New Issue
Block a user