cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;

View File

@@ -1,34 +1,37 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\Request;
class CalendarAPIController extends ApiController
{
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
{
switch($action) {
case '_index':
switch ($request->getMethod()) {
case Request::METHOD_GET:
return [ 'groups' => [ 'calendar:read' ] ];
}
}
return parent::getContextForSerialization($action, $request, $_format, $entity);
}
protected function customizeQuery(string $action, Request $request, $qb): void
{
if ($request->query->has('main_user')) {
$qb->where('e.mainUser = :main_user')
->setParameter('main_user', $request->query->get('main_user'));
->setParameter('main_user', $request->query->get('main_user'));
}
}
protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array
{
switch ($action) {
case '_index':
switch ($request->getMethod()) {
case Request::METHOD_GET:
return ['groups' => ['calendar:read']];
}
}
return parent::getContextForSerialization($action, $request, $_format, $entity);
}
}

View File

@@ -1,43 +1,49 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\Controller;
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;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Role\Role;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Form\CalendarType;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Symfony\Component\Serializer\SerializerInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Exception;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
class CalendarController extends AbstractController
{
protected EventDispatcherInterface $eventDispatcher;
protected AuthorizationHelper $authorizationHelper;
protected EventDispatcherInterface $eventDispatcher;
protected LoggerInterface $logger;
protected SerializerInterface $serializer;
protected PaginatorFactory $paginator;
protected SerializerInterface $serializer;
private CalendarRepository $calendarRepository;
public function __construct(
@@ -56,8 +62,129 @@ class CalendarController extends AbstractController
$this->calendarRepository = $calendarRepository;
}
/**
* Delete a calendar item.
*
* @Route("/{_locale}/calendar/{id}/delete", name="chill_calendar_calendar_delete")
*/
public function deleteAction(Request $request, int $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';
}
/* @var $entity Calendar */
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.');
}
$form = $this->createDeleteForm($id, $user, $accompanyingPeriod);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->logger->notice('A calendar event has been removed', [
'by_user' => $this->getUser()->getUsername(),
'calendar_id' => $entity->getId(),
]);
$em->remove($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans('The calendar item has been successfully removed.'));
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
}
if (null === $view) {
throw $this->createNotFoundException('Template not found');
}
return $this->render($view, [
'calendar' => $entity,
'delete_form' => $form->createView(),
'accompanyingCourse' => $accompanyingPeriod,
]);
}
/**
* Edit a calendar item.
*
* @Route("/{_locale}/calendar/calendar/{id}/edit", name="chill_calendar_calendar_edit")
*/
public function editAction(int $id, Request $request): Response
{
$view = null;
$em = $this->getDoctrine()->getManager();
[$user, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = '@ChillCalendar/Calendar/editByAccompanyingCourse.html.twig';
} elseif ($user instanceof User) {
$view = '@ChillCalendar/Calendar/editByUser.html.twig';
}
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.');
}
$form = $this->createForm(CalendarType::class, $entity, [
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->persist($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
}
$deleteForm = $this->createDeleteForm($id, $user, $accompanyingPeriod);
if (null === $view) {
throw $this->createNotFoundException('Template not found');
}
$entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, [
'entity' => $entity,
'form' => $form->createView(),
'delete_form' => $deleteForm->createView(),
'accompanyingCourse' => $accompanyingPeriod,
'user' => $user,
'entity_json' => $entity_array,
]);
}
/**
* Lists all Calendar entities.
*
* @Route("/{_locale}/calendar/calendar/", name="chill_calendar_calendar_list")
*/
public function listAction(Request $request): Response
@@ -67,14 +194,13 @@ class CalendarController extends AbstractController
[$user, $accompanyingPeriod] = $this->getEntity($request);
if ($user instanceof User) {
$calendarItems = $this->calendarRepository->findByUser($user);
$view = '@ChillCalendar/Calendar/listByUser.html.twig';
return $this->render($view, [
'calendarItems' => $calendarItems,
'user' => $user
'user' => $user,
]);
}
@@ -93,15 +219,16 @@ class CalendarController extends AbstractController
return $this->render($view, [
'calendarItems' => $calendarItems,
'accompanyingCourse' => $accompanyingPeriod,
'paginator' => $paginator
'paginator' => $paginator,
]);
}
throw new \Exception('Unable to list actions.');
throw new Exception('Unable to list actions.');
}
/**
* Create a new calendar item
* Create a new calendar item.
*
* @Route("/{_locale}/calendar/calendar/new", name="chill_calendar_calendar_new")
*/
public function newAction(Request $request): Response
@@ -149,7 +276,7 @@ class CalendarController extends AbstractController
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
}
if ($view === null) {
if (null === $view) {
throw $this->createNotFoundException('Template not found');
}
@@ -160,12 +287,13 @@ class CalendarController extends AbstractController
'accompanyingCourse' => $accompanyingPeriod,
'entity' => $entity,
'form' => $form->createView(),
'entity_json' => $entity_array
'entity_json' => $entity_array,
]);
}
/**
* Show a calendar item
* Show a calendar item.
*
* @Route("/{_locale}/calendar/calendar/{id}/show", name="chill_calendar_calendar_show")
*/
public function showAction(Request $request, int $id): Response
@@ -177,12 +305,11 @@ class CalendarController extends AbstractController
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = '@ChillCalendar/Calendar/showByAccompanyingCourse.html.twig';
}
elseif ($user instanceof User) {
} elseif ($user instanceof User) {
$view = '@ChillCalendar/Calendar/showByUser.html.twig';
}
if ($view === null) {
if (null === $view) {
throw $this->createNotFoundException('Template not found');
}
@@ -214,7 +341,7 @@ class CalendarController extends AbstractController
);
$durationTime = $entity->getEndDate()->diff($entity->getStartDate());
$durationTimeInMinutes = $durationTime->days*1440 + $durationTime->h*60 + $durationTime->i;
$durationTimeInMinutes = $durationTime->days * 1440 + $durationTime->h * 60 + $durationTime->i;
$activityData = [
'calendarId' => $id,
@@ -230,131 +357,24 @@ class CalendarController extends AbstractController
'accompanyingCourse' => $accompanyingPeriod,
'entity' => $entity,
'user' => $user,
'activityData' => $activityData
'activityData' => $activityData,
//'delete_form' => $deleteForm->createView(),
]);
}
/**
* Edit a calendar item
* @Route("/{_locale}/calendar/calendar/{id}/edit", name="chill_calendar_calendar_edit")
*/
public function editAction(int $id, Request $request): Response
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array
{
$view = null;
$em = $this->getDoctrine()->getManager();
$params = [];
[$user, $accompanyingPeriod] = $this->getEntity($request);
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
$view = '@ChillCalendar/Calendar/editByAccompanyingCourse.html.twig';
}
elseif ($user instanceof User) {
$view = '@ChillCalendar/Calendar/editByUser.html.twig';
if (null !== $user) {
$params['user_id'] = $user->getId();
}
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.');
if (null !== $accompanyingPeriod) {
$params['accompanying_period_id'] = $accompanyingPeriod->getId();
}
$form = $this->createForm(CalendarType::class, $entity, [
'accompanyingPeriod' => $accompanyingPeriod,
])->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->persist($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!'));
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
if ($form->isSubmitted() and !$form->isValid()) {
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
}
$deleteForm = $this->createDeleteForm($id, $user, $accompanyingPeriod);
if ($view === null) {
throw $this->createNotFoundException('Template not found');
}
$entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']);
return $this->render($view, [
'entity' => $entity,
'form' => $form->createView(),
'delete_form' => $deleteForm->createView(),
'accompanyingCourse' => $accompanyingPeriod,
'user' => $user,
'entity_json' => $entity_array
]);
}
/**
* Delete a calendar item
* @Route("/{_locale}/calendar/{id}/delete", name="chill_calendar_calendar_delete")
*/
public function deleteAction(Request $request, int $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';
}
/* @var $entity Calendar */
$entity = $em->getRepository('ChillCalendarBundle:Calendar')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Calendar entity.');
}
$form = $this->createDeleteForm($id, $user, $accompanyingPeriod);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->logger->notice("A calendar event has been removed", [
'by_user' => $this->getUser()->getUsername(),
'calendar_id' => $entity->getId()
]);
$em->remove($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The calendar item has been successfully removed."));
$params = $this->buildParamsToUrl($user, $accompanyingPeriod);
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
}
if ($view === null) {
throw $this->createNotFoundException('Template not found');
}
return $this->render($view, [
'calendar' => $entity,
'delete_form' => $form->createView(),
'accompanyingCourse' => $accompanyingPeriod,
]);
return $params;
}
/**
@@ -369,8 +389,7 @@ class CalendarController extends AbstractController
->setAction($this->generateUrl('chill_calendar_calendar_delete', $params))
->setMethod('DELETE')
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm()
;
->getForm();
}
private function getEntity(Request $request): array
@@ -382,7 +401,7 @@ class CalendarController extends AbstractController
$user_id = $request->get('user_id');
$user = $em->getRepository(User::class)->find($user_id);
if ($user === null) {
if (null === $user) {
throw $this->createNotFoundException('User not found');
}
@@ -392,32 +411,18 @@ class CalendarController extends AbstractController
$accompanying_period_id = $request->get('accompanying_period_id');
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id);
if ($accompanyingPeriod === null) {
if (null === $accompanyingPeriod) {
throw $this->createNotFoundException('Accompanying Period not found');
}
// TODO Add permission
// $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person);
} else {
throw $this->createNotFoundException("Person or Accompanying Period not found");
throw $this->createNotFoundException('Person or Accompanying Period not found');
}
return [
$user, $accompanyingPeriod
$user, $accompanyingPeriod,
];
}
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array {
$params = [];
if (null !== $user) {
$params['user_id'] = $user->getId();
}
if (null !== $accompanyingPeriod) {
$params['accompanying_period_id'] = $accompanyingPeriod->getId();
}
return $params;
}
}

View File

@@ -1,18 +1,22 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Chill\MainBundle\Serializer\Model\Collection;
use Symfony\Component\Routing\Annotation\Route;
class CalendarRangeAPIController extends ApiController
{
/**
* @Route("/api/1.0/calendar/calendar-range-available.{_format}", name="chill_api_single_calendar_range_available")
*/
@@ -34,8 +38,7 @@ class CalendarRangeAPIController extends ApiController
$results = $query->getResult();
return $this->json(['count' => count($results), 'results' => $results], Response::HTTP_OK, [], [ 'groups' => [ 'read' ]]);
return $this->json(['count' => count($results), 'results' => $results], Response::HTTP_OK, [], ['groups' => ['read']]);
//TODO use also the paginator, eg return $this->serializeCollection('get', $request, $_format, $paginator, $results);
}
}
}

