Merge remote-tracking branch 'origin/master' into issue557_address_civility_in_form_person

This commit is contained in:
2022-05-06 10:21:13 +02:00
403 changed files with 2662 additions and 41292 deletions

View File

@@ -33,10 +33,10 @@ use DateInterval;
use DateTimeImmutable;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Serializer\Exception\RuntimeException;
@@ -185,7 +185,7 @@ final class AccompanyingCourseApiController extends ApiController
->deserialize($request->getContent(), Person::class, $_format, []);
if (null === $person) {
throw new BadRequestException('person id not found');
throw new BadRequestHttpException('person id not found');
}
// TODO add acl
@@ -204,7 +204,7 @@ final class AccompanyingCourseApiController extends ApiController
break;
default:
throw new BadRequestException('This method is not supported');
throw new BadRequestHttpException('This method is not supported');
}
$errors = $this->validator->validate($accompanyingPeriod);
@@ -247,12 +247,12 @@ final class AccompanyingCourseApiController extends ApiController
}
if (null === $requestor) {
throw new BadRequestException('Could not find any person or thirdparty', 0, null);
throw new BadRequestHttpException('Could not find any person or thirdparty', 0, null);
}
$accompanyingPeriod->setRequestor($requestor);
} else {
throw new BadRequestException('method not supported');
throw new BadRequestHttpException('method not supported');
}
$errors = $this->validator->validate($accompanyingPeriod);

View File

@@ -186,6 +186,24 @@ class AccompanyingCourseCommentController extends AbstractController
]);
}
/**
* @Route("/{_locale}/parcours/comment/{id}/unpin", name="chill_person_accompanying_period_comment_unpin")
*/
public function unpinComment(AccompanyingPeriod\Comment $comment): Response
{
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::EDIT, $comment->getAccompanyingPeriod());
$comment->getAccompanyingPeriod()->setPinnedComment(null);
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans('accompanying_course.comment is unpinned'));
return $this->redirectToRoute('chill_person_accompanying_period_comment_list', [
'accompanying_period_id' => $comment->getAccompanyingPeriod()->getId(),
]);
}
private function createCommentForm(AccompanyingPeriod\Comment $comment, string $step): FormInterface
{
return $this->formFactory->createNamed($step, AccompanyingCourseCommentType::class, $comment);

View File

@@ -21,9 +21,9 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
@@ -255,7 +255,7 @@ class AccompanyingCourseController extends Controller
$personIds = $request->query->get('person_id');
if (false === is_array($personIds)) {
throw new BadRequestException('person_id parameter should be an array');
throw new BadRequestHttpException('person_id parameter should be an array');
}
foreach ($personIds as $personId) {

View File

@@ -451,7 +451,7 @@ class AccompanyingPeriodController extends AbstractController
private function _getPerson(int $id): Person
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')->find($id);
->getRepository(\Chill\PersonBundle\Entity\Person::class)->find($id);
if (null === $person) {
throw $this->createNotFoundException('Person not found');

View File

@@ -102,7 +102,6 @@ class HouseholdApiController extends ApiController
$event
->setPreviousAddress($household->getPreviousAddressOf($address))
->setNextAddress($address);
dump($event);
$this->eventDispatcher->dispatch($event);
}

View File

@@ -21,8 +21,8 @@ use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
@@ -202,7 +202,7 @@ class HouseholdController extends AbstractController
$this->denyAccessUnlessGranted(HouseholdVoter::EDIT, $household);
if (!$request->query->has('address_id')) {
throw new BadRequestException('parameter address_id is missing');
throw new BadRequestHttpException('parameter address_id is missing');
}
$address_id = $request->query->getInt('address_id');
@@ -218,7 +218,7 @@ class HouseholdController extends AbstractController
}
if (null === $address) {
throw new BadRequestException('The edited address does not belongs to the household');
throw new BadRequestHttpException('The edited address does not belongs to the household');
}
$form = $this->createForm(AddressDateType::class, $address, []);

View File

@@ -20,9 +20,9 @@ use Chill\PersonBundle\Form\HouseholdMemberType;
use Chill\PersonBundle\Household\MembersEditor;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Exception;
@@ -105,7 +105,7 @@ class HouseholdMemberController extends ApiController
$ids = $request->query->get('persons', []);
if (0 === count($ids)) {
throw new BadRequestException('parameters persons in query ' .
throw new BadRequestHttpException('parameters persons in query ' .
'is not an array or empty');
}
@@ -121,7 +121,8 @@ class HouseholdMemberController extends ApiController
}
}
if ($householdId = $request->query->get('household', false)) {
if ($request->query->has('household')) {
$householdId = $request->query->get('household', false);
$household = $em->getRepository(Household::class)
->find($householdId);
$allowHouseholdCreate = false;
@@ -189,7 +190,7 @@ class HouseholdMemberController extends ApiController
['groups' => ['read']]
);
} catch (Exception\InvalidArgumentException|Exception\UnexpectedValueException $e) {
throw new BadRequestException("Deserialization error: {$e->getMessage()}", 45896, $e);
throw new BadRequestHttpException("Deserialization error: {$e->getMessage()}", 45896, $e);
}
// TODO ACL

View File

