mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge branch 'master' into bootstrap5
This commit is contained in:
@@ -1,25 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2016-2019 Champs-Libres <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\PersonBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -28,39 +10,28 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class ChillPersonMoveCommand extends ContainerAwareCommand
|
||||
final class ChillPersonMoveCommand extends Command
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var PersonMove
|
||||
*/
|
||||
protected $mover;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $chillLogger;
|
||||
|
||||
private PersonMove $mover;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private LoggerInterface $chillLogger;
|
||||
|
||||
public function __construct(
|
||||
PersonMove $mover,
|
||||
PersonMove $mover,
|
||||
EntityManagerInterface $em,
|
||||
LoggerInterface $chillLogger
|
||||
) {
|
||||
parent::__construct('chill:person:move');
|
||||
|
||||
|
||||
$this->mover = $mover;
|
||||
$this->em = $em;
|
||||
$this->chillLogger = $chillLogger;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
@@ -73,14 +44,14 @@ class ChillPersonMoveCommand extends ContainerAwareCommand
|
||||
->addOption('delete-entity', null, InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, "entity to delete", [])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
protected function interact(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (FALSE === $input->hasOption('dump-sql') && FALSE === $input->hasOption('force')) {
|
||||
$msg = "You must use \"--dump-sql\" or \"--force\"";
|
||||
throw new RuntimeException($msg);
|
||||
}
|
||||
|
||||
|
||||
foreach (["from", "to"] as $name) {
|
||||
if (empty($input->getOption($name))) {
|
||||
throw new RuntimeException("You must set a \"$name\" option");
|
||||
@@ -90,7 +61,7 @@ class ChillPersonMoveCommand extends ContainerAwareCommand
|
||||
throw new RuntimeException("The id in \"$name\" field does not contains "
|
||||
. "only digits: $id");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
@@ -99,16 +70,16 @@ class ChillPersonMoveCommand extends ContainerAwareCommand
|
||||
$from = $repository->find($input->getOption('from'));
|
||||
$to = $repository->find($input->getOption('to'));
|
||||
$deleteEntities = $input->getOption('delete-entity');
|
||||
|
||||
|
||||
if ($from === NULL) {
|
||||
throw new RuntimeException(sprintf("Person \"from\" with id %d not found", $input->getOption('from')));
|
||||
}
|
||||
if ($to === NULL) {
|
||||
throw new RuntimeException(sprintf("Person \"to\" with id %d not found", $input->getOption('to')));
|
||||
}
|
||||
|
||||
|
||||
$sqls = $this->mover->getSQL($from, $to, $deleteEntities);
|
||||
|
||||
|
||||
if ($input->getOption('dump-sql')) {
|
||||
foreach($sqls as $sql) {
|
||||
$output->writeln($sql);
|
||||
@@ -125,25 +96,25 @@ class ChillPersonMoveCommand extends ContainerAwareCommand
|
||||
$connection->executeQuery($sql);
|
||||
}
|
||||
$connection->commit();
|
||||
|
||||
|
||||
$this->chillLogger->notice("Move a person from command line succeeded", $ctxt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function buildLoggingContext(Person $from, Person $to, $deleteEntities, $sqls)
|
||||
{
|
||||
$ctxt = [
|
||||
'from' => $from->getId(),
|
||||
'to' => $to->getId()
|
||||
];
|
||||
|
||||
|
||||
foreach ($deleteEntities as $key => $de) {
|
||||
$ctxt['delete_entity_'.$key] = $de;
|
||||
}
|
||||
foreach ($sqls as $key => $sql) {
|
||||
$ctxt['sql_'.$key] = $sql;
|
||||
}
|
||||
|
||||
|
||||
return $ctxt;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Command;
|
||||
|
||||
use Chill\PersonBundle\Service\Import\ChillImporter;
|
||||
use Chill\PersonBundle\Service\Import\SocialWorkMetadataInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use League\Csv\Reader;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Throwable;
|
||||
|
||||
final class ImportSocialWorkMetadata extends Command
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected EntityManagerInterface $em;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected ChillImporter $importer;
|
||||
|
||||
public function __construct(
|
||||
SocialWorkMetadataInterface $socialWorkMetadata
|
||||
) {
|
||||
parent::__construct('chill:person:import-socialwork');
|
||||
|
||||
$this->importer = $socialWorkMetadata;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('chill:person:import-socialwork')
|
||||
->addOption('filepath', 'f', InputOption::VALUE_REQUIRED, 'The file to import.')
|
||||
->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'The default language');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$filepath = $input->getOption('filepath');
|
||||
|
||||
try {
|
||||
$csv = Reader::createFromPath($filepath);
|
||||
} catch (Throwable $e) {
|
||||
throw new Exception('Error while loading CSV.',0, $e);
|
||||
}
|
||||
|
||||
$csv->setDelimiter(';');
|
||||
|
||||
return true === $this->importer->import($csv) ?
|
||||
0:
|
||||
1;
|
||||
}
|
||||
}
|
@@ -252,18 +252,6 @@ final class PersonController extends AbstractController
|
||||
*/
|
||||
$person = $form->getData();
|
||||
|
||||
$periods = $person->getAccompanyingPeriodsOrdered();
|
||||
$period = $periods[0];
|
||||
$period->setOpeningDate($form['creation_date']->getData());
|
||||
// $person = new Person($form['creation_date']->getData());
|
||||
//
|
||||
// $person->setFirstName($form['firstName']->getData())
|
||||
// ->setLastName($form['lastName']->getData())
|
||||
// ->setGender($form['gender']->getData())
|
||||
// ->setBirthdate($form['birthdate']->getData())
|
||||
// ->setCenter($form['center']->getData())
|
||||
// ;
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
@@ -364,7 +352,6 @@ final class PersonController extends AbstractController
|
||||
'lastName' => $form['lastName']->getData(),
|
||||
'birthdate' => $form['birthdate']->getData(),
|
||||
'gender' => $form['gender']->getData(),
|
||||
'creation_date' => $form['creation_date']->getData(),
|
||||
'form' => $form->createView()));
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
|
||||
use Chill\PersonBundle\DataFixtures\ORM\LoadAccompanyingPeriod;
|
||||
|
||||
/**
|
||||
* Load notififications into database
|
||||
*/
|
||||
class LoadAccompanyingPeriodNotifications extends AbstractFixture implements DependentFixtureInterface
|
||||
{
|
||||
use LoadAbstractNotificationsTrait;
|
||||
|
||||
public $notifs = [
|
||||
[
|
||||
'message' => 'Hello !',
|
||||
'entityClass' => AccompanyingPeriod::class,
|
||||
'entityRef' => LoadAccompanyingPeriod::ACCOMPANYING_PERIOD,
|
||||
'sender' => 'center a_social',
|
||||
'addressees' => [
|
||||
'center a_social',
|
||||
'center a_administrative',
|
||||
'center a_direction',
|
||||
'multi_center'
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadAccompanyingPeriod::class,
|
||||
];
|
||||
}
|
||||
}
|
@@ -183,6 +183,14 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
private function addAPerson(array $person, ObjectManager $manager)
|
||||
{
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(
|
||||
new AccompanyingPeriod(
|
||||
(new \DateTime())
|
||||
->sub(
|
||||
new \DateInterval('P'.\random_int(0, 180).'D')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($person as $key => $value) {
|
||||
switch ($key) {
|
||||
|
@@ -69,11 +69,11 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
||||
$loader->load('services/search.yaml');
|
||||
$loader->load('services/menu.yaml');
|
||||
$loader->load('services/privacyEvent.yaml');
|
||||
$loader->load('services/command.yaml');
|
||||
$loader->load('services/actions.yaml');
|
||||
$loader->load('services/form.yaml');
|
||||
$loader->load('services/alt_names.yaml');
|
||||
$loader->load('services/household.yaml');
|
||||
$loader->load('services/notification.yaml');
|
||||
// We can get rid of this file when the service 'chill.person.repository.person' is no more used.
|
||||
// We should use the PersonRepository service instead of a custom service name.
|
||||
$loader->load('services/repository.yaml');
|
||||
|
@@ -379,12 +379,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
*/
|
||||
private Collection $householdAddresses;
|
||||
|
||||
/**
|
||||
* Person constructor.
|
||||
*
|
||||
* @param \DateTime|null $opening
|
||||
*/
|
||||
public function __construct(\DateTime $opening = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->accompanyingPeriodParticipations = new ArrayCollection();
|
||||
$this->spokenLanguages = new ArrayCollection();
|
||||
@@ -393,12 +388,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
$this->otherPhoneNumbers = new ArrayCollection();
|
||||
$this->householdParticipations = new ArrayCollection();
|
||||
$this->householdAddresses = new ArrayCollection();
|
||||
|
||||
if ($opening === null) {
|
||||
$opening = new \DateTime();
|
||||
}
|
||||
|
||||
$this->open(new AccompanyingPeriod($opening));
|
||||
$this->genderComment = new CommentEmbeddable();
|
||||
$this->maritalStatusComment = new CommentEmbeddable();
|
||||
}
|
||||
@@ -734,9 +723,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this->birthdate;
|
||||
}
|
||||
|
||||
public function getAge(): int
|
||||
public function getAge(): ?int
|
||||
{
|
||||
return date_diff($this->birthdate, date_create('now'))->format("%y");
|
||||
if ($this->birthdate instanceof \DateTimeInterface) {
|
||||
return date_diff($this->birthdate, date_create('now'))->format("%y");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,7 +23,7 @@ class Evaluation
|
||||
private $title = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="dateinterval")
|
||||
* @ORM\Column(type="dateinterval", nullable=true)
|
||||
*/
|
||||
private $delay;
|
||||
|
||||
|
@@ -47,7 +47,7 @@ class SocialAction
|
||||
private $children;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="dateinterval")
|
||||
* @ORM\Column(type="dateinterval", nullable=true)
|
||||
*/
|
||||
private $defaultNotificationDelay;
|
||||
|
||||
|
@@ -26,7 +26,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Form\Type\CenterType;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
|
||||
@@ -80,9 +80,6 @@ final class CreationPersonType extends AbstractType
|
||||
'property_path' => 'birthdate'
|
||||
))
|
||||
->add('gender', HiddenType::class)
|
||||
->add('creation_date', HiddenType::class, array(
|
||||
'mapped' => false
|
||||
))
|
||||
->add('form_status', HiddenType::class, array(
|
||||
'mapped' => false,
|
||||
'data' => $options['form_status']
|
||||
@@ -99,25 +96,18 @@ final class CreationPersonType extends AbstractType
|
||||
|
||||
$builder->get('birthdate')
|
||||
->addModelTransformer($dateToStringTransformer);
|
||||
$builder->get('creation_date')
|
||||
->addModelTransformer($dateToStringTransformer);
|
||||
$builder->get('center')
|
||||
->addModelTransformer($this->centerTransformer);
|
||||
} else {
|
||||
$builder
|
||||
->add('firstName')
|
||||
->add('lastName')
|
||||
->add('birthdate', DateType::class, array('required' => false,
|
||||
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
|
||||
->add('birthdate', ChillDateType::class, [
|
||||
'required' => false,
|
||||
])
|
||||
->add('gender', GenderType::class, array(
|
||||
'required' => true, 'placeholder' => null
|
||||
))
|
||||
->add('creation_date', DateType::class, array(
|
||||
'required' => true,
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
'mapped' => false,
|
||||
'data' => new \DateTime()))
|
||||
->add('form_status', HiddenType::class, array(
|
||||
'data' => $options['form_status'],
|
||||
'mapped' => false
|
||||
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Notification;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
final class AccompanyingPeriodNotificationRenderer
|
||||
{
|
||||
public function supports(Notification $notification)
|
||||
{
|
||||
return $notification->getRelatedEntityClass() == AccompanyingPeriod::class;
|
||||
}
|
||||
|
||||
public function getTemplate()
|
||||
{
|
||||
return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig';
|
||||
}
|
||||
|
||||
public function getTemplateData(Notification $notification)
|
||||
{
|
||||
return ['notification' => $notification];
|
||||
}
|
||||
}
|
@@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class EvaluationRepository
|
||||
final class EvaluationRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
@@ -14,4 +15,40 @@ final class EvaluationRepository
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(Evaluation::class);
|
||||
}
|
||||
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Evaluation
|
||||
{
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Evaluation>
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Evaluation>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Evaluation
|
||||
{
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Evaluation::class;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -18,31 +18,27 @@ final class GoalRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(Goal::class);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Goal
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
/**
|
||||
* @return array<int, Goal>
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
|
||||
/**
|
||||
* @return array<int, Goal>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return Goal::class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Goal[]
|
||||
@@ -91,4 +87,16 @@ final class GoalRepository implements ObjectRepository
|
||||
|
||||
return $qb;
|
||||
}
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Goal
|
||||
{
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Goal::class;
|
||||
}
|
||||
}
|
||||
|
@@ -19,31 +19,19 @@ final class ResultRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(Result::class);
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?Result
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
/**
|
||||
* @return array<int, Result>
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
{
|
||||
return Result::class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Result[]
|
||||
@@ -133,5 +121,25 @@ final class ResultRepository implements ObjectRepository
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, Result>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?Result
|
||||
{
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Result::class;
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,9 @@ namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class SocialActionRepository
|
||||
final class SocialActionRepository implements ObjectRepository
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
@@ -14,4 +15,38 @@ final class SocialActionRepository
|
||||
{
|
||||
$this->repository = $entityManager->getRepository(SocialAction::class);
|
||||
}
|
||||
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?SocialAction
|
||||
{
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, SocialAction>
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, SocialAction>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialAction
|
||||
{
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getClassName(): string
|
||||
{
|
||||
return SocialAction::class;
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Repository\SocialWork;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
@@ -17,42 +18,36 @@ final class SocialIssueRepository implements ObjectRepository
|
||||
$this->repository = $entityManager->getRepository(SocialIssue::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function find($id)
|
||||
public function find($id, ?int $lockMode = null, ?int $lockVersion = null): ?SocialIssue
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return array<int, SocialIssue>
|
||||
*/
|
||||
public function findAll()
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return array<int, SocialIssue>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
|
||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findOneBy(array $criteria)
|
||||
public function findOneBy(array $criteria, ?array $orderBy = null): ?SocialIssue
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
return $this->repository->findOneBy($criteria, $orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return class-string
|
||||
*/
|
||||
public function getClassName()
|
||||
public function getClassName(): string
|
||||
{
|
||||
return SocialIssue::class;
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
<a href="{{ path('chill_person_accompanying_course_index', {'accompanying_period_id': notification.relatedEntityId }) }}">
|
||||
Go to Acc. period.
|
||||
</a>
|
@@ -63,7 +63,7 @@
|
||||
</time>
|
||||
{%- if options['addAge'] -%}
|
||||
<span class="age">
|
||||
{{ person.age ~ ((person.age > 1) ? ' ans' : ' an') }}
|
||||
{{ 'years_old'|trans({ 'age': person.age }) }}
|
||||
</span>
|
||||
{%- endif -%}
|
||||
</p>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
{#
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* * 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.
|
||||
|
@@ -68,7 +68,11 @@
|
||||
<dd>{{ person|chill_entity_render_string }}</dd>
|
||||
|
||||
<dt>{{ 'Date of birth'|trans }}</dt>
|
||||
<dd>{{ birthdate|format_date('long')|default( 'Unknown date of birth'|trans ) }}</dd>
|
||||
{% if birthdate is empty %}
|
||||
<dd>{{ 'Unknown date of birth'|trans }}</dd>
|
||||
{% else %}
|
||||
<dd>{{ birthdate|format_date('long') }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt>{{ 'Gender'|trans }}</dt>
|
||||
<dd>{{ gender|trans }}</dd>
|
||||
@@ -83,8 +87,13 @@
|
||||
</dl>
|
||||
|
||||
{{ form_rest(form) }}
|
||||
<button class="btn btn-submit" type="submit"><i class="fa fa-check"></i> {{ 'Confirm the creation'|trans }}</button>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="sc-button bt-create change-icon" type="submit"><i class="fa fa-check"></i> {{ 'Confirm the creation'|trans }}</button>
|
||||
</li>
|
||||
</ul>
|
||||
{{ form_end(form) }}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\Import;
|
||||
|
||||
interface ChillImporter
|
||||
{
|
||||
public function import(iterable $dataset): bool;
|
||||
}
|
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\Import;
|
||||
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\Expr\Comparison;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use Exception;
|
||||
|
||||
final class SocialWorkMetadata implements SocialWorkMetadataInterface
|
||||
{
|
||||
private SocialIssueRepository $socialIssueRepository;
|
||||
|
||||
private SocialActionRepository $socialActionRepository;
|
||||
|
||||
private GoalRepository $goalRepository;
|
||||
|
||||
private ResultRepository $resultRepository;
|
||||
|
||||
private EvaluationRepository $evaluationRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
public function __construct(
|
||||
SocialIssueRepository $socialIssueRepository,
|
||||
SocialActionRepository $socialActionRepository,
|
||||
GoalRepository $goalRepository,
|
||||
ResultRepository $resultRepository,
|
||||
EvaluationRepository $evaluationRepository,
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
$this->socialIssueRepository = $socialIssueRepository;
|
||||
$this->socialActionRepository = $socialActionRepository;
|
||||
$this->goalRepository = $goalRepository;
|
||||
$this->resultRepository = $resultRepository;
|
||||
$this->evaluationRepository = $evaluationRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function import(iterable $dataset): bool
|
||||
{
|
||||
foreach ($dataset as $row) {
|
||||
$this->import1(
|
||||
array_map(
|
||||
static fn (string $column): ?string => '' === $column ? null : $column,
|
||||
array_map('trim', $row)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function import1(array $row): void
|
||||
{
|
||||
// Structure:
|
||||
// Index 0: SocialIssue.parent
|
||||
// Index 1: SocialIssue
|
||||
// Index 2: SocialAction.parent
|
||||
// Index 3: SocialAction
|
||||
// Index 4: Goal
|
||||
// Index 5: Result
|
||||
// Index 6: Evaluation
|
||||
|
||||
$socialIssue = $this->handleSocialIssue($row[0], $row[1]);
|
||||
|
||||
$socialAction = $this->handleSocialAction($row[2], $row[3], $socialIssue);
|
||||
|
||||
$goal = $this->handleGoal($row[4], $socialAction);
|
||||
|
||||
$result = $this->handleResult($row[5], $socialAction, $goal);
|
||||
|
||||
$eval = $this->handleEvaluation($row[6], $socialAction);
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
private function handleSocialIssue(?string $socialIssueTitle = null, ?string $socialIssueChildrenTitle = null): SocialIssue
|
||||
{
|
||||
if (null !== $socialIssueChildrenTitle) {
|
||||
/** @var SocialIssue $socialIssueChildren */
|
||||
$socialIssueChildren = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueChildrenTitle]);
|
||||
$socialIssueChildren->setTitle(['fr' => $socialIssueChildrenTitle]);
|
||||
|
||||
$this->entityManager->persist($socialIssueChildren);
|
||||
}
|
||||
|
||||
/** @var SocialIssue $socialIssue */
|
||||
$socialIssue = $this->getOrCreateEntity($this->socialIssueRepository, 'title', ['fr' => $socialIssueTitle]);
|
||||
$socialIssue->setTitle(['fr' => $socialIssueTitle]);
|
||||
|
||||
if (null !== $socialIssueChildrenTitle) {
|
||||
$socialIssue->addChild($socialIssueChildren);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($socialIssue);
|
||||
|
||||
return null === $socialIssueChildrenTitle ? $socialIssue : $socialIssueChildren;
|
||||
}
|
||||
|
||||
private function handleSocialAction(?string $socialActionTitle, ?string $socialActionChildrenTitle, SocialIssue $socialIssue): SocialAction
|
||||
{
|
||||
if (null !== $socialActionChildrenTitle) {
|
||||
/** @var SocialAction $socialActionChildren */
|
||||
$socialActionChildren = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionChildrenTitle]);
|
||||
$socialActionChildren->setTitle(['fr' => $socialActionChildrenTitle]);
|
||||
|
||||
$this->entityManager->persist($socialActionChildren);
|
||||
}
|
||||
|
||||
/** @var SocialIssue $socialIssue */
|
||||
$socialAction = $this->getOrCreateEntity($this->socialActionRepository, 'title', ['fr' => $socialActionTitle]);
|
||||
$socialAction->setTitle(['fr' => $socialActionTitle]);
|
||||
|
||||
if (null !== $socialActionChildrenTitle) {
|
||||
$socialActionChildren->setIssue($socialIssue);
|
||||
$this->entityManager->persist($socialActionChildren);
|
||||
|
||||
$socialAction->addChild($socialActionChildren);
|
||||
} else {
|
||||
$socialAction->setIssue($socialIssue);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($socialAction);
|
||||
|
||||
return null === $socialActionChildrenTitle ? $socialAction : $socialActionChildren;
|
||||
}
|
||||
|
||||
private function handleGoal(?string $goalTitle = null, ?SocialAction $socialAction = null): ?Goal
|
||||
{
|
||||
if (null === $goalTitle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Goal $goal */
|
||||
$goal = $this->getOrCreateEntity($this->goalRepository, 'title', ['fr' => $goalTitle]);
|
||||
$goal->setTitle(['fr' => $goalTitle]);
|
||||
|
||||
if (null !== $socialAction) {
|
||||
$socialAction->addGoal($goal);
|
||||
$goal->addSocialAction($socialAction);
|
||||
|
||||
$this->entityManager->persist($socialAction);
|
||||
}
|
||||
|
||||
$this->entityManager->persist($goal);
|
||||
|
||||
return $goal;
|
||||
}
|
||||
|
||||
private function handleResult(?string $resultTitle = null, ?SocialAction $socialAction = null, ?Goal $goal = null): ?Result
|
||||
{
|
||||
if (null === $resultTitle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Result $result */
|
||||
$result = $this->getOrCreateEntity($this->resultRepository, 'title', ['fr' => $resultTitle]);
|
||||
$result->setTitle(['fr' => $resultTitle]);
|
||||
|
||||
if (null !== $goal) {
|
||||
$result->addGoal($goal);
|
||||
$goal->addResult($result);
|
||||
|
||||
$this->entityManager->persist($goal);
|
||||
} else {
|
||||
$result->addSocialAction($socialAction);
|
||||
}
|
||||
|
||||
$result->addSocialAction($socialAction);
|
||||
$socialAction->addResult($result);
|
||||
|
||||
$this->entityManager->persist($result);
|
||||
$this->entityManager->persist($socialAction);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function handleEvaluation(?string $evaluationTitle, SocialAction $socialAction): ?Evaluation
|
||||
{
|
||||
if (null === $evaluationTitle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var Evaluation $eval */
|
||||
$eval = $this->getOrCreateEntity($this->evaluationRepository, 'title', ['fr' => $evaluationTitle]);
|
||||
$eval->setTitle(['fr' => $evaluationTitle]);
|
||||
$eval->setSocialAction($socialAction);
|
||||
|
||||
$this->entityManager->persist($eval);
|
||||
|
||||
return $eval;
|
||||
}
|
||||
|
||||
private function findByJson(ObjectRepository $repository, string $field, array $jsonCriterias): array
|
||||
{
|
||||
$qb = $this
|
||||
->entityManager
|
||||
->createQueryBuilder()
|
||||
->select('s')
|
||||
->from($repository->getClassName(), 's');
|
||||
|
||||
$expr = $qb->expr();
|
||||
|
||||
$temporaryJsonCriterias = $jsonParameters = [];
|
||||
|
||||
foreach ($jsonCriterias as $key => $value) {
|
||||
$temporaryJsonCriterias[] = [$field, $key, $value, sprintf(':placeholder_%s_%s', $field, $key)];
|
||||
}
|
||||
|
||||
$jsonParameters = array_reduce(
|
||||
$temporaryJsonCriterias,
|
||||
static function (array $carry, array $row): array
|
||||
{
|
||||
[,, $value, $placeholder] = $row;
|
||||
|
||||
return array_merge(
|
||||
$carry,
|
||||
[
|
||||
$placeholder => sprintf('"%s"', $value),
|
||||
]
|
||||
);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
$jsonPredicates = array_map(
|
||||
static function (array $row) use ($expr): Comparison
|
||||
{
|
||||
[$field, $key,, $placeholder] = $row;
|
||||
|
||||
$left = sprintf(
|
||||
"GET_JSON_FIELD_BY_KEY(s.%s, '%s')",
|
||||
$field,
|
||||
$key
|
||||
);
|
||||
|
||||
return $expr
|
||||
->eq(
|
||||
$left,
|
||||
$placeholder
|
||||
);
|
||||
},
|
||||
$temporaryJsonCriterias
|
||||
);
|
||||
|
||||
$query = $qb
|
||||
->select('s')
|
||||
->where(...$jsonPredicates)
|
||||
->setParameters($jsonParameters)
|
||||
->getQuery();
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
|
||||
private function getOrCreateEntity(ObjectRepository $repository, string $field, array $jsonCriterias = [])
|
||||
{
|
||||
$results = $this
|
||||
->findByJson(
|
||||
$repository,
|
||||
$field,
|
||||
$jsonCriterias
|
||||
);
|
||||
|
||||
switch (true) {
|
||||
case count($results) === 0:
|
||||
$entity = $repository->getClassName();
|
||||
$entity = new $entity();
|
||||
break;
|
||||
case count($results) === 1;
|
||||
$entity = current($results);
|
||||
break;
|
||||
case count($results) > 1;
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'More than one entity(%s) found.',
|
||||
$repository->getClassName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\Import;
|
||||
|
||||
interface SocialWorkMetadataInterface extends ChillImporter
|
||||
{
|
||||
}
|
@@ -152,7 +152,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
* with : dateClosing: 2015-02-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
* And the next page should have a `.error` element present in page
|
||||
* And the next page should have a `.alert-danger` element present in page
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
@@ -174,7 +174,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
->filter('.alert-success')->count(),
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
* with : dateClosing: 2014-01-01
|
||||
* with : the last closing motive in list
|
||||
* Then the response should redirect to period view
|
||||
* And the next page should have a `.error` element present in page
|
||||
* And the next page should have a `.alert-danger` element present in page
|
||||
*
|
||||
* @todo
|
||||
*/
|
||||
@@ -207,8 +207,8 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stays on the /close page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse
|
||||
->filter('.error')->count(),
|
||||
"an '.error' element is shown");
|
||||
->filter('.alert-danger')->count(),
|
||||
"an '.alert-danger' element is shown");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,7 +240,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'),
|
||||
'the server redirects to /accompanying-period page');
|
||||
$this->assertGreaterThan(0, $this->client->followRedirect()
|
||||
->filter('.success')->count(),
|
||||
->filter('.alert-success')->count(),
|
||||
"a 'success' element is shown");
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the server stay on form page');
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawlerResponse->filter('.alert-danger')->count(),
|
||||
"an 'error' element is shown");
|
||||
}
|
||||
|
||||
|
@@ -93,8 +93,6 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
'The page contains a "gender" input');
|
||||
$this->assertTrue($form->has(self::BIRTHDATE_INPUT),
|
||||
'The page has a "date of birth" input');
|
||||
$this->assertTrue($form->has(self::CREATEDATE_INPUT),
|
||||
'The page contains a "creation date" input');
|
||||
|
||||
$genderType = $form->get(self::GENDER_INPUT);
|
||||
$this->assertEquals('radio', $genderType->getType(),
|
||||
@@ -107,10 +105,6 @@ class PersonControllerCreateTest extends WebTestCase
|
||||
'gender has "femme" option');
|
||||
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
|
||||
|
||||
$today = new \DateTime();
|
||||
$this->assertEquals($today->format('d-m-Y'), $form->get(self::CREATEDATE_INPUT)
|
||||
->getValue(), 'The creation date input has the current date by default');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@@ -102,7 +102,6 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
public function testHiddenFielsArePresent()
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$configurables = array('placeOfBirth', 'phonenumber', 'email',
|
||||
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus');
|
||||
$form = $crawler->selectButton('Enregistrer')->form(); //;
|
||||
@@ -190,7 +189,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
'the value '.$field.' is updated in db');
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
$this->assertGreaterThan(0, $crawler->filter('.success')->count(),
|
||||
$this->assertGreaterThan(0, $crawler->filter('.alert-success')->count(),
|
||||
'a element .success is shown');
|
||||
|
||||
if($field == 'birthdate' or $field == 'memo' or $field == 'countryOfBirth' or $field == 'nationality'
|
||||
@@ -245,7 +244,7 @@ class PersonControllerUpdateTest extends WebTestCase
|
||||
|
||||
$this->assertFalse($this->client->getResponse()->isRedirect(),
|
||||
'the page is not redirected to /general');
|
||||
$this->assertGreaterThan(0, $crawler->filter('.error')->count(),
|
||||
$this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(),
|
||||
'a element .error is shown');
|
||||
}
|
||||
|
||||
|
@@ -45,11 +45,12 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
public function testGetCurrentAccompanyingPeriod()
|
||||
{
|
||||
$d = new \DateTime('yesterday');
|
||||
$p = new Person($d);
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
|
||||
|
||||
$period = $p->getCurrentAccompanyingPeriod();
|
||||
|
||||
$this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period);
|
||||
$this->assertInstanceOf(AccompanyingPeriod::class, $period);
|
||||
$this->assertTrue($period->isOpen());
|
||||
$this->assertEquals($d, $period->getOpeningDate());
|
||||
|
||||
@@ -67,7 +68,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
|
||||
{
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
@@ -93,7 +95,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testAccompanyingPeriodOrderSameDateOpening() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
|
||||
|
||||
$g = new \DateTime("2013/4/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
|
||||
@@ -120,7 +123,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testDateCoveringWithCoveringAccompanyingPeriod() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
@@ -145,7 +149,8 @@ class PersonTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testNotOpenAFileReOpenedLater() {
|
||||
$d = new \DateTime("2013/2/1");
|
||||
$p = new Person($d);
|
||||
$p = new Person();
|
||||
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
|
||||
|
||||
$e = new \DateTime("2013/3/1");
|
||||
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
|
||||
|
@@ -20,9 +20,11 @@
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Timeline;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Tests\Functional\WebTestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* This class tests entries are shown for closing and opening
|
||||
@@ -31,22 +33,20 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
*/
|
||||
class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controller\AccompanyingPeriodControllerTest
|
||||
class TimelineAccompanyingPeriodTest extends WebTestCase
|
||||
{
|
||||
public function testEntriesAreShown()
|
||||
use PrepareClientTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataPersonWithAccompanyingPeriod
|
||||
*/
|
||||
public function testEntriesAreShown($personId)
|
||||
{
|
||||
$this->generatePeriods(array(
|
||||
[
|
||||
'openingDate' => '2014-01-01',
|
||||
'closingDate' => '2014-12-31',
|
||||
'closingMotive' => $this->getRandomClosingMotive()
|
||||
]
|
||||
));
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$crawler = $client->request('GET', "/en/person/{$personId}/timeline");
|
||||
|
||||
$crawler = $this->client->request('GET', '/en/person/'
|
||||
.$this->person->getId().'/timeline');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful(),
|
||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||
"the timeline page loads sucessfully");
|
||||
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
|
||||
"the timeline page contains multiple div inside a .timeline element");
|
||||
@@ -57,5 +57,34 @@ class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controlle
|
||||
$crawler->Filter('.timeline')->text(),
|
||||
"the text 'Une période d'accompagnement a été fermée' is present");
|
||||
}
|
||||
|
||||
public function provideDataPersonWithAccompanyingPeriod()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$qb = self::$container->get(EntityManagerInterface::class)
|
||||
->createQueryBuilder()
|
||||
;
|
||||
$personIds = $qb
|
||||
->from(Person::class, 'p')
|
||||
->join('p.accompanyingPeriodParticipations', 'part')
|
||||
->join('part.accompanyingPeriod', 'period')
|
||||
->join('p.center', 'center')
|
||||
->select('p.id')
|
||||
->where($qb->expr()->isNotNull('period.closingDate'))
|
||||
->andWhere($qb->expr()->eq('center.name', ':center'))
|
||||
->setParameter('center', 'Center A')
|
||||
->setMaxResults(1000)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
\shuffle($personIds);
|
||||
|
||||
yield [ \array_pop($personIds)['id'] ];
|
||||
yield [ \array_pop($personIds)['id'] ];
|
||||
yield [ \array_pop($personIds)['id'] ];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,12 +6,24 @@ services:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\PersonBundle\Service\:
|
||||
resource: '../Service/'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\PersonBundle\Serializer\Normalizer\:
|
||||
resource: '../Serializer/Normalizer/'
|
||||
autowire: true
|
||||
tags:
|
||||
- { name: 'serializer.normalizer', priority: 64 }
|
||||
|
||||
Chill\PersonBundle\Command\:
|
||||
resource: '../Command/'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
chill.person.form.type.select2maritalstatus:
|
||||
class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType
|
||||
arguments:
|
||||
@@ -49,7 +61,7 @@ services:
|
||||
tags:
|
||||
- { name: security.voter }
|
||||
- { name: chill.role }
|
||||
|
||||
|
||||
chill.person.birthdate_validation:
|
||||
class: Chill\PersonBundle\Validator\Constraints\BirthdateValidator
|
||||
arguments:
|
||||
|
@@ -1,19 +0,0 @@
|
||||
services:
|
||||
Chill\PersonBundle\Command\ChillPersonMoveCommand:
|
||||
arguments:
|
||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||
$mover: '@Chill\PersonBundle\Actions\Remove\PersonMove'
|
||||
$chillLogger: '@chill.main.logger'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
Chill\PersonBundle\Command\ImportPeopleFromCSVCommand:
|
||||
arguments:
|
||||
$logger: '@logger'
|
||||
$helper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
|
||||
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||
$customFieldProvider: '@Chill\CustomFieldsBundle\Service\CustomFieldProvider'
|
||||
$eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface'
|
||||
$formFactory: '@form.factory'
|
||||
tags:
|
||||
- { name: console.command }
|
@@ -0,0 +1,3 @@
|
||||
services:
|
||||
Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer:
|
||||
autowire: true
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210623142046 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_action ALTER defaultnotificationdelay DROP NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_action ALTER defaultNotificationDelay SET NOT NULL');
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210624131722 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER delay DROP NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER delay SET NOT NULL');
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Person;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210624131723 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER notificationdelay DROP NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_person_social_work_evaluation ALTER notificationdelay SET NOT NULL');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user