mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
fix: Fix wrong entity class and a few other fixes.
This commit is contained in:
parent
597a12b085
commit
17ef963924
@ -5,18 +5,20 @@ declare(strict_types=1);
|
|||||||
namespace Chill\ActivityBundle\Controller;
|
namespace Chill\ActivityBundle\Controller;
|
||||||
|
|
||||||
use Chill\ActivityBundle\Entity\ActivityReason;
|
use Chill\ActivityBundle\Entity\ActivityReason;
|
||||||
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
|
|
||||||
use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
||||||
|
use Chill\ActivityBundle\Repository\ActivityRepository;
|
||||||
|
use Chill\ActivityBundle\Repository\ActivityTypeRepository;
|
||||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||||
use Chill\MainBundle\Entity\Location;
|
use Chill\MainBundle\Repository\LocationRepository;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\Form;
|
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@ -30,26 +32,50 @@ use Symfony\Component\Serializer\SerializerInterface;
|
|||||||
|
|
||||||
final class ActivityController extends AbstractController
|
final class ActivityController extends AbstractController
|
||||||
{
|
{
|
||||||
protected EventDispatcherInterface $eventDispatcher;
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
protected AuthorizationHelper $authorizationHelper;
|
private LoggerInterface $logger;
|
||||||
|
|
||||||
protected LoggerInterface $logger;
|
private SerializerInterface $serializer;
|
||||||
|
|
||||||
protected SerializerInterface $serializer;
|
private ActivityACLAwareRepositoryInterface $activityACLAwareRepository;
|
||||||
|
|
||||||
protected ActivityACLAwareRepositoryInterface $activityACLAwareRepository;
|
private ActivityTypeRepository $activityTypeRepository;
|
||||||
|
|
||||||
|
private ThirdPartyRepository $thirdPartyRepository;
|
||||||
|
|
||||||
|
private PersonRepository $personRepository;
|
||||||
|
|
||||||
|
private LocationRepository $locationRepository;
|
||||||
|
|
||||||
|
private EntityManagerInterface $entityManager;
|
||||||
|
|
||||||
|
private ActivityRepository $activityRepository;
|
||||||
|
|
||||||
|
private AccompanyingPeriodRepository $accompanyingPeriodRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ActivityACLAwareRepositoryInterface $activityACLAwareRepository,
|
ActivityACLAwareRepositoryInterface $activityACLAwareRepository,
|
||||||
|
ActivityTypeRepository $activityTypeRepository,
|
||||||
|
PersonRepository $personRepository,
|
||||||
|
ThirdPartyRepository $thirdPartyRepository,
|
||||||
|
LocationRepository $locationRepository,
|
||||||
|
ActivityRepository $activityRepository,
|
||||||
|
AccompanyingPeriodRepository $accompanyingPeriodRepository,
|
||||||
|
EntityManagerInterface $entityManager,
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
AuthorizationHelper $authorizationHelper,
|
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
SerializerInterface $serializer
|
SerializerInterface $serializer
|
||||||
) {
|
) {
|
||||||
$this->activityACLAwareRepository = $activityACLAwareRepository;
|
$this->activityACLAwareRepository = $activityACLAwareRepository;
|
||||||
|
$this->activityTypeRepository = $activityTypeRepository;
|
||||||
|
$this->personRepository = $personRepository;
|
||||||
|
$this->thirdPartyRepository = $thirdPartyRepository;
|
||||||
|
$this->locationRepository = $locationRepository;
|
||||||
|
$this->activityRepository = $activityRepository;
|
||||||
|
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
||||||
|
$this->entityManager = $entityManager;
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->serializer = $serializer;
|
$this->serializer = $serializer;
|
||||||
}
|
}
|
||||||
@ -98,7 +124,6 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
public function selectTypeAction(Request $request): Response
|
public function selectTypeAction(Request $request): Response
|
||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
$view = null;
|
$view = null;
|
||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
@ -111,12 +136,10 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
$activityTypeCategories = $em->getRepository(ActivityTypeCategory::class)
|
$activityTypeCategories = $this->activityTypeRepository->findBy(['active' => true], ['ordering' => 'ASC']);
|
||||||
->findBy(['active' => true], ['ordering' => 'ASC']);
|
|
||||||
|
|
||||||
foreach ($activityTypeCategories as $activityTypeCategory) {
|
foreach ($activityTypeCategories as $activityTypeCategory) {
|
||||||
$activityTypes = $em->getRepository(ActivityType::class)
|
$activityTypes = $this->activityTypeRepository->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']);
|
||||||
->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']);
|
|
||||||
|
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'activityTypeCategory' => $activityTypeCategory,
|
'activityTypeCategory' => $activityTypeCategory,
|
||||||
@ -139,7 +162,6 @@ final class ActivityController extends AbstractController
|
|||||||
public function newAction(Request $request): Response
|
public function newAction(Request $request): Response
|
||||||
{
|
{
|
||||||
$view = null;
|
$view = null;
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
|
|
||||||
@ -150,8 +172,7 @@ final class ActivityController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$activityType_id = $request->get('activityType_id', 0);
|
$activityType_id = $request->get('activityType_id', 0);
|
||||||
$activityType = $em->getRepository(ActivityType::class)
|
$activityType = $this->activityTypeRepository->find($activityType_id);
|
||||||
->find($activityType_id);
|
|
||||||
|
|
||||||
if (isset($activityType) && !$activityType->isActive()) {
|
if (isset($activityType) && !$activityType->isActive()) {
|
||||||
throw new \InvalidArgumentException('Activity type must be active');
|
throw new \InvalidArgumentException('Activity type must be active');
|
||||||
@ -209,20 +230,20 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
if (array_key_exists('personsId', $activityData)) {
|
if (array_key_exists('personsId', $activityData)) {
|
||||||
foreach($activityData['personsId'] as $personId){
|
foreach($activityData['personsId'] as $personId){
|
||||||
$concernedPerson = $em->getRepository(Person::class)->find($personId);
|
$concernedPerson = $this->personRepository->find($personId);
|
||||||
$entity->addPerson($concernedPerson);
|
$entity->addPerson($concernedPerson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('professionalsId', $activityData)) {
|
if (array_key_exists('professionalsId', $activityData)) {
|
||||||
foreach($activityData['professionalsId'] as $professionalsId){
|
foreach($activityData['professionalsId'] as $professionalsId){
|
||||||
$professional = $em->getRepository(ThirdParty::class)->find($professionalsId);
|
$professional = $this->thirdPartyRepository->find($professionalsId);
|
||||||
$entity->addThirdParty($professional);
|
$entity->addThirdParty($professional);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('location', $activityData)) {
|
if (array_key_exists('location', $activityData)) {
|
||||||
$location = $em->getRepository(Location::class)->find($activityData['location']);
|
$location = $this->locationRepository->find($activityData['location']);
|
||||||
$entity->setLocation($location);
|
$entity->setLocation($location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,8 +268,8 @@ final class ActivityController extends AbstractController
|
|||||||
])->handleRequest($request);
|
])->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em->persist($entity);
|
$this->entityManager->persist($entity);
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans('Success : activity created!'));
|
$this->addFlash('success', $this->get('translator')->trans('Success : activity created!'));
|
||||||
|
|
||||||
@ -277,7 +298,6 @@ final class ActivityController extends AbstractController
|
|||||||
public function showAction(Request $request, $id): Response
|
public function showAction(Request $request, $id): Response
|
||||||
{
|
{
|
||||||
$view = null;
|
$view = null;
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
|
|
||||||
@ -287,8 +307,7 @@ final class ActivityController extends AbstractController
|
|||||||
$view = 'ChillActivityBundle:Activity:showPerson.html.twig';
|
$view = 'ChillActivityBundle:Activity:showPerson.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Activity $entity */
|
$entity = $this->activityRepository->find($id);
|
||||||
$entity = $em->getRepository(Activity::class)->find($id);
|
|
||||||
|
|
||||||
if (null === $entity) {
|
if (null === $entity) {
|
||||||
throw $this->createNotFoundException('Unable to find Activity entity.');
|
throw $this->createNotFoundException('Unable to find Activity entity.');
|
||||||
@ -333,7 +352,6 @@ final class ActivityController extends AbstractController
|
|||||||
public function editAction($id, Request $request): Response
|
public function editAction($id, Request $request): Response
|
||||||
{
|
{
|
||||||
$view = null;
|
$view = null;
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
|
|
||||||
@ -343,8 +361,7 @@ final class ActivityController extends AbstractController
|
|||||||
$view = 'ChillActivityBundle:Activity:editPerson.html.twig';
|
$view = 'ChillActivityBundle:Activity:editPerson.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Activity $entity */
|
$entity = $this->activityRepository->find($id);
|
||||||
$entity = $em->getRepository(Activity::class)->find($id);
|
|
||||||
|
|
||||||
if (null === $entity) {
|
if (null === $entity) {
|
||||||
throw $this->createNotFoundException('Unable to find Activity entity.');
|
throw $this->createNotFoundException('Unable to find Activity entity.');
|
||||||
@ -361,8 +378,8 @@ final class ActivityController extends AbstractController
|
|||||||
])->handleRequest($request);
|
])->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em->persist($entity);
|
$this->entityManager->persist($entity);
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans('Success : activity updated!'));
|
$this->addFlash('success', $this->get('translator')->trans('Success : activity updated!'));
|
||||||
|
|
||||||
@ -406,7 +423,6 @@ final class ActivityController extends AbstractController
|
|||||||
public function deleteAction(Request $request, $id)
|
public function deleteAction(Request $request, $id)
|
||||||
{
|
{
|
||||||
$view = null;
|
$view = null;
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
|
|
||||||
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
[$person, $accompanyingPeriod] = $this->getEntity($request);
|
||||||
|
|
||||||
@ -416,8 +432,7 @@ final class ActivityController extends AbstractController
|
|||||||
$view = 'ChillActivityBundle:Activity:confirm_deletePerson.html.twig';
|
$view = 'ChillActivityBundle:Activity:confirm_deletePerson.html.twig';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @var Activity $activity */
|
$activity = $this->activityRepository->find($id);
|
||||||
$activity = $em->getRepository(Activity::class)->find($id);
|
|
||||||
|
|
||||||
if (!$activity) {
|
if (!$activity) {
|
||||||
throw $this->createNotFoundException('Unable to find Activity entity.');
|
throw $this->createNotFoundException('Unable to find Activity entity.');
|
||||||
@ -449,8 +464,8 @@ final class ActivityController extends AbstractController
|
|||||||
'attendee' => $activity->getAttendee()
|
'attendee' => $activity->getAttendee()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$em->remove($activity);
|
$this->entityManager->remove($activity);
|
||||||
$em->flush();
|
$this->entityManager->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')
|
$this->addFlash('success', $this->get('translator')
|
||||||
->trans("The activity has been successfully removed."));
|
->trans("The activity has been successfully removed."));
|
||||||
@ -490,12 +505,11 @@ final class ActivityController extends AbstractController
|
|||||||
|
|
||||||
private function getEntity(Request $request): array
|
private function getEntity(Request $request): array
|
||||||
{
|
{
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
$person = $accompanyingPeriod = null;
|
$person = $accompanyingPeriod = null;
|
||||||
|
|
||||||
if ($request->query->has('person_id')) {
|
if ($request->query->has('person_id')) {
|
||||||
$person_id = $request->get('person_id');
|
$person_id = $request->get('person_id');
|
||||||
$person = $em->getRepository(Person::class)->find($person_id);
|
$person = $this->personRepository->find($person_id);
|
||||||
|
|
||||||
if ($person === null) {
|
if ($person === null) {
|
||||||
throw $this->createNotFoundException('Person not found');
|
throw $this->createNotFoundException('Person not found');
|
||||||
@ -504,7 +518,7 @@ final class ActivityController extends AbstractController
|
|||||||
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
$this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
|
||||||
} elseif ($request->query->has('accompanying_period_id')) {
|
} elseif ($request->query->has('accompanying_period_id')) {
|
||||||
$accompanying_period_id = $request->get('accompanying_period_id');
|
$accompanying_period_id = $request->get('accompanying_period_id');
|
||||||
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id);
|
$accompanyingPeriod = $this->accompanyingPeriodRepository->find($accompanying_period_id);
|
||||||
|
|
||||||
if ($accompanyingPeriod === null) {
|
if ($accompanyingPeriod === null) {
|
||||||
throw $this->createNotFoundException('Accompanying Period not found');
|
throw $this->createNotFoundException('Accompanying Period not found');
|
||||||
@ -522,7 +536,8 @@ final class ActivityController extends AbstractController
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildParamsToUrl(?Person $person, ?AccompanyingPeriod $accompanyingPeriod): array {
|
private function buildParamsToUrl(?Person $person, ?AccompanyingPeriod $accompanyingPeriod): array
|
||||||
|
{
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if (null !== $person) {
|
if (null !== $person) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user