@@ -43,7 +43,7 @@ class PersonAddressController extends AbstractController
public function createAction($person_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {
@@ -98,7 +98,7 @@ class PersonAddressController extends AbstractController
public function editAction($person_id, $address_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {
@@ -126,7 +126,7 @@ class PersonAddressController extends AbstractController
public function listAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {
@@ -148,7 +148,7 @@ class PersonAddressController extends AbstractController
public function newAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {
@@ -175,7 +175,7 @@ class PersonAddressController extends AbstractController
public function updateAction($person_id, $address_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->getRepository(\Chill\PersonBundle\Entity\Person::class)
->find($person_id);
if (null === $person) {

View File

@@ -159,7 +159,7 @@ final class PersonController extends AbstractController
{
$cFGroup = null;
$cFDefaultGroup = $this->em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')
$cFDefaultGroup = $this->em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup::class)
->findOneByEntity('Chill\\PersonBundle\\Entity\\Person');
if ($cFDefaultGroup) {

View File

@@ -12,13 +12,18 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -27,11 +32,18 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Validator\Constraints\NotIdenticalTo;
use Symfony\Component\Validator\Constraints\NotNull;
use function is_int;
class ReassignAccompanyingPeriodController extends AbstractController
{
private AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository;
private AccompanyingPeriodRepository $courseRepository;
private EntityManagerInterface $em;
private EngineInterface $engine;
private FormFactoryInterface $formFactory;
@@ -44,8 +56,17 @@ class ReassignAccompanyingPeriodController extends AbstractController
private UserRepository $userRepository;
public function __construct(AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
{
public function __construct(
AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository,
UserRepository $userRepository,
AccompanyingPeriodRepository $courseRepository,
EngineInterface $engine,
FormFactoryInterface $formFactory,
PaginatorFactory $paginatorFactory,
Security $security,
UserRender $userRender,
EntityManagerInterface $em
) {
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
$this->engine = $engine;
$this->formFactory = $formFactory;
@@ -53,6 +74,8 @@ class ReassignAccompanyingPeriodController extends AbstractController
$this->security = $security;
$this->userRepository = $userRepository;
$this->userRender = $userRender;
$this->courseRepository = $courseRepository;
$this->em = $em;
}
/**
@@ -68,23 +91,55 @@ class ReassignAccompanyingPeriodController extends AbstractController
$form->handleRequest($request);
$total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod(
$form['user']->getData()
);
$userFrom = $form['user']->getData();
$total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod($userFrom);
$paginator = $this->paginatorFactory->create($total);
$periods = $this->accompanyingPeriodACLAwareRepository
->findByUserOpenedAccompanyingPeriod(
$form['user']->getData(),
$userFrom,
['openingDate' => 'ASC'],
$paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber()
);
$periodIds = [];
foreach ($periods as $period) {
$periodIds[] = $period->getId();
}
// Create an array of period id's to pass into assignForm hiddenfield
$assignForm = $this->buildReassignForm($periodIds, $userFrom);
$assignForm->handleRequest($request);
if ($assignForm->isSubmitted() && $assignForm->isValid()) {
$assignPeriodIds = json_decode($assignForm->get('periods')->getData(), true);
$userTo = $assignForm->get('userTo')->getData();
$userFrom = $assignForm->get('userFrom')->getData();
foreach ($assignPeriodIds as $periodId) {
$period = $this->courseRepository->find($periodId);
if ($period->getUser() === $userFrom) {
$period->setUser($userTo);
}
}
$this->em->flush();
// redirect to the first page
return $this->redirectToRoute('chill_course_list_reassign', $request->query->all());
}
return new Response(
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
'assignForm' => $assignForm->createView(),
'form' => $form->createView(),
'paginator' => $paginator,
'periods' => $periods,
'form' => $form->createView(),
'userFrom' => $userFrom,
])
);
}
@@ -98,17 +153,63 @@ class ReassignAccompanyingPeriodController extends AbstractController
'method' => 'get', 'csrf_protection' => false, ]);
$builder
->add('user', EntityType::class, [
'class' => User::class,
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
'choice_label' => function (User $u) {
return $this->userRender->renderString($u, []);
},
->add('user', PickUserDynamicType::class, [
'multiple' => false,
'label' => 'User',
'label' => 'reassign.Current user',
'required' => false,
'help' => 'reassign.Choose a user and click on "Filter" to apply',
]);
return $builder->getForm();
}
private function buildReassignForm(array $periodIds, ?User $userFrom): FormInterface
{
$defaultData = [
'userFrom' => $userFrom,
'periods' => json_encode($periodIds),
];
$builder = $this->formFactory->createNamedBuilder('reassign', FormType::class, $defaultData);
if (null !== $userFrom) {
$constraints = [new NotIdenticalTo(['value' => $userFrom])];
} else {
$constraints = [];
}
$builder
->add('periods', HiddenType::class)
->add('userFrom', HiddenType::class)
->add('userTo', PickUserDynamicType::class, [
'multiple' => false,
'label' => 'reassign.Next user',
'required' => true,
'help' => 'reassign.All periods on this list will be reassigned to this user, excepted the one you manually reassigned before',
'constraints' => [new NotNull()],
]);
$builder->get('userFrom')->addModelTransformer(new CallbackTransformer(
static function (?User $user) {
if (null === $user) {
return '';
}
return $user->getId();
},
function (?string $id) {
if (null === $id) {
return null;
}
if (!is_int((int) $id)) {
throw new TransformationFailedException('the user id is not a numeric');
}
return $this->userRepository->find((int) $id);
}
));
return $builder->getForm();
}
}