View File

@@ -1,12 +1,17 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Entity\CalendarRange;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\UserRepository;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
@@ -14,34 +19,33 @@ use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
class LoadCalendarRange extends Fixture implements FixtureGroupInterface, OrderedFixtureInterface
{
private UserRepository $userRepository;
public static array $references = [];
private UserRepository $userRepository;
public function __construct(
UserRepository $userRepository
) {
$this->userRepository = $userRepository;
}
public function getOrder(): int
{
return 40003;
}
public static function getGroups(): array
{
return ['calendar'];
}
public function getOrder(): int
{
return 40003;
}
public function load(ObjectManager $manager): void
{
$arr = range(-50, 50);
print "Creating calendar range ('plage de disponibilités')\n";
echo "Creating calendar range ('plage de disponibilités')\n";
$users = $this->userRepository->findAll();
@@ -60,25 +64,23 @@ class LoadCalendarRange extends Fixture implements FixtureGroupInterface, Ordere
'10:00:00',
'11:30:00',
'13:30:00',
'15:00:00'
'15:00:00',
];
foreach ($users as $u) {
foreach ($days as $d) {
foreach ($hours as $h){
$event = $d.' '.$h;
foreach ($hours as $h) {
$event = $d . ' ' . $h;
$startEvent = new DateTimeImmutable($event);
$endEvent = new DateTimeImmutable($event.' + 1 hours');
$calendarRange= (new CalendarRange())
$endEvent = new DateTimeImmutable($event . ' + 1 hours');
$calendarRange = (new CalendarRange())
->setUser($u)
->setStartDate($startEvent)
->setEndDate($endEvent);
$manager->persist($calendarRange);
}
}
}
$manager->flush();
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Entity\CancelReason;
@@ -7,20 +14,19 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Persistence\ObjectManager;
class LoadCancelReason extends Fixture implements FixtureGroupInterface
{
public function getOrder(): int
{
return 40001;
}
public static $references = [];
public static function getGroups(): array
{
return ['calendar'];
}
public static $references = [];
public function getOrder(): int
{
return 40001;
}
public function load(ObjectManager $manager): void
{
@@ -31,12 +37,12 @@ class LoadCancelReason extends Fixture implements FixtureGroupInterface
];
foreach ($arr as $a) {
print "Creating calendar cancel reason : " . $a['name'] . "\n";
$cancelReason= (new CancelReason())
echo 'Creating calendar cancel reason : ' . $a['name'] . "\n";
$cancelReason = (new CancelReason())
->setCanceledBy($a['name'])
->setActive(true);
$manager->persist($cancelReason);
$reference = 'CancelReason_'.$a['name'];
$reference = 'CancelReason_' . $a['name'];
$this->addReference($reference, $cancelReason);
static::$references[] = $reference;
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Entity\Invite;
@@ -7,20 +14,19 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Persistence\ObjectManager;
class LoadInvite extends Fixture implements FixtureGroupInterface
{
public function getOrder(): int
{
return 40002;
}
public static $references = [];
public static function getGroups(): array
{
return ['calendar'];
}
public static $references = [];
public function getOrder(): int
{
return 40002;
}
public function load(ObjectManager $manager): void
{
@@ -30,11 +36,11 @@ class LoadInvite extends Fixture implements FixtureGroupInterface
];
foreach ($arr as $a) {
print "Creating calendar invite : " . $a['name']['fr'] . "\n";
$invite= (new Invite())
echo 'Creating calendar invite : ' . $a['name']['fr'] . "\n";
$invite = (new Invite())
->setStatus($a['name']);
$manager->persist($invite);
$reference = 'Invite_'.$a['name']['fr'];
$reference = 'Invite_' . $a['name']['fr'];
$this->addReference($reference, $invite);
static::$references[] = $reference;
}

View File

@@ -1,30 +1,34 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
* @see http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class ChillCalendarExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('services/controller.yml');
$loader->load('services/fixtures.yml');
@@ -37,22 +41,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
$this->preprendRoutes($container);
$this->prependCruds($container);
}
protected function preprendRoutes(ContainerBuilder $container)
{
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
'@ChillCalendarBundle/Resources/config/routing.yml'
]
]
]);
}
/**
* @param ContainerBuilder $container
*/
protected function prependCruds(ContainerBuilder $container)
{
$container->prependExtensionConfig('chill_main', [
@@ -77,9 +66,9 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
Request::METHOD_POST => true,
Request::METHOD_PATCH => true,
Request::METHOD_DELETE => true,
]
],
],
]
],
],
[
'controller' => \Chill\CalendarBundle\Controller\CalendarAPIController::class,
@@ -91,20 +80,29 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true
Request::METHOD_HEAD => true,
],
],
'_entity' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true
]
Request::METHOD_HEAD => true,
],
],
]
]
]
],
],
],
]);
}
protected function preprendRoutes(ContainerBuilder $container)
{
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
'@ChillCalendarBundle/Resources/config/routing.yml',
],
],
]);
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -12,9 +19,6 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('chill_calendar');

