mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
fix deprecations: replace many strings by fqcn
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2016, Champs Libres Cooperative SCRLFS,
|
||||
* Copyright (C) 2016, 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
|
||||
@@ -23,6 +23,7 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Form\Type\AddressType;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
@@ -37,97 +38,97 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
*/
|
||||
class PersonAddressController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function listAction($person_id)
|
||||
{
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found ");
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_SEE',
|
||||
$person,
|
||||
"You are not allowed to edit this person."
|
||||
);
|
||||
|
||||
|
||||
return $this->render('ChillPersonBundle:Address:list.html.twig', array(
|
||||
'person' => $person
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function newAction($person_id)
|
||||
{
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found ");
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_UPDATE',
|
||||
$person,
|
||||
"You are not allowed to edit this person."
|
||||
);
|
||||
|
||||
|
||||
$address = new Address();
|
||||
|
||||
|
||||
$form = $this->createCreateForm($person, $address);
|
||||
|
||||
|
||||
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
|
||||
'person' => $person,
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function createAction($person_id, Request $request)
|
||||
{
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found ");
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_UPDATE',
|
||||
$person,
|
||||
"You are not allowed to edit this person."
|
||||
);
|
||||
|
||||
|
||||
$address = new Address();
|
||||
|
||||
|
||||
$form = $this->createCreateForm($person, $address);
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
$person->addAddress($address);
|
||||
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
$validatePersonErrors = $this->validatePerson($person);
|
||||
|
||||
|
||||
if (count($validatePersonErrors) !== 0) {
|
||||
foreach ($validatePersonErrors as $error) {
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
}
|
||||
} elseif ($form->isValid()) {
|
||||
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->flush();
|
||||
|
||||
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->get('translator')->trans('The new address was created successfully')
|
||||
);
|
||||
|
||||
|
||||
return $this->redirectToRoute('chill_person_address_list', array(
|
||||
'person_id' => $person->getId()
|
||||
));
|
||||
@@ -136,66 +137,66 @@ class PersonAddressController extends Controller
|
||||
->trans('Error! Address not created!'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
|
||||
'person' => $person,
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function editAction($person_id, $address_id)
|
||||
{
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found ");
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_UPDATE',
|
||||
$person,
|
||||
"You are not allowed to edit this person."
|
||||
);
|
||||
|
||||
|
||||
$address = $this->findAddressById($person, $address_id);
|
||||
|
||||
|
||||
$form = $this->createEditForm($person, $address);
|
||||
|
||||
|
||||
return $this->render('ChillPersonBundle:Address:edit.html.twig', array(
|
||||
'person' => $person,
|
||||
'address' => $address,
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function updateAction($person_id, $address_id, Request $request)
|
||||
{
|
||||
$person = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillPersonBundle:Person')
|
||||
->find($person_id);
|
||||
|
||||
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found ");
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_UPDATE',
|
||||
$person,
|
||||
"You are not allowed to edit this person."
|
||||
);
|
||||
|
||||
|
||||
$address = $this->findAddressById($person, $address_id);
|
||||
|
||||
|
||||
$form = $this->createEditForm($person, $address);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
|
||||
if ($request->getMethod() === 'POST') {
|
||||
$validatePersonErrors = $this->validatePerson($person);
|
||||
|
||||
|
||||
if (count($validatePersonErrors) !== 0) {
|
||||
foreach ($validatePersonErrors as $error) {
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
@@ -203,11 +204,11 @@ class PersonAddressController extends Controller
|
||||
} elseif ($form->isValid()) {
|
||||
$this->getDoctrine()->getManager()
|
||||
->flush();
|
||||
|
||||
|
||||
$this->addFlash('success', $this->get('translator')->trans(
|
||||
"The address has been successfully updated"
|
||||
));
|
||||
|
||||
|
||||
return $this->redirectToRoute('chill_person_address_list', array(
|
||||
'person_id' => $person->getId()
|
||||
));
|
||||
@@ -216,14 +217,14 @@ class PersonAddressController extends Controller
|
||||
->trans('Error when updating the period'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->render('ChillPersonBundle:Address:edit.html.twig', array(
|
||||
'person' => $person,
|
||||
'address' => $address,
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Person $person
|
||||
* @param Address $address
|
||||
@@ -238,16 +239,16 @@ class PersonAddressController extends Controller
|
||||
'address_id' => $address->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array(
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Submit'
|
||||
));
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param Person $person
|
||||
* @param Address $address
|
||||
* @return \Symfony\Component\Form\Form
|
||||
@@ -260,16 +261,16 @@ class PersonAddressController extends Controller
|
||||
'person_id' => $person->getId()
|
||||
))
|
||||
));
|
||||
|
||||
$form->add('submit', 'submit', array(
|
||||
|
||||
$form->add('submit', SubmitType::class, array(
|
||||
'label' => 'Submit'
|
||||
));
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param Person $person
|
||||
* @param int $address_id
|
||||
* @return Address
|
||||
@@ -282,15 +283,15 @@ class PersonAddressController extends Controller
|
||||
->where(Criteria::expr()->eq('id', $address_id))
|
||||
->setMaxResults(1);
|
||||
$addresses = $person->getAddresses()->matching($criteria);
|
||||
|
||||
|
||||
if (count($addresses) === 0) {
|
||||
throw $this->createNotFoundException("Address with id $address_id "
|
||||
. "matching person $person_id not found ");
|
||||
}
|
||||
|
||||
|
||||
return $addresses->first();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Chill\PersonBundle\Entity\Person $person
|
||||
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
|
||||
@@ -301,11 +302,11 @@ class PersonAddressController extends Controller
|
||||
->validate($person, array('Default'));
|
||||
$errors_addresses_consistent = $this->get('validator')
|
||||
->validate($person, array('addresses_consistent'));
|
||||
|
||||
|
||||
foreach($errors_addresses_consistent as $error) {
|
||||
$errors->add($error);
|
||||
}
|
||||
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user