fix deprecations: use fqcn in the activity bundle

This commit is contained in:
nobohan 2018-04-05 10:34:41 +02:00
parent b6f9d1156e
commit 6327d25783
7 changed files with 69 additions and 60 deletions

View File

@ -3,7 +3,7 @@
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
@ -24,6 +24,7 @@ namespace Chill\ActivityBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\ActivityBundle\Entity\Activity;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Entity\Person;
@ -43,23 +44,23 @@ class ActivityController extends Controller
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
if ($person === NULL) {
throw $this->createNotFoundException('Person not found');
}
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$reachableScopes = $this->get('chill.main.security.authorization.helper')
->getReachableScopes($this->getUser(), new Role('CHILL_ACTIVITY_SEE'),
$person->getCenter());
$activities = $em->getRepository('ChillActivityBundle:Activity')
->findBy(
array('person' => $person, 'scope' => $reachableScopes),
array('date' => 'DESC')
);
return $this->render('ChillActivityBundle:Activity:list.html.twig', array(
'activities' => $activities,
@ -74,13 +75,13 @@ class ActivityController extends Controller
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
if ($person === NULL) {
throw $this->createNotFoundException('person not found');
}
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$entity = new Activity();
$entity->setPerson($person);
$form = $this->createCreateForm($entity, $person);
@ -88,16 +89,16 @@ class ActivityController extends Controller
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity,
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity,
'creation of this activity not allowed');
$em->persist($entity);
$em->flush();
$this->get('session')
->getFlashBag()
->add('success',
->add('success',
$this->get('translator')
->trans('Success : activity created!')
);
@ -106,7 +107,7 @@ class ActivityController extends Controller
$this->generateUrl('chill_activity_activity_show',
array('id' => $entity->getId(), 'person_id' => $person_id)));
}
$this->get('session')
->getFlashBag()->add('danger',
$this->get('translator')
@ -129,7 +130,7 @@ class ActivityController extends Controller
*/
private function createCreateForm(Activity $entity)
{
$form = $this->createForm('chill_activitybundle_activity', $entity,
$form = $this->createForm('chill_activitybundle_activity', $entity,
array(
'action' => $this->generateUrl('chill_activity_activity_create', [
'person_id' => $entity->getPerson()->getId(),
@ -151,20 +152,20 @@ class ActivityController extends Controller
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
if ($person === NULL){
throw $this->createNotFoundException('Person not found');
}
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$entity = new Activity();
$entity->setUser($this->get('security.token_storage')->getToken()->getUser());
$entity->setPerson($person);
$entity->setDate(new \DateTime('now'));
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity);
$form = $this->createCreateForm($entity, $person);
return $this->render('ChillActivityBundle:Activity:new.html.twig', array(
@ -182,11 +183,11 @@ class ActivityController extends Controller
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
if (!$person) {
throw $this->createNotFoundException('person not found');
}
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$entity = $em->getRepository('ChillActivityBundle:Activity')->find($id);
@ -194,7 +195,7 @@ class ActivityController extends Controller
if (!$entity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity);
$deleteForm = $this->createDeleteForm($id, $person);
@ -214,11 +215,11 @@ class ActivityController extends Controller
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
if (!$person) {
throw $this->createNotFoundException('person not found');
}
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
$entity = $em->getRepository('ChillActivityBundle:Activity')->find($id);
@ -226,7 +227,7 @@ class ActivityController extends Controller
if (!$entity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
$editForm = $this->createEditForm($entity);
@ -250,9 +251,9 @@ class ActivityController extends Controller
private function createEditForm(Activity $entity)
{
$form = $this->createForm('chill_activitybundle_activity', $entity, array(
'action' => $this->generateUrl('chill_activity_activity_update',
'action' => $this->generateUrl('chill_activity_activity_update',
array(
'id' => $entity->getId(),
'id' => $entity->getId(),
'person_id' => $entity->getPerson()->getId()
)),
'method' => 'PUT',
@ -269,14 +270,14 @@ class ActivityController extends Controller
public function updateAction(Request $request, $person_id, $id)
{
$em = $this->getDoctrine()->getManager();
$person = $em->getRepository('ChillPersonBundle:Person')->find($person_id);
$entity = $em->getRepository('ChillActivityBundle:Activity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
$deleteForm = $this->createDeleteForm($id, $person);
@ -285,17 +286,17 @@ class ActivityController extends Controller
if ($editForm->isValid()) {
$em->flush();
$this->get('session')
->getFlashBag()
->add('success',
->add('success',
$this->get('translator')
->trans('Success : activity updated!')
);
//die();
return $this->redirect($this->generateUrl('chill_activity_activity_show', array('id' => $id, 'person_id' => $person_id)));
}
$this->get('session')
->getFlashBag()
->add('danger',
@ -309,7 +310,7 @@ class ActivityController extends Controller
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Activity entity.
*
@ -317,7 +318,7 @@ class ActivityController extends Controller
public function deleteAction(Request $request, $id, $person_id)
{
$em = $this->getDoctrine()->getManager();
/* @var $activity Activity */
$activity = $em->getRepository('ChillActivityBundle:Activity')
->find($id);
@ -326,17 +327,17 @@ class ActivityController extends Controller
if (!$activity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity);
$form = $this->createDeleteForm($id, $person);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$logger = $this->get('chill.main.logger');
$logger->notice("An activity has been removed", array(
'by_user' => $this->getUser()->getUsername(),
'activity_id' => $activity->getId(),
@ -351,26 +352,26 @@ class ActivityController extends Controller
'date' => $activity->getDate()->format('Y-m-d'),
'attendee' => $activity->getAttendee()
));
$em->remove($activity);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The activity has been successfully removed."));
return $this->redirect($this->generateUrl(
'chill_activity_activity_list', array(
'person_id' => $person_id
)));
}
}
return $this->render('ChillActivityBundle:Activity:confirm_delete.html.twig', array(
'activity' => $activity,
'delete_form' => $form->createView()
));
}
/**
@ -387,7 +388,7 @@ class ActivityController extends Controller
'chill_activity_activity_delete',
array('id' => $id, 'person_id' => $person->getId())))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->add('submit', SubmitType::class, array('label' => 'Delete'))
->getForm()
;
}

View File

@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\ActivityBundle\Entity\ActivityReasonCategory;
use Chill\ActivityBundle\Form\ActivityReasonCategoryType;
@ -67,7 +68,7 @@ class ActivityReasonCategoryController extends Controller
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
$form->add('submit', SubmitType::class, array('label' => 'Create'));
return $form;
}
@ -142,7 +143,7 @@ class ActivityReasonCategoryController extends Controller
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
$form->add('submit', SubmitType::class, array('label' => 'Update'));
return $form;
}

View File

@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Form\ActivityReasonType;
@ -67,7 +68,7 @@ class ActivityReasonController extends Controller
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
$form->add('submit', SubmitType::class, array('label' => 'Create'));
return $form;
}
@ -142,7 +143,7 @@ class ActivityReasonController extends Controller
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
$form->add('submit', SubmitType::class, array('label' => 'Update'));
return $form;
}

View File

@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\ActivityBundle\Entity\ActivityType;
use Chill\ActivityBundle\Form\ActivityTypeType;
@ -67,7 +68,7 @@ class ActivityTypeController extends Controller
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
$form->add('submit', SubmitType::class, array('label' => 'Create'));
return $form;
}
@ -142,7 +143,7 @@ class ActivityTypeController extends Controller
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
$form->add('submit', SubmitType::class, array('label' => 'Update'));
return $form;
}
@ -159,7 +160,7 @@ class ActivityTypeController extends Controller
if (!$entity) {
throw $this->createNotFoundException('Unable to find ActivityType entity.');
}
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);

View File

@ -5,6 +5,8 @@ namespace Chill\ActivityBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ActivityReasonCategoryType extends AbstractType
{
@ -15,8 +17,8 @@ class ActivityReasonCategoryType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'translatable_string')
->add('active', 'checkbox', array('required' => false))
->add('name', TranslatableStringFormType::class)
->add('active', CheckboxType::class, array('required' => false))
;
}

View File

@ -5,6 +5,8 @@ namespace Chill\ActivityBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ActivityReasonType extends AbstractType
{
@ -15,8 +17,8 @@ class ActivityReasonType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'translatable_string')
->add('active', 'checkbox', array('required' => false))
->add('name', TranslatableStringFormType::class)
->add('active', CheckboxType::class, array('required' => false))
->add('category', 'translatable_activity_reason_category')
;
}

View File

@ -6,6 +6,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
class ActivityTypeType extends AbstractType
{
@ -16,7 +17,7 @@ class ActivityTypeType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'translatable_string')
->add('name', TranslatableStringFormType::class)
->add('active', ChoiceType::class, array(
'choices' => array(
'Yes' => true,
@ -26,7 +27,7 @@ class ActivityTypeType extends AbstractType
'expanded' => true
));
}
/**
* @param OptionsResolverInterface $resolver
*/