View File

@@ -1,28 +1,31 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Entity;
use Chill\ActivityBundle\Entity\Activity;
use Chill\CalendarBundle\Repository\CalendarRepository;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\Location;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\CalendarBundle\Entity\CancelReason;
use Chill\CalendarBundle\Entity\CalendarRange;
use Chill\CalendarBundle\Entity\Invite;
use Chill\ActivityBundle\Entity\Activity;
use Chill\CalendarBundle\Repository\CalendarRepository;
use DateInterval;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_calendar.calendar")
@@ -30,24 +33,11 @@ use Symfony\Component\Serializer\Annotation as Serializer;
*/
class Calendar
{
const STATUS_VALID = 'valid';
const STATUS_CANCELED = 'canceled';
const STATUS_MOVED = 'moved';
public const STATUS_CANCELED = 'canceled';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"calendar:read"})
*/
private ?int $id;
public const STATUS_MOVED = 'moved';
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
*/
private ?User $user = null;
public const STATUS_VALID = 'valid';
/**
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod")
@@ -56,42 +46,19 @@ class Calendar
private AccompanyingPeriod $accompanyingPeriod;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Serializer\Groups({"calendar:read"})
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\Activity")
*/
private ?User $mainUser;
private ?Activity $activity = null;
/**
*
* @ORM\ManyToMany(
* targetEntity="Chill\PersonBundle\Entity\Person",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_persons")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
* @ORM\ManyToOne(targetEntity="CalendarRange", inversedBy="calendars")
*/
private Collection $persons;
private ?CalendarRange $calendarRange = null;
/**
*
* @ORM\ManyToMany(
* targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_thirdparties")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
* @ORM\ManyToOne(targetEntity="CancelReason")
*/
private Collection $professionals;
/**
*
* @ORM\ManyToMany(
* targetEntity="Invite",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_invites")
* @Groups({"read"})
*/
private Collection $invites;
private ?CancelReason $cancelReason = null;
/**
* @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_")
@@ -103,38 +70,24 @@ class Calendar
* @ORM\Column(type="datetimetz_immutable")
* @Serializer\Groups({"calendar:read"})
*/
private ?\DateTimeImmutable $startDate = null;
private ?DateTimeImmutable $endDate = null;
/**
* @ORM\Column(type="datetimetz_immutable")
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"calendar:read"})
*/
private ?\DateTimeImmutable $endDate = null;
private ?int $id;
/**
* @ORM\Column(type="string", length=255)
* @ORM\ManyToMany(
* targetEntity="Invite",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_invites")
* @Groups({"read"})
*/
private ?string $status = null;
/**
* @ORM\ManyToOne(targetEntity="CancelReason")
*/
private ?CancelReason $cancelReason = null;
/**
* @ORM\ManyToOne(targetEntity="CalendarRange", inversedBy="calendars")
*/
private ?CalendarRange $calendarRange = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\Activity")
*/
private ?Activity $activity = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $sendSMS;
private Collection $invites;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
@@ -142,6 +95,54 @@ class Calendar
*/
private ?Location $location = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Serializer\Groups({"calendar:read"})
*/
private ?User $mainUser;
/**
* @ORM\ManyToMany(
* targetEntity="Chill\PersonBundle\Entity\Person",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_persons")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
*/
private Collection $persons;
/**
* @ORM\ManyToMany(
* targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_thirdparties")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
*/
private Collection $professionals;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $sendSMS;
/**
* @ORM\Column(type="datetimetz_immutable")
* @Serializer\Groups({"calendar:read"})
*/
private ?DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="string", length=255)
*/
private ?string $status = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @Groups({"read"})
* @Serializer\Groups({"calendar:read"})
*/
private ?User $user = null;
public function __construct()
{
@@ -151,164 +152,6 @@ class Calendar
$this->invites = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSendSMS(): ?bool
{
return $this->sendSMS;
}
public function setSendSMS(?bool $sendSMS): self
{
$this->sendSMS = $sendSMS;
return $this;
}
public function getComment(): CommentEmbeddable
{
return $this->comment;
}
public function setComment(CommentEmbeddable $comment): self
{
$this->comment = $comment;
return $this;
}
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
public function setStartDate(\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
public function setEndDate(\DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getAccompanyingPeriod(): ?AccompanyingPeriod
{
return $this->accompanyingPeriod;
}
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
{
$this->accompanyingPeriod = $accompanyingPeriod;
return $this;
}
public function getMainUser(): ?User
{
return $this->mainUser;
}
public function setMainUser(?User $mainUser): self
{
$this->mainUser = $mainUser;
return $this;
}
/**
* @return Collection|Person[]
*/
public function getPersons(): Collection
{
return $this->persons;
}
public function addPerson(?Person $person): self
{
if (null !== $person) {
$this->persons[] = $person;
}
return $this;
}
public function removePerson(Person $person): self
{
$this->persons->removeElement($person);
return $this;
}
/**
* @return Collection|ThirdParty[]
*/
public function getProfessionals(): Collection
{
return $this->professionals;
}
public function addProfessional(?ThirdParty $professional): self
{
if (null !== $professional) {
$this->professionals[] = $professional;
}
return $this;
}
public function removeProfessional(ThirdParty $professional): self
{
$this->professionals->removeElement($professional);
return $this;
}
/**
* @return Collection|Invite[]
*/
public function getInvites(): Collection
{
return $this->invites;
}
public function addInvite(?Invite $invite): self
{
if (null !== $invite) {
@@ -318,35 +161,27 @@ class Calendar
return $this;
}
public function removeInvite(Invite $invite): self
public function addPerson(?Person $person): self
{
$this->invites->removeElement($invite);
if (null !== $person) {
$this->persons[] = $person;
}
return $this;
}
public function getCancelReason(): ?CancelReason
public function addProfessional(?ThirdParty $professional): self
{
return $this->cancelReason;
}
public function setCancelReason(?CancelReason $cancelReason): self
{
$this->cancelReason = $cancelReason;
if (null !== $professional) {
$this->professionals[] = $professional;
}
return $this;
}
public function getCalendarRange(): ?CalendarRange
public function getAccompanyingPeriod(): ?AccompanyingPeriod
{
return $this->calendarRange;
}
public function setCalendarRange(?CalendarRange $calendarRange): self
{
$this->calendarRange = $calendarRange;
return $this;
return $this->accompanyingPeriod;
}
public function getActivity(): ?Activity
@@ -354,24 +189,71 @@ class Calendar
return $this->activity;
}
public function setActivity(?Activity $activity): self
public function getCalendarRange(): ?CalendarRange
{
$this->activity = $activity;
return $this->calendarRange;
}
return $this;
public function getCancelReason(): ?CancelReason
{
return $this->cancelReason;
}
public function getComment(): CommentEmbeddable
{
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Invite[]
*/
public function getInvites(): Collection
{
return $this->invites;
}
public function getLocation(): ?Location
{
return $this->location;
}
public function getMainUser(): ?User
{
return $this->mainUser;
}
/**
* @return Collection|Person[]
*/
public function getPersons(): Collection
{
return $this->persons;
}
public function getPersonsAssociated(): array
{
if (null !== $this->accompanyingPeriod) {
$personsAssociated = [];
foreach ($this->accompanyingPeriod->getParticipations() as $participation) {
if ($this->persons->contains($participation->getPerson())) {
$personsAssociated[] = $participation->getPerson();
}
}
return $personsAssociated;
}
return [];
}
@@ -379,22 +261,52 @@ class Calendar
{
if (null !== $this->accompanyingPeriod) {
$personsNotAssociated = [];
foreach ($this->persons as $person) {
if (!in_array($person, $this->getPersonsAssociated())) {
$personsNotAssociated[] = $person;
$personsNotAssociated[] = $person;
}
}
return $personsNotAssociated;
}
return [];
}
/**
* @return Collection|ThirdParty[]
*/
public function getProfessionals(): Collection
{
return $this->professionals;
}
public function getSendSMS(): ?bool
{
return $this->sendSMS;
}
public function getStartDate(): ?DateTimeImmutable
{
return $this->startDate;
}
public function getStatus(): ?string
{
return $this->status;
}
public function getThirdParties(): Collection
{
return $this->getProfessionals();
}
public function getUser(): ?User
{
return $this->user;
}
public function getusers(): Collection
{
return $this->getInvites(); //TODO get users of the invite
@@ -414,22 +326,108 @@ class Calendar
]));
}
/**
* @return Location|null
*/
public function getLocation(): ?Location
public function removeInvite(Invite $invite): self
{
return $this->location;
}
$this->invites->removeElement($invite);
/**
* @param Location|null $location
* @return Calendar
*/
public function setLocation(?Location $location): Calendar
{
$this->location = $location;
return $this;
}
public function removePerson(Person $person): self
{
$this->persons->removeElement($person);
return $this;
}
public function removeProfessional(ThirdParty $professional): self
{
$this->professionals->removeElement($professional);
return $this;
}
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
{
$this->accompanyingPeriod = $accompanyingPeriod;
return $this;
}
public function setActivity(?Activity $activity): self
{
$this->activity = $activity;
return $this;
}
public function setCalendarRange(?CalendarRange $calendarRange): self
{
$this->calendarRange = $calendarRange;
return $this;
}
public function setCancelReason(?CancelReason $cancelReason): self
{
$this->cancelReason = $cancelReason;
return $this;
}
public function setComment(CommentEmbeddable $comment): self
{
$this->comment = $comment;
return $this;
}
public function setEndDate(DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function setLocation(?Location $location): Calendar
{
$this->location = $location;
return $this;
}
public function setMainUser(?User $mainUser): self
{
$this->mainUser = $mainUser;
return $this;
}
public function setSendSMS(?bool $sendSMS): self
{
$this->sendSMS = $sendSMS;
return $this;
}
public function setStartDate(DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}

View File

@@ -1,9 +1,17 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Entity;
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -15,6 +23,18 @@ use Symfony\Component\Serializer\Annotation\Groups;
*/
class CalendarRange
{
/**
* @ORM\OneToMany(targetEntity=Calendar::class,
* mappedBy="calendarRange")
*/
private Collection $calendars;
/**
* @ORM\Column(type="datetimetz_immutable")
* @groups({"read", "write"})
*/
private ?DateTimeImmutable $endDate = null;
/**
* @ORM\Id
* @ORM\GeneratedValue
@@ -23,30 +43,18 @@ class CalendarRange
*/
private $id;
/**
* @ORM\Column(type="datetimetz_immutable")
* @groups({"read", "write"})
*/
private ?DateTimeImmutable $startDate = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @groups({"read", "write"})
*/
private ?User $user = null;
/**
* @ORM\Column(type="datetimetz_immutable")
* @groups({"read", "write"})
*/
private ?\DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="datetimetz_immutable")
* @groups({"read", "write"})
*/
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\OneToMany(targetEntity=Calendar::class,
* mappedBy="calendarRange")
*/
private Collection $calendars;
//TODO Lieu
public function __construct()
@@ -54,38 +62,38 @@ class CalendarRange
$this->calendars = new ArrayCollection();
}
public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
public function getId(): ?int
{
return $this->id;
}
public function getStartDate(): ?\DateTimeImmutable
public function getStartDate(): ?DateTimeImmutable
{
return $this->startDate;
}
public function setStartDate(\DateTimeImmutable $startDate): self
public function getUser(): ?User
{
$this->startDate = $startDate;
return $this;
return $this->user;
}
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
public function setEndDate(\DateTimeImmutable $endDate): self
public function setEndDate(DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function getUser(): ?User
public function setStartDate(DateTimeImmutable $startDate): self
{
return $this->user;
$this->startDate = $startDate;
return $this;
}
public function setUser(?User $user): self
@@ -94,6 +102,4 @@ class CalendarRange
return $this;
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Entity;
use Chill\CalendarBundle\Repository\CancelReasonRepository;
@@ -11,17 +18,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class CancelReason
{
public const CANCELEDBY_DONOTCOUNT = 'CANCELEDBY_DONOTCOUNT';
const CANCELEDBY_USER = 'CANCELEDBY_USER';
const CANCELEDBY_PERSON = 'CANCELEDBY_PERSON';
const CANCELEDBY_DONOTCOUNT = 'CANCELEDBY_DONOTCOUNT';
public const CANCELEDBY_PERSON = 'CANCELEDBY_PERSON';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
public const CANCELEDBY_USER = 'CANCELEDBY_USER';
/**
* @ORM\Column(type="boolean")
@@ -33,19 +34,36 @@ class CancelReason
*/
private $canceledBy;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="json")
*/
private $name = [];
public function getActive(): ?bool
{
return $this->active;
}
public function getCanceledBy(): ?string
{
return $this->canceledBy;
}
public function getId(): ?int
{
return $this->id;
}
public function getActive(): ?bool
public function getName(): ?array
{
return $this->active;
return $this->name;
}
public function setActive(bool $active): self
@@ -55,11 +73,6 @@ class CancelReason
return $this;
}
public function getCanceledBy(): ?string
{
return $this->canceledBy;
}
public function setCanceledBy(string $canceledBy): self
{
$this->canceledBy = $canceledBy;
@@ -67,11 +80,6 @@ class CancelReason
return $this;
}
public function getName(): ?array
{
return $this->name;
}
public function setName(array $name): self
{
$this->name = $name;

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Entity;
use Chill\CalendarBundle\Repository\InviteRepository;
@@ -19,16 +26,16 @@ class Invite
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
*/
private User $user;
/**
* @ORM\Column(type="json")
*/
private array $status = [];
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
*/
private User $user;
public function getId(): ?int
{
return $this->id;
@@ -39,6 +46,11 @@ class Invite
return $this->status;
}
public function getUser(): ?User
{
return $this->user;
}
public function setStatus(array $status): self
{
$this->status = $status;
@@ -46,11 +58,6 @@ class Invite
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Event;
use Chill\ActivityBundle\Entity\Activity;
@@ -8,7 +15,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
class ListenToActivityCreate
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
@@ -24,9 +30,10 @@ class ListenToActivityCreate
if (null === $request) {
return;
}
if ($request->query->has('activityData')) {
$activityData = $request->query->get('activityData');
if (array_key_exists('calendarId', $activityData)) {
$calendarId = $activityData['calendarId'];
@@ -40,8 +47,5 @@ class ListenToActivityCreate
$em->flush();
}
}
}
}

View File

@@ -1,53 +1,54 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Form;
use Chill\MainBundle\Entity\Location;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\CalendarBundle\Entity\CalendarRange;
use Chill\CalendarBundle\Entity\CancelReason;
use Chill\CalendarBundle\Entity\Invite;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CalendarType extends AbstractType
{
protected ObjectManager $om;
protected TranslatableStringHelper $translatableStringHelper;
protected ObjectManager $om;
public function __construct(
TranslatableStringHelper $translatableStringHelper,
ObjectManager $om
)
{
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->om = $om;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('comment', CommentType::class, [
'required' => false
'required' => false,
])
// ->add('cancelReason', EntityType::class, [
// 'required' => false,
@@ -60,124 +61,126 @@ class CalendarType extends AbstractType
'required' => false,
'choices' => [
'Oui' => true,
'Non' => false
'Non' => false,
],
'expanded' => true
])
;
'expanded' => true,
]);
$builder->add('mainUser', HiddenType::class);
$builder->get('mainUser')
->addModelTransformer(new CallbackTransformer(
function (?User $user): int {
if (NULL !== $user) {
if (null !== $user) {
$res = $user->getId();
} else {
$res = -1; //TODO cannot be null in any ways...
}
return $res;
},
function (?int $userId): User {
return $this->om->getRepository(user::class)->findOneBy(['id' => (int) $userId]);
}
))
;
));
$builder->add('startDate', HiddenType::class);
$builder->get('startDate')
->addModelTransformer(new CallbackTransformer(
function (?DateTimeImmutable $dateTimeImmutable): string {
if (NULL !== $dateTimeImmutable) {
if (null !== $dateTimeImmutable) {
$res = date_format($dateTimeImmutable, 'Y-m-d H:i:s');
} else {
$res = '';
}
return $res;
},
function (?string $dateAsString): DateTimeImmutable {
dump($dateAsString);
return new DateTimeImmutable($dateAsString);
}
))
;
));
$builder->add('endDate', HiddenType::class);
$builder->get('endDate')
->addModelTransformer(new CallbackTransformer(
function (?DateTimeImmutable $dateTimeImmutable): string {
if (NULL !== $dateTimeImmutable) {
if (null !== $dateTimeImmutable) {
$res = date_format($dateTimeImmutable, 'Y-m-d H:i:s');
} else {
$res = '';
}
return $res;
},
function (?string $dateAsString): DateTimeImmutable {
return new DateTimeImmutable($dateAsString);
}
))
;
));
$builder->add('persons', HiddenType::class);
$builder->get('persons')
->addModelTransformer(new CallbackTransformer(
function (iterable $personsAsIterable): string {
$personIds = [];
foreach ($personsAsIterable as $value) {
$personIds[] = $value->getId();
}
return implode(',', $personIds);
},
function (?string $personsAsString): array {
return array_map(
fn(string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]),
fn (string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]),
explode(',', $personsAsString)
);
}
))
;
));
$builder->add('professionals', HiddenType::class);
$builder->get('professionals')
->addModelTransformer(new CallbackTransformer(
function (iterable $thirdpartyAsIterable): string {
$thirdpartyIds = [];
foreach ($thirdpartyAsIterable as $value) {
$thirdpartyIds[] = $value->getId();
}
return implode(',', $thirdpartyIds);
},
function (?string $thirdpartyAsString): array {
return array_map(
fn(string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]),
fn (string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]),
explode(',', $thirdpartyAsString)
);
}
))
;
));
$builder->add('calendarRange', HiddenType::class);
$builder->get('calendarRange')
->addModelTransformer(new CallbackTransformer(
function (?CalendarRange $calendarRange): ?int {
if (NULL !== $calendarRange) {
if (null !== $calendarRange) {
$res = $calendarRange->getId();
} else {
$res = -1;
}
return $res;
},
function (?string $calendarRangeId): ?CalendarRange {
if (NULL !== $calendarRangeId) {
if (null !== $calendarRangeId) {
$res = $this->om->getRepository(CalendarRange::class)->findOneBy(['id' => (int) $calendarRangeId]);
} else {
$res = NULL;
$res = null;
}
return $res;
}
))
;
));
$builder->add('location', HiddenType::class)
->get('location')
@@ -186,58 +189,48 @@ class CalendarType extends AbstractType
if (null === $location) {
return '';
}
return $location->getId();
},
function (?string $id): ?Location {
return $this->om->getRepository(Location::class)->findOneBy(['id' => (int) $id]);
}
))
;
));
$builder->add('invites', HiddenType::class);
$builder->get('invites')
->addModelTransformer(new CallbackTransformer(
function (iterable $usersAsIterable): string {
->addModelTransformer(new CallbackTransformer(
function (iterable $usersAsIterable): string {
$userIds = [];
foreach ($usersAsIterable as $value) {
$userIds[] = $value->getId();
}
return implode(',', $userIds);
},
function (?string $usersAsString): array {
function (?string $usersAsString): array {
return array_map(
fn(string $id): ?Invite => $this->om->getRepository(Invite::class)->findOneBy(['id' => (int) $id]),
fn (string $id): ?Invite => $this->om->getRepository(Invite::class)->findOneBy(['id' => (int) $id]),
explode(',', $usersAsString)
);
}
))
;
));
}
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Calendar::class
'data_class' => Calendar::class,
]);
$resolver
->setRequired(['accompanyingPeriod'])
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null'])
;
->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'chill_calendarbundle_calendar';
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
@@ -11,10 +18,10 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
{
protected TokenStorageInterface $tokenStorage;
protected AuthorizationHelper $authorizationHelper;
protected TokenStorageInterface $tokenStorage;
protected TranslatorInterface $translator;
public function __construct(
@@ -26,10 +33,6 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
$this->authorizationHelper = $authorizationHelper;
$this->tokenStorage = $tokenStorage;
}
public static function getMenuIds(): array
{
return ['accompanyingCourse'];
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
@@ -40,8 +43,13 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
'route' => 'chill_calendar_calendar_list',
'routeParameters' => [
'accompanying_period_id' => $period->getId(),
]])
], ])
->setExtras(['order' => 35]);
}
}
public static function getMenuIds(): array
{
return ['accompanyingCourse'];
}
}

