mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix: SA: Fix "might not be defined" rule.
SA stands for Static Analysis.
This commit is contained in:
@@ -1,24 +1,6 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\Controller;
|
||||
|
||||
@@ -26,9 +8,11 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@@ -42,11 +26,6 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* Class CalendarController
|
||||
*
|
||||
* @package Chill\CalendarBundle\Controller
|
||||
*/
|
||||
class CalendarController extends AbstractController
|
||||
{
|
||||
protected EventDispatcherInterface $eventDispatcher;
|
||||
@@ -127,13 +106,14 @@ class CalendarController extends AbstractController
|
||||
*/
|
||||
public function newAction(Request $request): Response
|
||||
{
|
||||
$view = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
[$user, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = '@ChillCalendar/Calendar/newByAccompanyingCourse.html.twig';
|
||||
}
|
||||
}
|
||||
// elseif ($user instanceof User) {
|
||||
// $view = '@ChillCalendar/Calendar/newUser.html.twig';
|
||||
// }
|
||||
@@ -163,17 +143,18 @@ class CalendarController extends AbstractController
|
||||
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
|
||||
|
||||
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
if ($view === null) {
|
||||
throw $this->createNotFoundException('Template not found');
|
||||
}
|
||||
|
||||
$entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
|
||||
|
||||
|
||||
return $this->render($view, [
|
||||
'user' => $user,
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
@@ -189,44 +170,49 @@ class CalendarController extends AbstractController
|
||||
*/
|
||||
public function showAction(Request $request, $id): Response
|
||||
{
|
||||
$view = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
[$user, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = '@ChillCalendar/Calendar/showByAccompanyingCourse.html.twig';
|
||||
}
|
||||
}
|
||||
elseif ($user instanceof User) {
|
||||
$view = '@ChillCalendar/Calendar/showByUser.html.twig';
|
||||
}
|
||||
|
||||
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
}
|
||||
|
||||
if (null !== $accompanyingPeriod) {
|
||||
$entity->personsAssociated = $entity->getPersonsAssociated();
|
||||
$entity->personsNotAssociated = $entity->getPersonsNotAssociated();
|
||||
}
|
||||
|
||||
// $deleteForm = $this->createDeleteForm($id, $accompanyingPeriod);
|
||||
|
||||
if ($view === null) {
|
||||
throw $this->createNotFoundException('Template not found');
|
||||
}
|
||||
|
||||
$personsId = [];
|
||||
foreach ($entity->getPersons() as $p) {
|
||||
array_push($personsId, $p->getId());
|
||||
/** @var Calendar $entity */
|
||||
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
|
||||
|
||||
if (null === $entity) {
|
||||
throw $this->createNotFoundException('Unable to find Calendar entity.');
|
||||
}
|
||||
|
||||
$professionalsId = [];
|
||||
foreach ($entity->getProfessionals() as $p) {
|
||||
array_push($professionalsId, $p->getId());
|
||||
if (null !== $accompanyingPeriod) {
|
||||
// @TODO: These properties are declared dynamically.
|
||||
// It must be removed.
|
||||
// @See https://wiki.php.net/rfc/deprecate_dynamic_properties
|
||||
$entity->personsAssociated = $entity->getPersonsAssociated();
|
||||
$entity->personsNotAssociated = $entity->getPersonsNotAssociated();
|
||||
}
|
||||
|
||||
// $deleteForm = $this->createDeleteForm($id, $accompanyingPeriod);
|
||||
|
||||
$personsId = array_map(
|
||||
static fn (Person $p): int => $p->getId(),
|
||||
$entity->getPersons()
|
||||
);
|
||||
|
||||
$professionalsId = array_map(
|
||||
static fn (ThirdParty $thirdParty): ?int => $thirdParty->getId(),
|
||||
$entity->getProfessionals()
|
||||
);
|
||||
|
||||
$durationTime = $entity->getEndDate()->diff($entity->getStartDate());
|
||||
$durationTimeInMinutes = $durationTime->days*1440 + $durationTime->h*60 + $durationTime->i;
|
||||
|
||||
@@ -242,7 +228,7 @@ class CalendarController extends AbstractController
|
||||
|
||||
return $this->render($view, [
|
||||
'accompanyingCourse' => $accompanyingPeriod,
|
||||
'entity' => $entity,
|
||||
'entity' => $entity,
|
||||
'user' => $user,
|
||||
'activityData' => $activityData
|
||||
//'delete_form' => $deleteForm->createView(),
|
||||
@@ -257,6 +243,7 @@ class CalendarController extends AbstractController
|
||||
*/
|
||||
public function editAction($id, Request $request): Response
|
||||
{
|
||||
$view = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
[$user, $accompanyingPeriod] = $this->getEntity($request);
|
||||
@@ -285,8 +272,11 @@ class CalendarController extends AbstractController
|
||||
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
|
||||
|
||||
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
|
||||
|
||||
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
|
||||
}
|
||||
|
||||
@@ -297,7 +287,7 @@ class CalendarController extends AbstractController
|
||||
}
|
||||
|
||||
$entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
|
||||
|
||||
|
||||
return $this->render($view, [
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
@@ -314,13 +304,14 @@ class CalendarController extends AbstractController
|
||||
*/
|
||||
public function deleteAction(Request $request, $id)
|
||||
{
|
||||
$view = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
[$user, $accompanyingPeriod] = $this->getEntity($request);
|
||||
|
||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||
$view = '@ChillCalendar/Calendar/confirm_deleteByAccompanyingCourse.html.twig';
|
||||
}
|
||||
}
|
||||
elseif ($user instanceof User) {
|
||||
$view = '@ChillCalendar/Calendar/confirm_deleteByUser.html.twig';
|
||||
}
|
||||
@@ -369,7 +360,7 @@ class CalendarController extends AbstractController
|
||||
/**
|
||||
* Creates a form to delete a Calendar entity by id.
|
||||
*/
|
||||
private function createDeleteForm(int $id, ?User $user, ?AccompanyingPeriod $accompanyingPeriod): Form
|
||||
private function createDeleteForm(int $id, ?User $user, ?AccompanyingPeriod $accompanyingPeriod): FormInterface
|
||||
{
|
||||
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
|
||||
$params['id'] = $id;
|
||||
@@ -416,17 +407,14 @@ class CalendarController extends AbstractController
|
||||
];
|
||||
}
|
||||
|
||||
private function buildParamsToUrl(
|
||||
?User $user,
|
||||
?AccompanyingPeriod $accompanyingPeriod
|
||||
): array {
|
||||
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array {
|
||||
$params = [];
|
||||
|
||||
if ($user) {
|
||||
if (null !== $user) {
|
||||
$params['user_id'] = $user->getId();
|
||||
}
|
||||
|
||||
if ($accompanyingPeriod) {
|
||||
if (null !== $accompanyingPeriod) {
|
||||
$params['accompanying_period_id'] = $accompanyingPeriod->getId();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user