View File

@@ -1,40 +1,29 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <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/>.
*/
namespace Chill\CalendarBundle\Menu;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* Chill is a software for social workers
*
* @author Champs-Libres
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Translation\TranslatorInterface;
class UserMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
/**
*
* @var CountNotificationTask
*/
public $counter;
@@ -45,17 +34,10 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
public $tokenStorage;
/**
*
* @var TranslatorInterface
*/
public $translator;
/**
*
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
public function __construct(
CountNotificationTask $counter,
TokenStorageInterface $tokenStorage,
@@ -68,25 +50,23 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
$this->authorizationChecker = $authorizationChecker;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
$user = $this->tokenStorage->getToken()->getUser();
if ($this->authorizationChecker->isGranted('ROLE_USER')){
$menu->addChild("My calendar list", [
'route' => 'chill_calendar_calendar_list'
if ($this->authorizationChecker->isGranted('ROLE_USER')) {
$menu->addChild('My calendar list', [
'route' => 'chill_calendar_calendar_list',
])
->setExtras([
'order' => 9,
'icon' => 'tasks'
]);
->setExtras([
'order' => 9,
'icon' => 'tasks',
]);
}
}
public static function getMenuIds(): array
{
return [ 'user' ];
return ['user'];
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\CalendarBundle\Entity\CalendarRange;
@@ -34,7 +41,7 @@ class CalendarRangeRepository extends ServiceEntityRepository
->getResult()
;
}
*/
*/
/*
public function findOneBySomeField($value): ?CalendarRange
@@ -46,5 +53,5 @@ class CalendarRangeRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
*/
*/
}

View File

@@ -1,9 +1,15 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -16,13 +22,12 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class CalendarRepository extends ServiceEntityRepository
{
// private EntityRepository $repository;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Calendar::class);
// $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class);
// $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class);
}
// /**
@@ -40,7 +45,7 @@ class CalendarRepository extends ServiceEntityRepository
->getResult()
;
}
*/
*/
/*
public function findOneBySomeField($value): ?Calendar
@@ -52,5 +57,5 @@ class CalendarRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
*/
*/
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\CalendarBundle\Entity\CancelReason;
@@ -34,7 +41,7 @@ class CancelReasonRepository extends ServiceEntityRepository
->getResult()
;
}
*/
*/
/*
public function findOneBySomeField($value): ?CancelReason
@@ -46,5 +53,5 @@ class CancelReasonRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
*/
*/
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Repository;
use Chill\CalendarBundle\Entity\Invite;
@@ -34,7 +41,7 @@ class InviteRepository extends ServiceEntityRepository
->getResult()
;
}
*/
*/
/*
public function findOneBySomeField($value): ?Invite
@@ -46,5 +53,5 @@ class InviteRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
*/
*/
}

View File

@@ -1,47 +1,56 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CalendarBundle\Tests\Controller;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use function random_int;
/**
* @internal
* @coversNothing
*/
class CalendarControllerTest extends WebTestCase
{
/**
* Setup before each test method (see phpunit doc)
* Setup before each test method (see phpunit doc).
*/
public function setUp()
{
static::bootKernel();
$this->client = static::createClient(array(), array(
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
));
$this->client = static::createClient([], [
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
]);
}
public function provideAccompanyingPeriod(): iterable
{
static::bootKernel();
$em= static::$container->get(EntityManagerInterface::class);
$em = static::$container->get(EntityManagerInterface::class);
$nb = $em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('COUNT(ac) AS nb')
->getQuery()
->getSingleScalarResult()
;
->getSingleScalarResult();
yield [ $em->createQueryBuilder()
yield [$em->createQueryBuilder()
->from(AccompanyingPeriod::class, 'ac')
->select('ac.id')
->setFirstResult(\random_int(0, $nb))
->setFirstResult(random_int(0, $nb))
->setMaxResults(1)
->getQuery()
->getSingleScalarResult()
->getSingleScalarResult(),
];
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
@@ -8,10 +15,34 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Create the schema chill_calendar and several calendar entities
* Create the schema chill_calendar and several calendar entities.
*/
final class Version20210715141731 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar_to_persons DROP CONSTRAINT FK_AEE94715A40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals DROP CONSTRAINT FK_FADF2C77A40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_thirdparties DROP CONSTRAINT FK_2BAB7EFDA40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_invites DROP CONSTRAINT FK_FCBEAAAA40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP CONSTRAINT FK_712315ACC5CB285D');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP CONSTRAINT FK_712315ACE980772F');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_invites DROP CONSTRAINT FK_FCBEAAAEA417747');
$this->addSql('DROP SEQUENCE chill_calendar.calendar_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.calendar_range_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.cancel_reason_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.invite_id_seq CASCADE');
$this->addSql('DROP TABLE chill_calendar.calendar');
$this->addSql('DROP TABLE chill_calendar.calendar_to_persons');
$this->addSql('DROP TABLE chill_calendar.calendar_to_non_professionals');
$this->addSql('DROP TABLE chill_calendar.calendar_to_thirdparties');
$this->addSql('DROP TABLE chill_calendar.calendar_to_invites');
$this->addSql('DROP TABLE chill_calendar.calendar_range');
$this->addSql('DROP TABLE chill_calendar.cancel_reason');
$this->addSql('DROP TABLE chill_calendar.invite');
$this->addSql('DROP SCHEMA chill_calendar');
}
public function getDescription(): string
{
return 'Create the schema chill_calendar and several calendar entities';
@@ -69,28 +100,4 @@ final class Version20210715141731 extends AbstractMigration
$this->addSql('ALTER TABLE chill_calendar.calendar_range ADD CONSTRAINT FK_38D57D05A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.invite ADD CONSTRAINT FK_F517FFA7A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar_to_persons DROP CONSTRAINT FK_AEE94715A40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals DROP CONSTRAINT FK_FADF2C77A40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_thirdparties DROP CONSTRAINT FK_2BAB7EFDA40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_invites DROP CONSTRAINT FK_FCBEAAAA40A2C8');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP CONSTRAINT FK_712315ACC5CB285D');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP CONSTRAINT FK_712315ACE980772F');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_invites DROP CONSTRAINT FK_FCBEAAAEA417747');
$this->addSql('DROP SEQUENCE chill_calendar.calendar_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.calendar_range_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.cancel_reason_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_calendar.invite_id_seq CASCADE');
$this->addSql('DROP TABLE chill_calendar.calendar');
$this->addSql('DROP TABLE chill_calendar.calendar_to_persons');
$this->addSql('DROP TABLE chill_calendar.calendar_to_non_professionals');
$this->addSql('DROP TABLE chill_calendar.calendar_to_thirdparties');
$this->addSql('DROP TABLE chill_calendar.calendar_to_invites');
$this->addSql('DROP TABLE chill_calendar.calendar_range');
$this->addSql('DROP TABLE chill_calendar.cancel_reason');
$this->addSql('DROP TABLE chill_calendar.invite');
$this->addSql('DROP SCHEMA chill_calendar');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
@@ -8,10 +15,21 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Adapt calendar entities
* Adapt calendar entities.
*/
final class Version20210723074557 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_calendar.calendar_to_non_professionals (calendar_id INT NOT NULL, person_id INT NOT NULL, PRIMARY KEY(calendar_id, person_id))');
$this->addSql('CREATE INDEX idx_fadf2c77217bbb47 ON chill_calendar.calendar_to_non_professionals (person_id)');
$this->addSql('CREATE INDEX idx_fadf2c77a40a2c8 ON chill_calendar.calendar_to_non_professionals (calendar_id)');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77a40a2c8 FOREIGN KEY (calendar_id) REFERENCES chill_calendar.calendar (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77217bbb47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy TYPE JSON');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy DROP DEFAULT');
}
public function getDescription(): string
{
return 'Adapt calendar entities';
@@ -24,15 +42,4 @@ final class Version20210723074557 extends AbstractMigration
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledby DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.cancel_reason.canceledBy IS NULL');
}
public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_calendar.calendar_to_non_professionals (calendar_id INT NOT NULL, person_id INT NOT NULL, PRIMARY KEY(calendar_id, person_id))');
$this->addSql('CREATE INDEX idx_fadf2c77217bbb47 ON chill_calendar.calendar_to_non_professionals (person_id)');
$this->addSql('CREATE INDEX idx_fadf2c77a40a2c8 ON chill_calendar.calendar_to_non_professionals (calendar_id)');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77a40a2c8 FOREIGN KEY (calendar_id) REFERENCES chill_calendar.calendar (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77217bbb47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy TYPE JSON');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy DROP DEFAULT');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
@@ -8,10 +15,20 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Alter startDate and endDate to datetimetz_immutable
* Alter startDate and endDate to datetimetz_immutable.
*/
final class Version20210723142003 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER startDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER startDate DROP DEFAULT');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER endDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER endDate DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.startdate IS \'(DC2Type:date_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.enddate IS \'(DC2Type:date_immutable)\'');
}
public function getDescription(): string
{
return 'Alter startDate and endDate to datetimetz_immutable';
@@ -26,14 +43,4 @@ final class Version20210723142003 extends AbstractMigration
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.startDate IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.endDate IS \'(DC2Type:datetimetz_immutable)\'');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER startDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER startDate DROP DEFAULT');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER endDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar ALTER endDate DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.startdate IS \'(DC2Type:date_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar.enddate IS \'(DC2Type:date_immutable)\'');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
@@ -8,10 +15,20 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Alter startDate and endDate to datetimetz_immutable on calendarRange
* Alter startDate and endDate to datetimetz_immutable on calendarRange.
*/
final class Version20210723142842 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER startDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER startDate DROP DEFAULT');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER endDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER endDate DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.startdate IS \'(DC2Type:date_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.enddate IS \'(DC2Type:date_immutable)\'');
}
public function getDescription(): string
{
return 'Alter startDate and endDate to datetimetz_immutable on calendarRange';
@@ -26,14 +43,4 @@ final class Version20210723142842 extends AbstractMigration
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.startDate IS \'(DC2Type:datetimetz_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.endDate IS \'(DC2Type:datetimetz_immutable)\'');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER startDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER startDate DROP DEFAULT');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER endDate TYPE DATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_range ALTER endDate DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.startdate IS \'(DC2Type:date_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_calendar.calendar_range.enddate IS \'(DC2Type:date_immutable)\'');
}
}

View File

@@ -1,5 +1,12 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
@@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20211119173557 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
public function getDescription(): string
{
return 'remove comment on deprecated json_array type';
@@ -22,12 +34,7 @@ final class Version20211119173557 extends AbstractMigration
];
foreach ($columns as $col) {
$this->addSql("COMMENT ON COLUMN $col IS NULL");
$this->addSql("COMMENT ON COLUMN {$col} IS NULL");
}
}
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
}