apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -16,10 +16,8 @@ use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use DateTimeImmutable;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
@@ -41,7 +39,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
$person = $event->getPerson();
foreach ($person->getCurrentAccompanyingPeriods() as $period) {
if ($period->getStep() === AccompanyingPeriod::STEP_DRAFT) {
if (AccompanyingPeriod::STEP_DRAFT === $period->getStep()) {
continue;
}
@@ -49,7 +47,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
$period->getPersonLocation() === $person
&& (
$event->getMoveDate() >= $period->getLastLocationHistory()->getStartDate()
|| $event->willChangeBeActiveAt(new DateTimeImmutable('now'))
|| $event->willChangeBeActiveAt(new \DateTimeImmutable('now'))
)
&& null !== $period->getUser()
&& $period->getUser() !== $this->security->getUser()

View File

@@ -18,7 +18,6 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Workflow\Event\EnteredEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -39,7 +38,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
{
if (
$enteredEvent->getMarking()->has(AccompanyingPeriod::STEP_CONFIRMED)
and $enteredEvent->getTransition()->getName() === 'confirm'
and 'confirm' === $enteredEvent->getTransition()->getName()
) {
$this->onPeriodConfirmed($enteredEvent->getSubject());
}
@@ -50,7 +49,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
if ($period->isChangedUser()
&& $period->getUser() !== $this->security->getUser()
&& null !== $period->getUser()
&& $period->getStep() !== AccompanyingPeriod::STEP_DRAFT
&& AccompanyingPeriod::STEP_DRAFT !== $period->getStep()
&& !$period->isPreventUserIsChangedNotification()
) {
$this->generateNotificationToUser($period);
@@ -62,12 +61,12 @@ class UserRefEventSubscriber implements EventSubscriberInterface
$notification = new Notification();
$urgentStatement =
$period->isEmergency() ? strtoupper($this->translator->trans('accompanying_period.emergency')) . ' ' : '';
$period->isEmergency() ? strtoupper($this->translator->trans('accompanying_period.emergency')).' ' : '';
$notification
->setRelatedEntityId($period->getId())
->setRelatedEntityClass(AccompanyingPeriod::class)
->setTitle($urgentStatement . $this->translator->trans('period_notification.period_designated_subject'))
->setTitle($urgentStatement.$this->translator->trans('period_notification.period_designated_subject'))
->setMessage($this->engine->render(
'@ChillPerson/Notification/accompanying_course_designation.md.twig',
[

View File

@@ -28,7 +28,7 @@ class AccompanyingPeriodStepChangeMessageHandler implements MessageHandlerInterf
public function __invoke(AccompanyingPeriodStepChangeRequestMessage $message): void
{
if (null === $period = $this->accompanyingPeriodRepository->find($message->getPeriodId())) {
throw new \RuntimeException(self::LOG_PREFIX . 'Could not find period with this id: '. $message->getPeriodId());
throw new \RuntimeException(self::LOG_PREFIX.'Could not find period with this id: '.$message->getPeriodId());
}
($this->changer)($period, $message->getTransition());

View File

@@ -14,7 +14,7 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Lifecycle;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
/**
* Message which will request a change in the step of accompanying period
* Message which will request a change in the step of accompanying period.
*/
class AccompanyingPeriodStepChangeRequestMessage
{
@@ -31,7 +31,7 @@ class AccompanyingPeriodStepChangeRequestMessage
$this->periodId = $id;
}
throw new \LogicException("This AccompanyingPeriod does not have and id yet");
throw new \LogicException('This AccompanyingPeriod does not have and id yet');
}
}

View File

@@ -13,13 +13,12 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Lifecycle;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodInfoRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\MessageBusInterface;
/**
* Gather all the accompanying period which needs a change in step
* Gather all the accompanying period which needs a change in step.
*/
class AccompanyingPeriodStepChangeRequestor
{

View File

@@ -17,7 +17,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\Workflow\Registry;
/**
* Change the step of an accompanying period
* Change the step of an accompanying period.
*
* This should be invoked through scripts (not in the in context of an http request, or an
* action from a user).
@@ -32,14 +32,14 @@ class AccompanyingPeriodStepChanger
private readonly Registry $workflowRegistry,
) {}
public function __invoke(AccompanyingPeriod $period, string $transition, ?string $workflowName = null): void
public function __invoke(AccompanyingPeriod $period, string $transition, string $workflowName = null): void
{
$workflow = $this->workflowRegistry->get($period, $workflowName);
if (!$workflow->can($period, $transition)) {
$this->logger->info(self::LOG_PREFIX . 'not able to apply the transition on period', [
$this->logger->info(self::LOG_PREFIX.'not able to apply the transition on period', [
'period_id' => $period->getId(),
'transition' => $transition
'transition' => $transition,
]);
return;
@@ -49,9 +49,9 @@ class AccompanyingPeriodStepChanger
$this->entityManager->flush();
$this->logger->info(self::LOG_PREFIX . 'could apply a transition', [
$this->logger->info(self::LOG_PREFIX.'could apply a transition', [
'period_id' => $period->getId(),
'transition' => $transition
'transition' => $transition,
]);
}
}

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;

View File

@@ -33,10 +33,10 @@ class ActionEvent extends \Symfony\Contracts\EventDispatcher\Event
protected $preSql = [];
/**
* @param string $entity
* @param string $entity
* @param mixed[] $metadata
* @param int $personId
* @param string $sqlStatement
* @param int $personId
* @param string $sqlStatement
*/
public function __construct(
protected $personId,

View File

@@ -19,7 +19,7 @@ class PersonMoveAccompanyingPeriodParticipationHandler implements PersonMoveSqlH
{
public function supports(string $className, string $field): bool
{
return $className === AccompanyingPeriodParticipation::class;
return AccompanyingPeriodParticipation::class === $className;
}
public function getSqls(string $className, string $field, Person $from, Person $to): array

View File

@@ -23,7 +23,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
public function supports(string $className, string $field): bool
{
return $className === Person\PersonCenterHistory::class;
return Person\PersonCenterHistory::class === $className;
}
public function getSqls(string $className, string $field, Person $from, Person $to): array
@@ -37,7 +37,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
$centerHistoriesA = $this->centerHistoryRepository->findBy(['person' => $from]);
foreach ($centerHistoriesA as $ch) {
if ($oldestDateA === null || ($ch->getStartDate() < $oldestDateA)) {
if (null === $oldestDateA || ($ch->getStartDate() < $oldestDateA)) {
$oldestDateA = $ch->getStartDate();
$oldestCenterHistoryA = $ch;
}
@@ -45,7 +45,7 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
$centerHistoriesB = $this->centerHistoryRepository->findBy(['person' => $to]);
foreach ($centerHistoriesB as $ch) {
if ($oldestDateB === null || ($ch->getStartDate() < $oldestDateB)) {
if (null === $oldestDateB || ($ch->getStartDate() < $oldestDateB)) {
$oldestDateB = $ch->getStartDate();
$oldestCenterHistoryB = $ch;
}
@@ -58,7 +58,6 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
$sqlStatements = [$sqlDelete];
if ((null !== $oldestDateA && null !== $oldestDateB) && $oldestDateA <= $oldestDateB) {
$sqlInsert = sprintf(<<<'SQL'
UPDATE chill_person_person_center_history SET startDate = '%s' WHERE id = %d;
SQL, $oldestDateA->format('Y-m-d'), $oldestCenterHistoryB->getId());
@@ -67,7 +66,5 @@ class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
}
return $sqlStatements;
}
}

View File

@@ -19,7 +19,7 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
{
public function supports(string $className, string $field): bool
{
return $className === HouseholdMember::class;
return HouseholdMember::class === $className;
}
public function getSqls(string $className, string $field, Person $from, Person $to): array
@@ -43,5 +43,4 @@ class PersonMoveHouseholdHandler implements PersonMoveSqlHandlerInterface
return [$sqlInsert, $deleteSql];
}
}

View File

@@ -19,7 +19,7 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
{
public function supports(string $className, string $field): bool
{
return $className === Relationship::class;
return Relationship::class === $className;
}
public function getSqls(string $className, string $field, Person $from, Person $to): array
@@ -38,8 +38,8 @@ class PersonMoveRelationHandler implements PersonMoveSqlHandlerInterface
SQL, $from->getId(), $from->getId(), $to->getId(), $from->getId(), $from->getId(), $to->getId());
$deleteSql = [
sprintf("DELETE FROM chill_person_relationships WHERE fromperson_id = %d", $from->getId()),
sprintf("DELETE FROM chill_person_relationships WHERE toperson_id = %d", $from->getId())
sprintf('DELETE FROM chill_person_relationships WHERE fromperson_id = %d', $from->getId()),
sprintf('DELETE FROM chill_person_relationships WHERE toperson_id = %d', $from->getId()),
];
return [$insertSql, ...$deleteSql];

View File

@@ -13,8 +13,6 @@ namespace Chill\PersonBundle\Actions\Remove;
use Chill\PersonBundle\Actions\ActionEvent;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relationship;
@@ -22,10 +20,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use function array_merge;
use function implode;
use function in_array;
/**
* Move or delete entities associated to a person to a new one, and delete the
* old person. The data associated to a person (birthdate, name, ...) are left
@@ -36,7 +30,7 @@ use function in_array;
class PersonMove
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly EntityManagerInterface $em,
private readonly PersonMoveManager $personMoveManager,
private readonly EventDispatcherInterface $eventDispatcher
) {}
@@ -68,7 +62,7 @@ class PersonMove
public function getSQL(Person $from, Person $to, array $deleteEntities = [])
{
$sqls = [];
$toDelete = array_merge($deleteEntities, $this->getDeleteEntities());
$toDelete = \array_merge($deleteEntities, $this->getDeleteEntities());
foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) {
if ($metadata->isMappedSuperclass) {
@@ -76,18 +70,17 @@ class PersonMove
}
foreach ($metadata->getAssociationMappings() as $field => $mapping) {
if ($this->personMoveManager->hasHandler($metadata->getName(), $field)) {
$sqls = array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
$sqls = \array_merge($sqls, $this->personMoveManager->getSqls($metadata->getName(), $field, $from, $to));
continue;
}
if (in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
if (\in_array($mapping['sourceEntity'], $this->getIgnoredEntities(), true)) {
continue;
}
if (Person::class === $mapping['targetEntity'] and true === $mapping['isOwningSide']) {
if (in_array($mapping['sourceEntity'], $toDelete, true)) {
if (\in_array($mapping['sourceEntity'], $toDelete, true)) {
$sql = $this->createDeleteSQL($metadata, $from, $field);
$event = new ActionEvent(
$from->getId(),
@@ -96,9 +89,9 @@ class PersonMove
['to' => $to->getId(), 'original_action' => 'move']
);
$this->eventDispatcher->dispatch($event, ActionEvent::DELETE);
$sqls = array_merge($sqls, $event->getPreSql(), [$event->getSqlStatement()], $event->getPostSql());
$sqls = \array_merge($sqls, $event->getPreSql(), [$event->getSqlStatement()], $event->getPostSql());
} else {
$sqls = array_merge($sqls, $this->createMoveSQLs($metadata, $from, $to, $field));
$sqls = \array_merge($sqls, $this->createMoveSQLs($metadata, $from, $to, $field));
}
}
}
@@ -133,7 +126,7 @@ class PersonMove
return sprintf(
'DELETE FROM %s WHERE %s;',
$this->getTableName($metadata),
implode(' AND ', $conditions)
\implode(' AND ', $conditions)
);
}
@@ -148,11 +141,11 @@ class PersonMove
if (array_key_exists('joinTable', $mapping)) {
// there is a join_table: we have to find conflict
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'] . '.' : '')
. $mapping['joinTable']['name'];
$tableName = (null !== ($mapping['joinTable']['schema'] ?? null) ? $mapping['joinTable']['schema'].'.' : '')
.$mapping['joinTable']['name'];
$sqlInsert = sprintf(
"INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING;",
'INSERT INTO %s (%s, %s) SELECT %d, %s FROM %s WHERE %s = %d ON CONFLICT DO NOTHING;',
$tableName,
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
$mapping['joinTable']['joinColumns'][0]['name'], // something_else_id
@@ -164,7 +157,7 @@ class PersonMove
);
$deleteSql = sprintf(
"DELETE FROM %s WHERE %s = %d;",
'DELETE FROM %s WHERE %s = %d;',
$tableName,
$mapping['joinTable']['inverseJoinColumns'][0]['name'], // person_id
$from->getId()
@@ -179,9 +172,8 @@ class PersonMove
}
return [
$sqlInsert, $deleteSql
$sqlInsert, $deleteSql,
];
}
if (array_key_exists('joinColumns', $mapping)) {
$tableName = $this->getTableName($metadata);
@@ -197,8 +189,8 @@ class PersonMove
return [sprintf(
'UPDATE %s SET %s WHERE %s;',
$tableName,
implode(' ', $sets),
implode(' AND ', $conditions)
\implode(' ', $sets),
\implode(' AND ', $conditions)
)];
}
@@ -210,7 +202,7 @@ class PersonMove
{
return [
AccompanyingPeriod\AccompanyingPeriodWork::class,
Relationship::class
Relationship::class,
];
}
@@ -230,6 +222,6 @@ class PersonMove
{
return empty($metadata->getSchemaName()) ?
$metadata->getTableName() :
$metadata->getSchemaName() . '.' . $metadata->getTableName();
$metadata->getSchemaName().'.'.$metadata->getTableName();
}
}

View File

@@ -17,14 +17,13 @@ class PersonMoveManager
{
public function __construct(
/**
* @var iterable<PersonMoveSqlHandlerInterface>
* @var iterable<PersonMoveSqlHandlerInterface>
*/
private readonly iterable $handlers,
) {}
/**
* @param class-string $className
* @return bool
*/
public function hasHandler(string $className, string $field): bool
{
@@ -39,6 +38,7 @@ class PersonMoveManager
/**
* @param class-string $className
*
* @return array<string>
*/
public function getSqls(string $className, string $field, Person $from, Person $to): array
@@ -48,7 +48,7 @@ class PersonMoveManager
return $handler->getSqls($className, $field, $from, $to);
}
}
return [];
}
}

View File

@@ -22,6 +22,7 @@ interface PersonMoveSqlHandlerInterface
/**
* @param class-string $className
*
* @return array<string>
*/
public function getSqls(string $className, string $field, Person $from, Person $to): array;

View File

@@ -14,11 +14,8 @@ namespace Chill\PersonBundle\CRUD\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\QueryBuilder;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function array_merge;
/**
* Class EntityPersonCRUDController
@@ -68,25 +65,21 @@ class EntityPersonCRUDController extends CRUDController
}
/**
* @param mixed $entity
*
* @throws Exception
* @throws \Exception
*/
protected function generateTemplateParameter(string $action, $entity, Request $request, array $defaultTemplateParameters = []): array
{
$person = $this->getPerson($request);
if (null === $person) {
throw new Exception('the `person_id` parameter is not set in the query. '
. 'You should set it or override the current method to allow another '
. 'behaviour: ' . __METHOD__);
throw new \Exception('the `person_id` parameter is not set in the query. You should set it or override the current method to allow another behaviour: '.__METHOD__);
}
return parent::generateTemplateParameter(
$action,
$entity,
$request,
array_merge(['person' => $person], $defaultTemplateParameters)
\array_merge(['person' => $person], $defaultTemplateParameters)
);
}
@@ -122,7 +115,6 @@ class EntityPersonCRUDController extends CRUDController
/**
* @param string $action
* @param mixed $entity
*
* @return string
*/
@@ -142,25 +134,22 @@ class EntityPersonCRUDController extends CRUDController
};
}
/**
* @param mixed $entity
*/
protected function onBeforeRedirectAfterSubmission(string $action, $entity, \Symfony\Component\Form\FormInterface $form, Request $request): ?Response
{
$next = $request->request->get('submit', 'save-and-close');
return match ($next) {
'save-and-close' => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_index', [
'save-and-close' => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_index', [
'person_id' => $this->getPerson($request)->getId(),
]),
'save-and-new' => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_new', [
'save-and-new' => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_new', [
'person_id' => $this->getPerson($request)->getId(),
]),
'new' => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', [
'new' => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', [
'id' => $entity->getId(),
'person_id' => $this->getPerson($request)->getId(),
]),
default => $this->redirectToRoute('chill_crud_' . $this->getCrudName() . '_view', [
default => $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', [
'id' => $entity->getId(),
'person_id' => $this->getPerson($request)->getId(),
]),

View File

@@ -11,10 +11,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\CRUD\Controller;
use BadMethodCallException;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Chill\PersonBundle\Entity\Person;
use LogicException;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -24,7 +22,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController
{
protected function generateRedirectOnCreateRoute($action, Request $request, $entity): string
{
throw new BadMethodCallException('Not implemented yet.');
throw new \BadMethodCallException('Not implemented yet.');
}
protected function getEntity($action, $id, Request $request): ?object
@@ -54,9 +52,7 @@ class OneToOneEntityPersonCRUDController extends CRUDController
'new' => '@ChillPerson/CRUD/new.html.twig',
'edit' => '@ChillPerson/CRUD/edit.html.twig',
'index' => '@ChillPerson/CRUD/index.html.twig',
default => throw new LogicException("the view for action {$action} is not "
. 'defined. You should override ' . __METHOD__ . ' to add this '
. 'action'),
default => throw new \LogicException("the view for action {$action} is not ".'defined. You should override '.__METHOD__.' to add this action'),
};
}

View File

@@ -21,8 +21,6 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function ctype_digit;
final class ChillPersonMoveCommand extends Command
{
public function __construct(
@@ -41,11 +39,11 @@ final class ChillPersonMoveCommand extends Command
];
foreach ($deleteEntities as $key => $de) {
$ctxt['delete_entity_' . $key] = $de;
$ctxt['delete_entity_'.$key] = $de;
}
foreach ($sqls as $key => $sql) {
$ctxt['sql_' . $key] = $sql;
$ctxt['sql_'.$key] = $sql;
}
return $ctxt;
@@ -100,6 +98,7 @@ final class ChillPersonMoveCommand extends Command
$this->chillLogger->notice('Move a person from command line succeeded', $ctxt);
}
return 0;
}
@@ -117,9 +116,8 @@ final class ChillPersonMoveCommand extends Command
}
$id = $input->getOption($name);
if (ctype_digit((string) $id) === false) {
throw new RuntimeException("The id in \"{$name}\" field does not contains "
. "only digits: {$id}");
if (false === \ctype_digit((string) $id)) {
throw new RuntimeException("The id in \"{$name}\" field does not contains only digits: {$id}");
}
}
}

View File

@@ -11,17 +11,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Command;
use Chill\PersonBundle\Service\Import\ChillImporter;
use Chill\PersonBundle\Service\Import\SocialWorkMetadataInterface;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use League\Csv\Reader;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
final class ImportSocialWorkMetadata extends Command
{
@@ -36,10 +32,10 @@ final class ImportSocialWorkMetadata extends Command
protected function configure()
{
$description = 'Imports a structured table containing social issues, social actions, objectives, results and evaluations.';
$help = 'File to csv format, no headers, semi-colon as delimiter, datas sorted by alphabetical order, column after column.'. PHP_EOL
. 'Columns are: social issues parent, social issues child, social actions parent, social actions child, goals, results, evaluations.'. PHP_EOL
. PHP_EOL
. 'See social_work_metadata.csv as example.'. PHP_EOL;
$help = 'File to csv format, no headers, semi-colon as delimiter, datas sorted by alphabetical order, column after column.'.PHP_EOL
.'Columns are: social issues parent, social issues child, social actions parent, social actions child, goals, results, evaluations.'.PHP_EOL
.PHP_EOL
.'See social_work_metadata.csv as example.'.PHP_EOL;
$this
->setName('chill:person:import-socialwork')
@@ -55,8 +51,8 @@ final class ImportSocialWorkMetadata extends Command
try {
$csv = Reader::createFromPath($filepath);
} catch (Throwable $e) {
throw new Exception('Error while loading CSV.', 0, $e);
} catch (\Throwable $e) {
throw new \Exception('Error while loading CSV.', 0, $e);
}
$csv->setDelimiter(';');

View File

@@ -12,8 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Command;
use Chill\PersonBundle\Service\AccompanyingPeriod\OldDraftAccompanyingPeriodRemoverInterface;
use DateInterval;
use Exception;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -36,21 +34,21 @@ class RemoveOldDraftAccompanyingPeriodCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->logger->info('[' . $this->getName() . '] started', [
$this->logger->info('['.$this->getName().'] started', [
'interval' => $input->getArgument('interval'),
]);
try {
$interval = new DateInterval($input->getArgument('interval'));
} catch (Exception $e) {
$this->logger->error('[' . $this->getName() . '] bad interval');
$interval = new \DateInterval($input->getArgument('interval'));
} catch (\Exception $e) {
$this->logger->error('['.$this->getName().'] bad interval');
throw $e;
}
$this->remover->remove($interval);
$this->logger->info('[' . $this->getName() . '] end of command');
$this->logger->info('['.$this->getName().'] end of command');
return 0;
}

View File

@@ -40,11 +40,11 @@ class ConfigPersonAltNamesHelper
$cur = reset($labels);
while ($cur) {
if (key($labels) === 'lang') {
if ('lang' === key($labels)) {
$lang = current($labels);
}
if (key($labels) === 'label') {
if ('label' === key($labels)) {
$label = current($labels);
}

View File

@@ -29,8 +29,6 @@ use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateInterval;
use DateTimeImmutable;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -43,11 +41,8 @@ use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Registry;
use function array_values;
use function count;
final class AccompanyingCourseApiController extends ApiController
{
@@ -70,7 +65,7 @@ final class AccompanyingCourseApiController extends ApiController
// throw new BadRequestException('It is not possible to confirm this period');
$errors = $this->validator->validate($accompanyingPeriod, null, [$accompanyingPeriod::STEP_CONFIRMED]);
if (count($errors) > 0) {
if (\count($errors) > 0) {
return $this->json($errors, 422);
}
}
@@ -96,7 +91,7 @@ final class AccompanyingCourseApiController extends ApiController
throw new AccessDeniedException();
}
$since = (new DateTimeImmutable('now'))->sub(new DateInterval('P15D'));
$since = (new \DateTimeImmutable('now'))->sub(new \DateInterval('P15D'));
$total = $this->accompanyingPeriodRepository->countByRecentUserHistory($user, $since);
@@ -146,7 +141,7 @@ final class AccompanyingCourseApiController extends ApiController
fn (AccompanyingPeriod $period) => $this->isGranted(AccompanyingPeriodVoter::SEE, $period)
);
return $this->json(array_values($accompanyingPeriodsChecked), Response::HTTP_OK, [], ['groups' => ['read']]);
return $this->json(\array_values($accompanyingPeriodsChecked), Response::HTTP_OK, [], ['groups' => ['read']]);
}
public function participationApi($id, Request $request, $_format)
@@ -284,11 +279,12 @@ final class AccompanyingCourseApiController extends ApiController
/**
* @Route("/api/1.0/person/accompanying-course/{id}/confidential.json", name="chill_api_person_accompanying_period_confidential")
*
* @ParamConverter("accompanyingCourse", options={"id": "id"})
*/
public function toggleConfidentialApi(AccompanyingPeriod $accompanyingCourse, mixed $id, Request $request)
{
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::TOGGLE_CONFIDENTIAL, $accompanyingCourse);
$accompanyingCourse->setConfidential(!$accompanyingCourse->isConfidential());
@@ -301,14 +297,15 @@ final class AccompanyingCourseApiController extends ApiController
/**
* @Route("/api/1.0/person/accompanying-course/{id}/intensity.json", name="chill_api_person_accompanying_period_intensity")
*
* @ParamConverter("accompanyingCourse", options={"id": "id"})
*/
public function toggleIntensityApi(AccompanyingPeriod $accompanyingCourse, Request $request)
{
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::TOGGLE_INTENSITY, $accompanyingCourse);
$status = $accompanyingCourse->getIntensity() === 'regular' ? 'occasional' : 'regular';
$status = 'regular' === $accompanyingCourse->getIntensity() ? 'occasional' : 'regular';
$accompanyingCourse->setIntensity($status);
$this->getDoctrine()->getManager()->flush();
}

View File

@@ -16,7 +16,6 @@ use Chill\PersonBundle\Form\AccompanyingCourseCommentType;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use LogicException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\FormType;
@@ -26,7 +25,6 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -38,6 +36,7 @@ class AccompanyingCourseCommentController extends AbstractController
* Page of comments in Accompanying Course section.
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response
@@ -66,13 +65,13 @@ class AccompanyingCourseCommentController extends AbstractController
}
if (!isset($editForm)) {
throw new NotFoundHttpException('comment with id ' . $request->query->getInt('edit') . ' is not found');
throw new NotFoundHttpException('comment with id '.$request->query->getInt('edit').' is not found');
}
if (isset($commentEdited)) {
$this->denyAccessUnlessGranted(AccompanyingPeriodCommentVoter::EDIT, $commentEdited);
} else {
throw new LogicException('at this step, commentEdited should be set');
throw new \LogicException('at this step, commentEdited should be set');
}
$editForm->handleRequest($request);

View File

@@ -19,7 +19,6 @@ use Chill\PersonBundle\Form\AccompanyingCourseType;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -33,9 +32,6 @@ use Symfony\Component\Workflow\Registry;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_slice;
use function is_array;
/**
* Class AccompanyingCourseController.
*/
@@ -45,6 +41,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
/**
* @Route("/{_locale}/parcours/{accompanying_period_id}/close", name="chill_person_accompanying_course_close")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function closeAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response
@@ -76,7 +73,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
$this->addFlash('error', $this->translator->trans('It is not possible to close this course'));
foreach ($errors as $e) {
/** @var ConstraintViolationInterface $e */
/* @var ConstraintViolationInterface $e */
$this->addFlash('error', $e->getMessage());
}
}
@@ -91,6 +88,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
* Delete page of Accompanying Course section.
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/delete", name="chill_person_accompanying_course_delete")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function deleteAction(Request $request, AccompanyingPeriod $accompanyingCourse)
@@ -108,7 +106,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
if (Request::METHOD_DELETE === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
@@ -147,6 +145,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
* the page edit all blocks managed by vuejs component
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/edit", name="chill_person_accompanying_course_edit")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function editAction(AccompanyingPeriod $accompanyingCourse): Response
@@ -164,6 +163,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
* the page show anti chronologic history with all actions, title of page is 'Accompanying Course History'
*
* @Route("/{_locale}/parcours/{accompanying_period_id}/history", name="chill_person_accompanying_course_history")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function historyAction(AccompanyingPeriod $accompanyingCourse): Response
@@ -179,6 +179,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
* Homepage of Accompanying Course section.
*
* @Route("/{_locale}/parcours/{accompanying_period_id}", name="chill_person_accompanying_course_index")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function indexAction(AccompanyingPeriod $accompanyingCourse): Response
@@ -200,7 +201,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
['date' => 'DESC', 'id' => 'DESC'],
);
$activities = array_slice($activities, 0, 3);
$activities = \array_slice($activities, 0, 3);
$works = $this->workRepository->findByAccompanyingPeriod(
$accompanyingCourse,
@@ -228,7 +229,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
if ($request->query->has('person_id')) {
$personIds = $request->query->get('person_id');
if (false === is_array($personIds)) {
if (false === \is_array($personIds)) {
throw new BadRequestHttpException('person_id parameter should be an array');
}
@@ -290,6 +291,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
/**
* @Route("/{_locale}/parcours/{accompanying_period_id}/open", name="chill_person_accompanying_course_reopen")
*
* @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"})
*/
public function reOpenAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response

View File

@@ -15,8 +15,6 @@ use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Serializer\Model\Collection;
use Chill\MainBundle\Serializer\Model\Counter;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use DateInterval;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@@ -30,10 +28,10 @@ class AccompanyingCourseWorkApiController extends ApiController
*/
public function myWorksNearEndDate(Request $request): JsonResponse
{
$since = (new DateTimeImmutable('now'))
->sub(new DateInterval('P' . $request->query->getInt('since', 15) . 'D'));
$until = (new DateTimeImmutable('now'))
->add(new DateInterval('P' . $request->query->getInt('since', 15) . 'D'));
$since = (new \DateTimeImmutable('now'))
->sub(new \DateInterval('P'.$request->query->getInt('since', 15).'D'));
$until = (new \DateTimeImmutable('now'))
->add(new \DateInterval('P'.$request->query->getInt('since', 15).'D'));
$total = $this->accompanyingPeriodWorkRepository
->countNearEndDateByUser($this->getUser(), $since, $until);

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
@@ -25,7 +24,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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;
@@ -56,11 +54,11 @@ final class AccompanyingCourseWorkController extends AbstractController
{
$this->denyAccessUnlessGranted(AccompanyingPeriodWorkVoter::CREATE, $period);
if ($period->getSocialIssues()->count() === 0) {
if (0 === $period->getSocialIssues()->count()) {
$this->addFlash(
'error',
$this->trans->trans(
'accompanying_work.You must add at least ' .
'accompanying_work.You must add at least '.
'one social issue on accompanying period'
)
);
@@ -93,7 +91,7 @@ final class AccompanyingCourseWorkController extends AbstractController
$form = $this->createDeleteForm($work->getId());
if ($request->getMethod() === Request::METHOD_DELETE) {
if (Request::METHOD_DELETE === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
@@ -161,7 +159,7 @@ final class AccompanyingCourseWorkController extends AbstractController
'types' => $filter->hasEntityChoice('typesFilter') ? $filter->getEntityChoiceData('typesFilter') : [],
'before' => $filter->getDateRangeData('dateFilter')['to'],
'after' => $filter->getDateRangeData('dateFilter')['from'],
'user' => $filter->getUserPickerData('userFilter')
'user' => $filter->getUserPickerData('userFilter'),
];
$totalItems = $this->workRepository->countByAccompanyingPeriod($period);
@@ -178,7 +176,7 @@ final class AccompanyingCourseWorkController extends AbstractController
'accompanyingCourse' => $period,
'works' => $works,
'paginator' => $paginator,
'filter' => $filter
'filter' => $filter,
]);
}
@@ -226,7 +224,7 @@ final class AccompanyingCourseWorkController extends AbstractController
if (1 < count($types)) {
$filterBuilder
->addEntityChoice('typesFilter', 'accompanying_course_work.types_filter', \Chill\PersonBundle\Entity\SocialWork\SocialAction::class, $types, [
'choice_label' => fn (SocialAction $sa) => $this->translatableStringHelper->localize($sa->getTitle())
'choice_label' => fn (SocialAction $sa) => $this->translatableStringHelper->localize($sa->getTitle()),
]);
}

View File

@@ -37,7 +37,7 @@ class AccompanyingCourseWorkEvaluationDocumentController extends AbstractControl
$this->security->isGranted(AccompanyingPeriodWorkVoter::UPDATE, $work) ?
'chill_person_accompanying_period_work_edit' : 'chill_person_accompanying_period_work_show',
[
'id' => $work->getId()
'id' => $work->getId(),
]
);
}

View File

@@ -18,7 +18,6 @@ use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTime;
use Doctrine\DBAL\Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -27,9 +26,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function array_filter;
use function count;
/**
* Class AccompanyingPeriodController.
@@ -57,6 +54,7 @@ class AccompanyingPeriodController extends AbstractController
/**
* @throws \Exception
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period/close", name="chill_person_accompanying_period_close")
*/
public function closeAction(int $person_id, Request $request): Response
@@ -65,7 +63,7 @@ class AccompanyingPeriodController extends AbstractController
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
if ($person->isOpen() === false) {
if (false === $person->isOpen()) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
->trans(
@@ -85,14 +83,14 @@ class AccompanyingPeriodController extends AbstractController
'center' => $person->getCenter(),
]);
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$person->close($current);
$errors = $this->_validatePerson($person);
if (count($errors) === 0) {
if (0 === \count($errors)) {
$this->get('session')->getFlashBag()
->add('success', $this->get('translator')
->trans('An accompanying period has been closed.', [
@@ -113,7 +111,7 @@ class AccompanyingPeriodController extends AbstractController
$this->get('session')->getFlashBag()
->add('info', $error->getMessage());
}
} else { //if form is not valid
} else { // if form is not valid
$this->get('session')->getFlashBag()
->add(
'error',
@@ -148,11 +146,11 @@ class AccompanyingPeriodController extends AbstractController
'You are not allowed to update this person'
);
$accompanyingPeriod = new AccompanyingPeriod(new DateTime('now'));
$accompanyingPeriod->setClosingDate(new DateTime('now'));
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime('now'));
$accompanyingPeriod->setClosingDate(new \DateTime('now'));
$accompanyingPeriod->addPerson($person);
//or $person->addAccompanyingPeriod($accompanyingPeriod);
// or $person->addAccompanyingPeriod($accompanyingPeriod);
$form = $this->createForm(
AccompanyingPeriodType::class,
@@ -163,14 +161,14 @@ class AccompanyingPeriodController extends AbstractController
]
);
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if (
$form->isValid(['Default', 'closed'])
&& count($errors) === 0
&& 0 === \count($errors)
) {
$em = $this->getDoctrine()->getManager();
$em->persist($accompanyingPeriod);
@@ -203,6 +201,7 @@ class AccompanyingPeriodController extends AbstractController
/**
* @ParamConverter("person", options={"id": "person_id"})
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period", name="chill_person_accompanying_period_list")
*/
public function listAction(Person $person): Response
@@ -216,12 +215,12 @@ class AccompanyingPeriodController extends AbstractController
$this->eventDispatcher->dispatch($event, PrivacyEvent::PERSON_PRIVACY_EVENT);
$accompanyingPeriods = $this->accompanyingPeriodACLAwareRepository
->findByPerson($person, AccompanyingPeriodVoter::SEE, ["openingDate" => "DESC", "id" => "DESC"]);
->findByPerson($person, AccompanyingPeriodVoter::SEE, ['openingDate' => 'DESC', 'id' => 'DESC']);
//usort($accompanyingPeriodsRaw, static fn ($a, $b) => $b->getOpeningDate() <=> $a->getOpeningDate());
// usort($accompanyingPeriodsRaw, static fn ($a, $b) => $b->getOpeningDate() <=> $a->getOpeningDate());
// filter visible or not visible
//$accompanyingPeriods = array_filter($accompanyingPeriodsRaw, fn (AccompanyingPeriod $ap) => $this->isGranted(AccompanyingPeriodVoter::SEE, $ap));
// $accompanyingPeriods = array_filter($accompanyingPeriodsRaw, fn (AccompanyingPeriod $ap) => $this->isGranted(AccompanyingPeriodVoter::SEE, $ap));
return $this->render('@ChillPerson/AccompanyingPeriod/list.html.twig', [
'accompanying_periods' => $accompanyingPeriods,
@@ -242,7 +241,7 @@ class AccompanyingPeriodController extends AbstractController
'You are not allowed to update this person'
);
//in case the person is already open
// in case the person is already open
if ($person->isOpen()) {
$this->get('session')->getFlashBag()
->add('error', $this->get('translator')
@@ -256,7 +255,7 @@ class AccompanyingPeriodController extends AbstractController
]);
}
$accompanyingPeriod = new AccompanyingPeriod(new DateTime());
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime());
$form = $this->createForm(
AccompanyingPeriodType::class,
@@ -267,7 +266,7 @@ class AccompanyingPeriodController extends AbstractController
]
);
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
@@ -275,7 +274,7 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
if (count($errors) <= 0) {
if (\count($errors) <= 0) {
$this->get('session')->getFlashBag()
->add('success', $this->get('translator')
->trans(
@@ -323,9 +322,9 @@ class AccompanyingPeriodController extends AbstractController
$person = $this->_getPerson($person_id);
/** @var AccompanyingPeriod $period */
$period = array_filter(
$period = \array_filter(
$person->getAccompanyingPeriods(),
static fn (AccompanyingPeriod $p) => $p->getId() === ($period_id)
static fn (AccompanyingPeriod $p) => $p->getId() === $period_id
)[0] ?? null;
if (null === $period) {
@@ -364,6 +363,7 @@ class AccompanyingPeriodController extends AbstractController
/**
* @throws Exception
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person_id}/accompanying-period/{period_id}/update", name="chill_person_accompanying_period_update")
*/
public function updateAction(int $person_id, int $period_id, Request $request): Response
@@ -374,7 +374,7 @@ class AccompanyingPeriodController extends AbstractController
$accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($period_id);
if (null === $accompanyingPeriod) {
throw $this->createNotFoundException('Period with id ' . $period_id . ' is not found');
throw $this->createNotFoundException('Period with id '.$period_id.' is not found');
}
/** @var Person $person */
@@ -382,7 +382,7 @@ class AccompanyingPeriodController extends AbstractController
// CHECK
if (!$accompanyingPeriod->containsPerson($person)) {
throw new Exception('Accompanying period ' . $period_id . ' does not contain person ' . $person_id);
throw new Exception('Accompanying period '.$period_id.' does not contain person '.$person_id);
}
$this->denyAccessUnlessGranted(
@@ -400,14 +400,14 @@ class AccompanyingPeriodController extends AbstractController
]
);
if ($request->getMethod() === 'POST') {
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if (
$form->isValid(['Default', 'closed'])
&& count($errors) === 0
&& 0 === \count($errors)
) {
$em->flush();

View File

@@ -28,7 +28,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
class AccompanyingPeriodRegulationListController
{

View File

@@ -27,9 +27,6 @@ use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use function count;
use function in_array;
class AccompanyingPeriodWorkEvaluationApiController
{
public function __construct(private readonly AccompanyingPeriodWorkEvaluationRepository $accompanyingPeriodWorkEvaluationRepository, private readonly DocGeneratorTemplateRepository $docGeneratorTemplateRepository, private readonly SerializerInterface $serializer, private readonly PaginatorFactory $paginatorFactory, private readonly Security $security) {}
@@ -51,12 +48,12 @@ class AccompanyingPeriodWorkEvaluationApiController
static function (DocGeneratorTemplate $t) use ($evaluation) {
$ids = $t->getOptions()['evaluations'] ?? [];
return in_array($evaluation->getId(), $ids, true);
return \in_array($evaluation->getId(), $ids, true);
}
);
$paginator = $this->paginatorFactory->create(count($evaluations));
$paginator->setItemsPerPage(count($evaluations));
$paginator = $this->paginatorFactory->create(\count($evaluations));
$paginator->setItemsPerPage(\count($evaluations));
return new JsonResponse($this->serializer->serialize(
new Collection(array_values($evaluations), $paginator),

View File

@@ -53,6 +53,7 @@ class AdminController extends AbstractController
/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/person_redirect_to_main", name="chill_person_admin_redirect_to_admin_index", options={null})
*/
public function redirectToAdminIndexAction()

View File

@@ -52,7 +52,7 @@ class ClosingMotiveController extends CRUDController
*/
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
{
/** @var \Doctrine\ORM\QueryBuilder $query */
/* @var \Doctrine\ORM\QueryBuilder $query */
return $query->orderBy('e.ordering', 'ASC');
}
}

View File

@@ -22,16 +22,12 @@ use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use Chill\PersonBundle\Repository\Household\HouseholdACLAwareRepositoryInterface;
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use DateTimeImmutable;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use function array_filter;
use function array_values;
class HouseholdApiController extends ApiController
{
@@ -79,9 +75,9 @@ class HouseholdApiController extends ApiController
$household->addAddress($address);
foreach ($household->getMembersOnRange(
DateTimeImmutable::createFromMutable($address->getValidFrom()),
\DateTimeImmutable::createFromMutable($address->getValidFrom()),
null === $address->getValidTo() ? null :
DateTimeImmutable::createFromMutable($address->getValidTo())
\DateTimeImmutable::createFromMutable($address->getValidTo())
) as $member) {
/** @var HouseholdMember $member */
$event = new PersonAddressMoveEvent($member->getPerson());
@@ -114,6 +110,7 @@ class HouseholdApiController extends ApiController
* "_format": "json"
* }
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function suggestAddressByHousehold(Household $household, string $_format)
@@ -146,11 +143,11 @@ class HouseholdApiController extends ApiController
$actual = $household->getCurrentAddress();
if (null !== $actual) {
$addresses = array_filter($addresses, static fn ($a) => $a !== $actual);
$addresses = \array_filter($addresses, static fn ($a) => $a !== $actual);
}
return $this->json(
array_values($addresses),
\array_values($addresses),
Response::HTTP_OK,
[],
['groups' => ['read']]
@@ -186,7 +183,7 @@ class HouseholdApiController extends ApiController
}
if (null !== $currentHouseholdPerson) {
$count = $count - 1;
--$count;
$paginator = $this->getPaginatorFactory()->create($count);
}
}

View File

@@ -18,7 +18,6 @@ use Chill\PersonBundle\Form\HouseholdCompositionType;
use Chill\PersonBundle\Repository\Household\HouseholdCompositionRepository;
use Chill\PersonBundle\Repository\Household\HouseholdRepository;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@@ -31,7 +30,6 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class HouseholdCompositionController extends AbstractController
@@ -71,7 +69,7 @@ class HouseholdCompositionController extends AbstractController
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
if (Request::METHOD_DELETE === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
@@ -135,13 +133,13 @@ class HouseholdCompositionController extends AbstractController
if ($isEdit) {
$householdCompositions = $household->getCompositions()->filter(static fn (HouseholdComposition $composition) => $composition->getId() === $request->query->getInt('edit'));
if ($householdCompositions->count() !== 1) {
if (1 !== $householdCompositions->count()) {
throw new BadRequestHttpException('could not find the composition with this id associated to the household');
}
$householdComposition = $householdCompositions->first();
} else {
$householdComposition = (new HouseholdComposition())
->setStartDate(new DateTimeImmutable());
->setStartDate(new \DateTimeImmutable());
}
$form = $this->formFactory->create(HouseholdCompositionType::class, $householdComposition);

View File

@@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\Request;
use UnexpectedValueException;
class HouseholdCompositionTypeApiController extends ApiController
{
@@ -25,7 +24,7 @@ class HouseholdCompositionTypeApiController extends ApiController
{
match ($action) {
'_index' => $query->andWhere($query->expr()->eq('e.active', "'TRUE'")),
default => throw new UnexpectedValueException('unexepcted action: ' . $action),
default => throw new \UnexpectedValueException('unexepcted action: '.$action),
};
}
}

View File

@@ -29,9 +29,6 @@ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
/**
* @Route("/{_locale}/person/household")
*/
@@ -45,6 +42,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_accompanying_period",
* methods={"GET", "HEAD"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function accompanyingPeriod(Request $request, Household $household)
@@ -77,7 +75,7 @@ class HouseholdController extends AbstractController
}
$id = $accompanyingPeriod->getId();
if (!array_key_exists($id, $accompanyingPeriodsOld) && !array_key_exists($id, $accompanyingPeriods)) {
if (!\array_key_exists($id, $accompanyingPeriodsOld) && !\array_key_exists($id, $accompanyingPeriods)) {
$accompanyingPeriodsOld[$id] = $accompanyingPeriod;
}
}
@@ -99,6 +97,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_address_edit",
* methods={"GET", "HEAD", "POST"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function addressEdit(Request $request, Household $household)
@@ -125,17 +124,18 @@ class HouseholdController extends AbstractController
* name="chill_person_household_addresses",
* methods={"GET", "HEAD"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function addresses(Request $request, Household $household)
{
// TODO ACL
//TODO put these lines into a validator constraint on household->getAddress
// TODO put these lines into a validator constraint on household->getAddress
$addresses = $household->getAddresses();
$cond = true;
for ($i = 0; count($addresses) - 1 > $i; ++$i) {
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
if ($addresses[$i]->getValidFrom() !== $addresses[$i + 1]->getValidTo()) {
$cond = false;
}
@@ -155,6 +155,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_address_move",
* methods={"GET", "HEAD", "POST"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function addressMove(Request $request, Household $household)
@@ -175,6 +176,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_address_valid_from_edit",
* methods={"GET", "HEAD", "POST"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function addressValidFromEdit(Request $request, Household $household)
@@ -231,6 +233,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_members_metadata_edit",
* methods={"GET", "POST"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function editHouseholdMetadata(Request $request, Household $household)
@@ -262,6 +265,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_relationship",
* methods={"GET", "HEAD"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function showRelationship(Request $request, Household $household)
@@ -287,6 +291,7 @@ class HouseholdController extends AbstractController
* name="chill_person_household_summary",
* methods={"GET", "HEAD"}
* )
*
* @ParamConverter("household", options={"id": "household_id"})
*/
public function summary(Request $request, Household $household)

View File

@@ -28,8 +28,6 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Exception;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
class HouseholdMemberController extends ApiController
{
public function __construct(private readonly UrlGeneratorInterface $generator, private readonly TranslatorInterface $translator, private readonly AccompanyingPeriodRepository $periodRepository) {}
@@ -90,9 +88,8 @@ class HouseholdMemberController extends ApiController
if ($request->query->has('persons')) {
$ids = $request->query->get('persons', []);
if (0 === count($ids)) {
throw new BadRequestHttpException('parameters persons in query ' .
'is not an array or empty');
if (0 === \count($ids)) {
throw new BadRequestHttpException('parameters persons in query is not an array or empty');
}
$persons = $em->getRepository(Person::class)
@@ -181,7 +178,7 @@ class HouseholdMemberController extends ApiController
//
$errors = $editor->validate();
if (count($errors) > 0) {
if (\count($errors) > 0) {
return $this->json($errors, 422);
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use DateTime;
use Symfony\Component\HttpFoundation\Request;
class OpeningApiController extends ApiController
@@ -21,6 +20,6 @@ class OpeningApiController extends ApiController
{
$qb->where($qb->expr()->gt('e.noActiveAfter', ':now'))
->orWhere($qb->expr()->isNull('e.noActiveAfter'));
$qb->setParameter('now', new DateTime('now'));
$qb->setParameter('now', new \DateTime('now'));
}
}

View File

@@ -19,8 +19,6 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
/**
* Class PersonAddressController
* Controller for addresses associated with person.
@@ -50,8 +48,7 @@ class PersonAddressController extends AbstractController
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
throw $this->createNotFoundException("Person with id {$person_id} not".' found ');
}
$this->denyAccessUnlessGranted(
@@ -70,7 +67,7 @@ class PersonAddressController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$validatePersonErrors = $this->validatePerson($person);
if (count($validatePersonErrors) !== 0) {
if (0 !== \count($validatePersonErrors)) {
foreach ($validatePersonErrors as $error) {
$this->addFlash('error', $error->getMessage());
}
@@ -108,8 +105,7 @@ class PersonAddressController extends AbstractController
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
throw $this->createNotFoundException("Person with id {$person_id} not".' found ');
}
$this->denyAccessUnlessGranted(
@@ -139,8 +135,7 @@ class PersonAddressController extends AbstractController
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
throw $this->createNotFoundException("Person with id {$person_id} not".' found ');
}
$this->denyAccessUnlessGranted(
@@ -164,8 +159,7 @@ class PersonAddressController extends AbstractController
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
throw $this->createNotFoundException("Person with id {$person_id} not".' found ');
}
$this->denyAccessUnlessGranted(
@@ -194,8 +188,7 @@ class PersonAddressController extends AbstractController
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
throw $this->createNotFoundException("Person with id {$person_id} not".' found ');
}
$this->denyAccessUnlessGranted(
@@ -212,7 +205,7 @@ class PersonAddressController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$validatePersonErrors = $this->validatePerson($person);
if (count($validatePersonErrors) !== 0) {
if (0 !== \count($validatePersonErrors)) {
foreach ($validatePersonErrors as $error) {
$this->addFlash('error', $error->getMessage());
}
@@ -284,9 +277,9 @@ class PersonAddressController extends AbstractController
/**
* @param int $address_id
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the address id does not exists or is not associated with given person
*
* @return Address
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the address id does not exists or is not associated with given person
*/
protected function findAddressById(Person $person, $address_id)
{

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person;
@@ -24,7 +23,6 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use function in_array;
class PersonApiController extends ApiController
{
@@ -91,6 +89,7 @@ class PersonApiController extends ApiController
* "_format": "json"
* }
* )
*
* @ParamConverter("person", options={"id": "person_id"})
*/
public function suggestAddress(Person $person, Request $request, string $_format): Response
@@ -116,7 +115,7 @@ class PersonApiController extends ApiController
static function (Address $address) use (&$seenAddressIds): bool {
$id = $address->getId();
if (in_array($id, $seenAddressIds, true)) {
if (\in_array($id, $seenAddressIds, true)) {
return false;
}

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Entity\Household\Household;
@@ -23,9 +22,7 @@ use Chill\PersonBundle\Privacy\PrivacyEvent;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\SimilarPersonMatcher;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -33,18 +30,11 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
use function hash;
use function implode;
use function in_array;
use function is_array;
final class PersonController extends AbstractController
{
@@ -131,6 +121,7 @@ final class PersonController extends AbstractController
* name="chill_person_household_person_history",
* methods={"GET", "POST"}
* )
*
* @ParamConverter("person", options={"id": "person_id"})
*/
public function householdHistoryByPerson(Request $request, Person $person): Response
@@ -160,6 +151,7 @@ final class PersonController extends AbstractController
*
* The next post compare the data with previous one and, if yes, show a
* review page if there are "alternate persons".
*
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/new", name="chill_person_new")
*/
public function newAction(Request $request): Response
@@ -168,7 +160,7 @@ final class PersonController extends AbstractController
$authorizedCenters = $this->authorizationHelper->getReachableCenters($this->getUser(), PersonVoter::CREATE);
if (1 === count($authorizedCenters)) {
if (1 === \count($authorizedCenters)) {
$person->setCenter($authorizedCenters[0]);
}
@@ -183,10 +175,10 @@ final class PersonController extends AbstractController
$form->handleRequest($request);
if ($request->getMethod() === Request::METHOD_GET) {
if (Request::METHOD_GET === $request->getMethod()) {
$this->lastPostDataReset();
} elseif (
$request->getMethod() === Request::METHOD_POST
Request::METHOD_POST === $request->getMethod()
&& $form->isValid()
) {
$alternatePersons = $this->similarPersonMatcher
@@ -194,7 +186,7 @@ final class PersonController extends AbstractController
if (
false === $this->isLastPostDataChanges($form, $request, true)
|| count($alternatePersons) === 0
|| 0 === \count($alternatePersons)
) {
$this->em->persist($person);
@@ -209,7 +201,7 @@ final class PersonController extends AbstractController
$member = new HouseholdMember();
$member->setPerson($person);
$member->setStartDate(new DateTimeImmutable());
$member->setStartDate(new \DateTimeImmutable());
$household->addMember($member);
$household->setForceAddress($address);
@@ -243,7 +235,7 @@ final class PersonController extends AbstractController
['person_id' => $person->getId()]
);
}
} elseif ($request->getMethod() === Request::METHOD_POST && !$form->isValid()) {
} elseif (Request::METHOD_POST === $request->getMethod() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
@@ -264,8 +256,7 @@ final class PersonController extends AbstractController
$person = $this->_getPerson($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person_id} not".' found on this server');
}
$this->denyAccessUnlessGranted(
@@ -290,7 +281,6 @@ final class PersonController extends AbstractController
/**
* easy getting a person by his id.
*
*
* @return \Chill\PersonBundle\Entity\Person
*/
private function _getPerson(int $id)
@@ -306,14 +296,14 @@ final class PersonController extends AbstractController
$errors = $this->validator
->validate($person, null, ['creation']);
//validate accompanying periods
// validate accompanying periods
$periods = $person->getAccompanyingPeriods();
foreach ($periods as $period) {
$period_errors = $this->validator
->validate($period);
//group errors :
// group errors :
foreach ($period_errors as $error) {
$errors->add($error);
}
@@ -353,15 +343,15 @@ final class PersonController extends AbstractController
$ignoredFields = ['form_status', '_token'];
foreach ($request->request->all()[$form->getName()] as $field => $value) {
if (in_array($field, $ignoredFields, true)) {
if (\in_array($field, $ignoredFields, true)) {
continue;
}
$fields[$field] = is_array($value) ?
implode(',', $value) : $value;
$fields[$field] = \is_array($value) ?
\implode(',', $value) : $value;
}
ksort($fields);
return hash('sha512', implode('&', $fields));
return \hash('sha512', \implode('&', $fields));
}
private function lastPostDataReset(): void

View File

@@ -25,11 +25,9 @@ use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\SimilarPersonMatcher;
use Chill\TaskBundle\Entity\SingleTask;
use http\Exception\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
@@ -52,8 +50,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$person2->counters = $this->_getCounters($person2_id);
if (null === $person1) {
throw $this->createNotFoundException("Person with id {$person1_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person1_id} not".' found on this server');
}
$this->denyAccessUnlessGranted(
@@ -63,8 +60,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
);
if (null === $person2) {
throw $this->createNotFoundException("Person with id {$person2_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person2_id} not".' found on this server');
}
$form = $this->createForm(PersonConfimDuplicateType::class);
@@ -109,8 +105,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$person = $this->_getPerson($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person_id} not".' found on this server');
}
$this->denyAccessUnlessGranted(
@@ -127,8 +122,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$person2 = $form->get('person')->getData();
if (null === $person2) {
throw $this->createNotFoundException("Person with id {$person2->getId}() not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person2->getId}() not".' found on this server');
}
$direction = $form->get('direction')->getData();
@@ -215,8 +209,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$person = $this->_getPerson($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person_id} not".' found on this server');
}
$this->denyAccessUnlessGranted(
@@ -248,11 +241,11 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$person = $em->getRepository(Person::class)->findOneBy(['id' => $id]);
return [
'nb_activity' => count($nb_activity),
'nb_document' => count($nb_document),
'nb_activity' => \count($nb_activity),
'nb_document' => \count($nb_document),
// 'nb_event' => count($nb_event),
'nb_task' => $nb_task,
'nb_addresses' => count($person->getAddresses()),
'nb_addresses' => \count($person->getAddresses()),
];
}
@@ -279,13 +272,11 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
}
if (null === $person1) {
throw $this->createNotFoundException("Person with id {$person1_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person1_id} not".' found on this server');
}
if (null === $person2) {
throw $this->createNotFoundException("Person with id {$person2_id} not"
. ' found on this server');
throw $this->createNotFoundException("Person with id {$person2_id} not".' found on this server');
}
return [$person1, $person2];

View File

@@ -50,7 +50,7 @@ final class PersonResourceController extends AbstractController
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
if (Request::METHOD_DELETE === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {

View File

@@ -36,7 +36,6 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\NotIdenticalTo;
use Symfony\Component\Validator\Constraints\NotNull;
use function is_int;
class ReassignAccompanyingPeriodController extends AbstractController
{
@@ -142,7 +141,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
return $builder->getForm();
}
private function buildReassignForm(array $periodIds, ?User $userFrom = null): FormInterface
private function buildReassignForm(array $periodIds, User $userFrom = null): FormInterface
{
$defaultData = [
'userFrom' => $userFrom,
@@ -181,7 +180,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
return null;
}
if (!is_int((int) $id)) {
if (!\is_int((int) $id)) {
throw new TransformationFailedException('the user id is not a numeric');
}

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Pagination\PaginatorInterface;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\Request;
class SocialIssueApiController extends ApiController
@@ -26,7 +25,7 @@ class SocialIssueApiController extends ApiController
$query->expr()->isNull('e.desactivationDate')
)
);
$query->setParameter('now', new DateTimeImmutable());
$query->setParameter('now', new \DateTimeImmutable());
}
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)

View File

@@ -13,13 +13,12 @@ namespace Chill\PersonBundle\Controller\SocialWork;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Chill\MainBundle\Pagination\PaginatorInterface;
use LogicException;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
class SocialIssueController extends CRUDController
{
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
{
if ('new' === $action) {
return parent::createFormFor($action, $entity, $formClass, ['step' => 'create']);
@@ -29,7 +28,7 @@ class SocialIssueController extends CRUDController
return parent::createFormFor($action, $entity, $formClass, ['step' => 'edit']);
}
throw new LogicException('action is not supported: ' . $action);
throw new \LogicException('action is not supported: '.$action);
}
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)

View File

@@ -31,6 +31,7 @@ class SocialWorkEvaluationApiController extends AbstractController
* "_format": "json"
* }
* )
*
* @ParamConverter("action", options={"id": "action_id"})
*/
public function listEvaluationBySocialAction(SocialAction $action): Response

View File

@@ -20,8 +20,6 @@ use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use function count;
final class SocialWorkSocialActionApiController extends ApiController
{
public function __construct(
@@ -46,9 +44,9 @@ final class SocialWorkSocialActionApiController extends ApiController
usort($socialActions, static fn (SocialAction $sa, SocialAction $sb) => $sa->getOrdering() <=> $sb->getOrdering());
$pagination = $this->paginator->create(count($socialActions));
$pagination = $this->paginator->create(\count($socialActions));
// max one page
$pagination->setItemsPerPage(count($socialActions));
$pagination->setItemsPerPage(\count($socialActions));
$collection = new Collection($socialActions, $pagination);

View File

@@ -14,9 +14,6 @@ namespace Chill\PersonBundle\DataFixtures\Helper;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use function array_pop;
use function random_int;
trait PersonRandomHelper
{
private ?int $countPersons = null;
@@ -41,11 +38,11 @@ trait PersonRandomHelper
->select('p')
->from(Person::class, 'p')
->getQuery()
->setFirstResult(random_int(0, $this->countPersons - $fetchBy))
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
->setMaxResults($fetchBy)
->getResult();
}
return array_pop($this->randPersons);
return \array_pop($this->randPersons);
}
}

View File

@@ -14,8 +14,6 @@ namespace Chill\PersonBundle\DataFixtures\Helper;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use function random_int;
trait RandomPersonHelperTrait
{
private ?int $nbOfPersons = null;
@@ -36,7 +34,7 @@ trait RandomPersonHelperTrait
return $qb
->select('p')
->setMaxResults(1)
->setFirstResult(random_int(0, $this->nbOfPersons))
->setFirstResult(\random_int(0, $this->nbOfPersons))
->getQuery()
->getSingleResult();
}

View File

@@ -58,7 +58,7 @@ class LoadAccompanyingPeriodClosingMotive extends AbstractFixture implements Ord
foreach (static::$closingMotives as $ref => $new) {
$motive = new ClosingMotive();
$motive->setName($new['name'])
->setActive(($new['active'] ?? true));
->setActive($new['active'] ?? true);
$manager->persist($motive);
$this->addReference($ref, $motive);

View File

@@ -17,13 +17,8 @@ use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
use DateTimeImmutable;
use Doctrine\Persistence\ObjectManager;
use function array_pop;
use function array_rand;
use function count;
class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\DependentFixtureInterface
{
/**
@@ -48,8 +43,8 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$i = 0;
while (null !== $period = array_pop($periods)) {
/** @var AccompanyingPeriod $period */
while (null !== $period = \array_pop($periods)) {
/* @var AccompanyingPeriod $period */
++$i;
if (0 === $i % 15) {
@@ -66,11 +61,11 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$work
->setAccompanyingPeriod($period)
->setSocialAction($action)
->setStartDate(new DateTimeImmutable('today'))
->setStartDate(new \DateTimeImmutable('today'))
->addPerson($period->getPersons()->first())
->setCreatedAt(new DateTimeImmutable())
->setCreatedAt(new \DateTimeImmutable())
->setCreatedBy($this->getReference('center a_social'))
->setUpdatedAt(new DateTimeImmutable())
->setUpdatedAt(new \DateTimeImmutable())
->setUpdatedBy($this->getReference('center a_social'));
$manager->persist($work);
@@ -93,11 +88,11 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$work
->setAccompanyingPeriod($period)
->setSocialAction($action)
->setStartDate(new DateTimeImmutable('today'))
->setStartDate(new \DateTimeImmutable('today'))
->addPerson($period->getPersons()->first())
->setCreatedAt(new DateTimeImmutable())
->setCreatedAt(new \DateTimeImmutable())
->setCreatedBy($this->getReference('center a_social'))
->setUpdatedAt(new DateTimeImmutable())
->setUpdatedAt(new \DateTimeImmutable())
->setUpdatedBy($this->getReference('center a_social'));
$manager->persist($work);
$ev = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
@@ -114,20 +109,20 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
{
$actions = $socialIssue->getRecursiveSocialActions()->toArray();
if (0 === count($actions)) {
if (0 === \count($actions)) {
return null;
}
return $actions[array_rand($actions)];
return $actions[\array_rand($actions)];
}
private function getRandomEvaluation(): Evaluation
{
if (0 === count($this->cacheEvaluations)) {
if (0 === \count($this->cacheEvaluations)) {
$this->cacheEvaluations = $this->evaluationRepository
->findAll();
}
return $this->cacheEvaluations[array_rand($this->cacheEvaluations)];
return $this->cacheEvaluations[\array_rand($this->cacheEvaluations)];
}
}

View File

@@ -17,27 +17,20 @@ use Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class LoadCustomFields extends AbstractFixture implements
OrderedFixtureInterface
class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterface
{
private ?\Chill\CustomFieldsBundle\Entity\CustomField $cfText = null;
private ?\Chill\CustomFieldsBundle\Entity\CustomField $cfChoice = null;
/**
/**
* /**
* LoadCustomFields constructor.
*/
public function __construct(
@@ -46,7 +39,7 @@ class LoadCustomFields extends AbstractFixture implements
private readonly CustomFieldText $customFieldText,
) {}
//put your code here
// put your code here
public function getOrder()
{
return 10003;
@@ -85,7 +78,7 @@ class LoadCustomFields extends AbstractFixture implements
// select a set of people and add data
foreach ($personIds as $id) {
// add info on 1 person on 2
if (random_int(0, 1) === 1) {
if (1 === random_int(0, 1)) {
/** @var Person $person */
$person = $manager->getRepository(Person::class)->find($id);
$person->setCFData([

View File

@@ -19,20 +19,12 @@ use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Household\MembersEditorFactory;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Nelmio\Alice\Loader\NativeLoader;
use function array_pop;
use function array_rand;
use function random_int;
use function shuffle;
class LoadHousehold extends Fixture implements DependentFixtureInterface
{
private const NUMBER_OF_HOUSEHOLD = 10;
@@ -64,43 +56,43 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
$this->generateHousehold(
$manager,
DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
\DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
);
$this->preparePersonIds();
$this->generateHousehold(
$manager,
DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
\DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
);
$manager->flush();
}
private function addAddressToHousehold(Household $household, DateTimeImmutable $date, ObjectManager $manager)
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
{
if (random_int(0, 10) > 8) {
if (\random_int(0, 10) > 8) {
// 20% of household without address
return;
}
$nb = random_int(1, 6);
$nb = \random_int(1, 6);
$i = 0;
while ($i < $nb) {
$address = $this->createAddress();
$address->setValidFrom(DateTime::createFromImmutable($date));
$address->setValidFrom(\DateTime::createFromImmutable($date));
if (random_int(0, 20) < 1) {
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
$address->setValidTo(DateTime::createFromImmutable($date));
if (\random_int(0, 20) < 1) {
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
$address->setValidTo(\DateTime::createFromImmutable($date));
}
$household->addAddress($address);
$manager->persist($address);
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
++$i;
}
}
@@ -120,7 +112,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
return $objectSet->getObjects()['address1'];
}
private function generateHousehold(ObjectManager $manager, DateTimeImmutable $startDate)
private function generateHousehold(ObjectManager $manager, \DateTimeImmutable $startDate)
{
for ($i = 0; self::NUMBER_OF_HOUSEHOLD > $i; ++$i) {
$household = new Household();
@@ -134,7 +126,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
$k = 0;
foreach ($this->getRandomPersons(1, 3) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::ADULT);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -143,7 +135,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// load children
foreach ($this->getRandomPersons(0, 3) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::CHILD);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -152,7 +144,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// load children out
foreach ($this->getRandomPersons(0, 2) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -167,7 +159,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
private function getPostalCode(): PostalCode
{
$ref = LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)];
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
return $this->getReference($ref);
}
@@ -176,10 +168,10 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
{
$persons = [];
$nb = random_int($min, $max);
$nb = \random_int($min, $max);
for ($i = 0; $i < $nb; ++$i) {
$personId = array_pop($this->personIds)['id'];
$personId = \array_pop($this->personIds)['id'];
$persons[] = $this->em->getRepository(Person::class)->find($personId);
}
@@ -193,17 +185,17 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// @TODO: Remove this and make this service stateless
$this->personIds = $this->em
->createQuery(
'SELECT p.id FROM ' . Person::class . ' p ' .
'WHERE EXISTS( ' .
'SELECT 1 FROM ' . PersonCenterHistory::class . ' pch ' .
'JOIN pch.center c ' .
'WHERE pch.person = p.id ' .
'AND c.name IN (:authorized_centers)' .
'SELECT p.id FROM '.Person::class.' p '.
'WHERE EXISTS( '.
'SELECT 1 FROM '.PersonCenterHistory::class.' pch '.
'JOIN pch.center c '.
'WHERE pch.person = p.id '.
'AND c.name IN (:authorized_centers)'.
')'
)
->setParameter('authorized_centers', $centers)
->getScalarResult();
shuffle($this->personIds);
\shuffle($this->personIds);
}
}

View File

@@ -41,11 +41,11 @@ class LoadMaritalStatus extends AbstractFixture implements OrderedFixtureInterfa
echo "loading maritalStatuses... \n";
foreach ($this->maritalStatuses as $ms) {
echo $ms['name']['en'] . ' ';
echo $ms['name']['en'].' ';
$new_ms = new MaritalStatus();
$new_ms->setId($ms['id']);
$new_ms->setName($ms['name']);
$this->addReference('ms_' . $ms['id'], $new_ms);
$this->addReference('ms_'.$ms['id'], $new_ms);
$manager->persist($new_ms);
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
use Chill\MainBundle\Doctrine\Model\Point;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Country;
@@ -29,13 +28,9 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Repository\MaritalStatusRepository;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Exception;
use Faker\Factory;
use Faker\Generator;
use Nelmio\Alice\Loader\NativeLoader;
@@ -43,10 +38,6 @@ use Nelmio\Alice\ObjectSet;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Workflow\Registry;
use function count;
use function random_int;
use function ucfirst;
/**
* Load people into database.
*/
@@ -118,7 +109,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
],
],
[
//to have a person with same firstname as Gérard Depardieu
// to have a person with same firstname as Gérard Depardieu
'lastName' => 'Depardieu',
'firstName' => 'Jean',
'birthdate' => '1960-10-12',
@@ -128,7 +119,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_divorce',
],
[
//to have a person with same birthdate of Gérard Depardieu
// to have a person with same birthdate of Gérard Depardieu
'lastName' => 'Van Snick',
'firstName' => 'Bart',
'birthdate' => '1948-12-27',
@@ -136,7 +127,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_legalco',
],
[
//to have a woman with Depardieu as FirstName
// to have a woman with Depardieu as FirstName
'lastName' => 'Depardieu',
'firstName' => 'Charline',
'birthdate' => '1970-10-15',
@@ -145,14 +136,14 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_legalco',
],
[
//to have a special character in lastName
// to have a special character in lastName
'lastName' => 'Manço',
'firstName' => 'Étienne',
'center' => 'Center A',
'maritalStatus' => 'ms_unknown',
],
[
//to have true duplicate person
// to have true duplicate person
'lastName' => 'Depardieu',
'firstName' => 'Jean',
'birthdate' => '1960-10-12',
@@ -162,7 +153,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_divorce',
],
[
//to have false duplicate person
// to have false duplicate person
'lastName' => 'Depardieu',
'firstName' => 'Jeanne',
'birthdate' => '1966-11-13',
@@ -253,7 +244,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
*/
public function getRandomCenter(): Center
{
if (0 === count($this->cacheCenters)) {
if (0 === \count($this->cacheCenters)) {
$this->cacheCenters = $this->centerRepository->findAll();
}
@@ -263,15 +254,15 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* @internal This method is public and called by faker as a custom generator
*
* @throws Exception
* @throws \Exception
*/
public function getRandomCountry(int $nullPercentage = 20): ?Country
{
if (0 === count($this->cacheCountries)) {
if (0 === \count($this->cacheCountries)) {
$this->cacheCountries = $this->countryRepository->findAll();
}
if (random_int(0, 100) > $nullPercentage) {
if (\random_int(0, 100) > $nullPercentage) {
return null;
}
@@ -289,15 +280,15 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* @internal This method is public and called by faker as a custom generator
*
* @throws Exception
* @throws \Exception
*/
public function getRandomMaritalStatus(int $nullPercentage = 50): ?MaritalStatus
{
if (0 === count($this->cacheMaritalStatuses)) {
if (0 === \count($this->cacheMaritalStatuses)) {
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
}
if (random_int(0, 100) > $nullPercentage) {
if (\random_int(0, 100) > $nullPercentage) {
return null;
}
@@ -335,22 +326,22 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* create a new person from array data.
*
* @throws Exception
* @throws \Exception
*/
private function addAPerson(Person $person, ObjectManager $manager)
{
$accompanyingPeriod = new AccompanyingPeriod(
(new DateTime())
(new \DateTime())
->sub(
new DateInterval('P' . random_int(0, 180) . 'D')
new \DateInterval('P'.\random_int(0, 180).'D')
)
);
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
->setCreatedAt(new DateTimeImmutable('now'));
->setCreatedAt(new \DateTimeImmutable('now'));
$person->addAccompanyingPeriod($accompanyingPeriod);
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
if (random_int(0, 10) > 3) {
if (\random_int(0, 10) > 3) {
// always add social scope:
$accompanyingPeriod->addScope($this->getReference('scope_social'));
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN);
@@ -365,7 +356,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
$manager->persist($person);
$manager->persist($accompanyingPeriod);
$this->addReference(self::PERSON . $person->getId(), $person);
$this->addReference(self::PERSON.$person->getId(), $person);
}
private function createAddress(): Address
@@ -408,7 +399,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
foreach ($default as $key => $value) {
switch ($key) {
case 'birthdate':
$person->setBirthdate(new DateTime($value));
$person->setBirthdate(new \DateTime($value));
break;
@@ -471,7 +462,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
private function getRandomSocialIssue(): SocialIssue
{
if (0 === count($this->cacheSocialIssues)) {
if (0 === \count($this->cacheSocialIssues)) {
$this->cacheSocialIssues = $this->socialIssueRepository->findAll();
}
@@ -480,7 +471,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
private function getRandomUser(): User
{
if (0 === count($this->cacheUsers)) {
if (0 === \count($this->cacheUsers)) {
$this->cacheUsers = $this->userRepository->findAll();
}

View File

@@ -36,7 +36,7 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
$permissionsGroup = $this->getReference($permissionsGroupRef);
$scopeSocial = $this->getReference('scope_social');
//create permission group
// create permission group
switch ($permissionsGroup->getName()) {
case 'social':
case 'direction':

View File

@@ -38,13 +38,13 @@ class LoadRelations extends Fixture implements FixtureGroupInterface
public function load(ObjectManager $manager)
{
foreach (self::RELATIONS as $key => $value) {
echo 'Creating a new relation type: relation' . $value['title']['fr'] . 'reverse relation: ' . $value['reverseTitle']['fr'] . "\n";
echo 'Creating a new relation type: relation'.$value['title']['fr'].'reverse relation: '.$value['reverseTitle']['fr']."\n";
$relation = new Relation();
$relation->setTitle($value['title'])
->setReverseTitle($value['reverseTitle']);
$manager->persist($relation);
$this->addReference(self::RELATION_KEY . $key, $relation);
$this->addReference(self::RELATION_KEY.$key, $relation);
}
$manager->flush();

View File

@@ -15,15 +15,11 @@ use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use Chill\PersonBundle\Entity\Relationships\Relationship;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use function array_key_exists;
use function count;
class LoadRelationships extends Fixture implements DependentFixtureInterface
{
use PersonRandomHelper;
@@ -45,12 +41,12 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
for ($i = 0; 20 > $i; ++$i) {
$user = $this->getRandomUser();
$date = new DateTimeImmutable();
$date = new \DateTimeImmutable();
$relationship = (new Relationship())
->setFromPerson($this->getRandomPerson($this->em))
->setToPerson($this->getRandomPerson($this->em))
->setRelation($this->getReference(LoadRelations::RELATION_KEY .
random_int(0, count(LoadRelations::RELATIONS) - 1)))
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
random_int(0, \count(LoadRelations::RELATIONS) - 1)))
->setReverse((bool) random_int(0, 1))
->setCreatedBy($user)
->setUpdatedBy($user)
@@ -63,7 +59,7 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
max($relationship->getFromPerson()->getId(), $relationship->getToPerson()->getId()),
];
if (array_key_exists($set[0], $existing) && array_key_exists($set[1], $existing[$set[0]])) {
if (\array_key_exists($set[0], $existing) && \array_key_exists($set[1], $existing[$set[0]])) {
continue;
}
$existing[$set[0]][$set[1]] = 1;

View File

@@ -15,9 +15,7 @@ use Chill\PersonBundle\Service\Import\SocialWorkMetadata;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Exception;
use League\Csv\Reader;
use Throwable;
class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
{
@@ -31,9 +29,9 @@ class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
public function load(ObjectManager $manager)
{
try {
$csv = Reader::createFromPath(__DIR__ . '/data/social_work_metadata.csv');
} catch (Throwable $e) {
throw new Exception('Error while loading CSV.', 0, $e);
$csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv');
} catch (\Throwable $e) {
throw new \Exception('Error while loading CSV.', 0, $e);
}
$csv->setDelimiter(';');

View File

@@ -20,7 +20,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodResourceVoter;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Exception;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
@@ -28,8 +27,6 @@ use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function array_key_exists;
/**
* Class ChillPersonExtension
* Loads and manages your bundle configuration.
@@ -39,7 +36,7 @@ use function array_key_exists;
class ChillPersonExtension extends Extension implements PrependExtensionInterface
{
/**
* @throws Exception
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
@@ -73,7 +70,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
// register all configuration in a unique parameter
$container->setParameter('chill_person', $config);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yaml');
$loader->load('services/widgets.yaml');
$loader->load('services/fixtures.yaml');
@@ -97,7 +94,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$loader->load('services/exports_person.yaml');
if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') {
if ('hidden' !== $container->getParameter('chill_person.accompanying_period')) {
$loader->load('services/exports_accompanying_course.yaml');
$loader->load('services/exports_social_actions.yaml');
$loader->load('services/exports_evaluation.yaml');
@@ -117,7 +114,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$this->prependCruds($container);
$this->prependWorkflows($container);
//add person_fields parameter as global
// add person_fields parameter as global
$chillPersonConfig = $container->getExtensionConfig($this->getAlias());
$config = $this->processConfiguration(new Configuration(), $chillPersonConfig);
$twigConfig = [
@@ -135,7 +132,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$this->declarePersonAsCustomizable($container);
//declare routes for person bundle
// declare routes for person bundle
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
@@ -918,7 +915,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
*/
protected function prependDoctrineDQL(ContainerBuilder $container)
{
//add DQL function to ORM (default entity_manager)
// add DQL function to ORM (default entity_manager)
$container->prependExtensionConfig('doctrine', [
'orm' => [
@@ -1026,7 +1023,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
'mark_inactive_long' => [
'from' => [
AccompanyingPeriod::STEP_CONFIRMED,
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT,
],
'to' => AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG,
],
@@ -1035,7 +1032,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG,
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT,
],
'to' => AccompanyingPeriod::STEP_CONFIRMED
'to' => AccompanyingPeriod::STEP_CONFIRMED,
],
'close' => [
'from' => [
@@ -1071,9 +1068,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
);
}
/**
* @param $config
*/
private function handleAccompanyingPeriodsFieldsParameters(ContainerBuilder $container, $config)
{
$container->setParameter('chill_person.accompanying_period_fields', $config);
@@ -1084,19 +1078,16 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
break;
default:
$container->setParameter('chill_person.accompanying_period_fields.' . $key, $value);
$container->setParameter('chill_person.accompanying_period_fields.'.$key, $value);
break;
}
}
}
/**
* @param $config
*/
private function handlePersonFieldsParameters(ContainerBuilder $container, $config)
{
if (array_key_exists('enabled', $config)) {
if (\array_key_exists('enabled', $config)) {
unset($config['enabled']);
}
@@ -1105,7 +1096,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
foreach ($config as $key => $value) {
match ($key) {
'accompanying_period' => $container->setParameter('chill_person.accompanying_period', $value),
default => $container->setParameter('chill_person.person_fields.' . $key, $value),
default => $container->setParameter('chill_person.person_fields.'.$key, $value),
};
}
}

View File

@@ -14,8 +14,6 @@ namespace Chill\PersonBundle\DependencyInjection\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use function in_array;
/**
* Remove services which add AccompanyingPeriod to timeline if
* accompanying_periods are set to `hidden`.
@@ -25,7 +23,7 @@ class AccompanyingPeriodTimelineCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
// remove services when accompanying period are hidden
if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') {
if ('hidden' !== $container->getParameter('chill_person.accompanying_period')) {
return;
}
@@ -52,7 +50,7 @@ class AccompanyingPeriodTimelineCompilerPass implements CompilerPassInterface
$definition->removeMethodCall('addProvider');
if (false === in_array($arguments[1], $definitions, true)) {
if (false === \in_array($arguments[1], $definitions, true)) {
$definition->addMethodCall($method, $arguments);
}
}

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\DependencyInjection;
use DateInterval;
use Exception;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -24,8 +22,8 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
private string $validationBirthdateNotAfterInfos = 'The period before today during which'
. ' any birthdate is not allowed. The birthdate is expressed as ISO8601 : '
. 'https://en.wikipedia.org/wiki/ISO_8601#Durations';
.' any birthdate is not allowed. The birthdate is expressed as ISO8601 : '
.'https://en.wikipedia.org/wiki/ISO_8601#Durations';
public function getConfigTreeBuilder()
{
@@ -48,19 +46,19 @@ class Configuration implements ConfigurationInterface
->validate()
->ifTrue(static function ($period) {
try {
$interval = new DateInterval($period);
} catch (Exception) {
$interval = new \DateInterval($period);
} catch (\Exception) {
return true;
}
return false;
})
->thenInvalid('Invalid period for birthdate validation : "%s" '
. 'The parameter should match duration as defined by ISO8601 : '
. 'https://en.wikipedia.org/wiki/ISO_8601#Durations')
.'The parameter should match duration as defined by ISO8601 : '
.'https://en.wikipedia.org/wiki/ISO_8601#Durations')
->end() // birthdate_not_after, parent = children of validation
->end() // children for 'validation', parent = validation
->end() //validation, parent = children of root
->end() // validation, parent = children of root
->end() // children of root, parent = root
->booleanNode('create_person_allowed')
->defaultTrue()
@@ -107,7 +105,7 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->end()
->end() //children for 'person_fields', parent = array 'person_fields'
->end() // children for 'person_fields', parent = array 'person_fields'
->end() // person_fields, parent = children of root
->arrayNode('accompanying_periods_fields')
->canBeDisabled()
@@ -122,7 +120,7 @@ class Configuration implements ConfigurationInterface
->append($this->addFieldNode('anonymous'))
->append($this->addFieldNode('emergency'))
->append($this->addFieldNode('confidential'))
->end() //children for 'accompanying_person_fields', parent = array 'person_fields'
->end() // children for 'accompanying_person_fields', parent = array 'person_fields'
->end() // paccompanying_person_fields, parent = children of root
->booleanNode('allow_multiple_simultaneous_accompanying_periods')
->info('Can we have more than one simultaneous accompanying period in the same time. Default false.')

View File

@@ -38,38 +38,36 @@ use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOve
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Iterator;
use LogicException;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\GroupSequenceProviderInterface;
use UnexpectedValueException;
use function array_key_exists;
use const SORT_REGULAR;
/**
* AccompanyingPeriod Class.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period": AccompanyingPeriod::class
* })
*
* @Assert\GroupSequenceProvider
*
* @AccompanyingPeriodValidity(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
*
* @LocationValidity(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
*
* @ConfidentialCourseMustHaveReferrer(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
*/
class AccompanyingPeriod implements
@@ -112,7 +110,7 @@ class AccompanyingPeriod implements
final public const STEP_CONFIRMED = 'CONFIRMED';
/**
* Mark an accompanying period as confirmed, but inactive
* Mark an accompanying period as confirmed, but inactive.
*
* this means that the accompanying period **is**
* confirmed, but no activity (Activity, AccompanyingPeriod, ...)
@@ -121,7 +119,7 @@ class AccompanyingPeriod implements
final public const STEP_CONFIRMED_INACTIVE_SHORT = 'CONFIRMED_INACTIVE_SHORT';
/**
* Mark an accompanying period as confirmed, but inactive
* Mark an accompanying period as confirmed, but inactive.
*
* this means that the accompanying period **is**
* confirmed, but no activity (Activity, AccompanyingPeriod, ...)
@@ -146,36 +144,43 @@ class AccompanyingPeriod implements
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
*
* @Groups({"read", "write"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?Location $administrativeLocation = null;
/**
* @var Collection&Selectable<int, Calendar>
*
* @ORM\OneToMany(targetEntity="Chill\CalendarBundle\Entity\Calendar", mappedBy="accompanyingPeriod")
*/
private Collection&Selectable $calendars;
/**
* @ORM\Column(type="date", nullable=true)
*
* @Groups({"read", "write", "docgen:read"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CLOSED})
*
* @Assert\GreaterThanOrEqual(
* propertyPath="openingDate",
* groups={AccompanyingPeriod::STEP_CLOSED},
* message="The closing date must be later than the date of creation"
* )
*/
private ?DateTime $closingDate = null;
private ?\DateTime $closingDate = null;
/**
* @var AccompanyingPeriod\ClosingMotive
*
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive")
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "write"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CLOSED})
*/
private ?ClosingMotive $closingMotive = null;
@@ -186,48 +191,61 @@ class AccompanyingPeriod implements
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
*
* @ORM\OrderBy({"createdAt": "DESC", "id": "DESC"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_DRAFT})
*
* @var Collection<Comment>
*/
private Collection $comments;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @Groups({"read", "write", "docgen:read"})
*/
private bool $confidential = false;
/**
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
*
* @Groups({"docgen:read"})
*/
private ?DateTimeInterface $createdAt = null;
private ?\DateTimeInterface $createdAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?User $createdBy = null;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @Groups({"read", "write", "docgen:read"})
*/
private bool $emergency = false;
/**
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", nullable=true)
*
* @Groups({"read"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private string $intensity = self::INTENSITY_OCCASIONAL;
@@ -236,13 +254,16 @@ class AccompanyingPeriod implements
* @ORM\ManyToOne(
* targetEntity=UserJob::class
* )
*
* @Groups({"read", "write"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?UserJob $job = null;
/**
* @var Collection<AccompanyingPeriodLocationHistory>
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodLocationHistory::class,
* mappedBy="period", cascade={"persist", "remove"}, orphanRemoval=true)
*/
@@ -250,16 +271,22 @@ class AccompanyingPeriod implements
/**
* @ORM\Column(type="date")
*
* @Groups({"read", "write", "docgen:read"})
*
* @Assert\LessThan(value="tomorrow", groups={AccompanyingPeriod::STEP_CONFIRMED})
*
* @Assert\LessThanOrEqual(propertyPath="closingDate", groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?DateTime $openingDate = null;
private ?\DateTime $openingDate = null;
/**
* @ORM\ManyToOne(targetEntity=Origin::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "write"})
*
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?Origin $origin = null;
@@ -268,8 +295,11 @@ class AccompanyingPeriod implements
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
* mappedBy="accompanyingPeriod", orphanRemoval=true,
* cascade={"persist", "refresh", "remove", "merge", "detach"})
*
* @Groups({"read", "docgen:read"})
*
* @ParticipationOverlap(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
*
* @var Collection<AccompanyingPeriodParticipation>
*/
private Collection $participations;
@@ -287,7 +317,9 @@ class AccompanyingPeriod implements
* targetEntity=Comment::class,
* cascade={"persist"},
* )
*
* @Groups({"read"})
*
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private ?Comment $pinnedComment = null;
@@ -296,79 +328,97 @@ class AccompanyingPeriod implements
/**
* @ORM\Column(type="text")
*
* @Groups({"read", "write"})
*/
private string $remark = '';
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @Groups({"read", "write", "docgen:read"})
*/
private bool $requestorAnonymous = false;
/**
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodRequested")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?Person $requestorPerson = null;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
*
* @ORM\JoinColumn(nullable=true)
*/
private ?ThirdParty $requestorThirdParty = null;
/**
* @var Collection<Resource>
* @var Collection<resource>
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource",
* mappedBy="accompanyingPeriod",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
*
* @Groups({"read", "docgen:read"})
*
* @ResourceDuplicateCheck(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED, "Default", "default"})
*/
private Collection $resources;
/**
* @var Collection<Scope>
*
* @ORM\ManyToMany(
* targetEntity=Scope::class,
* cascade={}
* )
*
* @ORM\JoinTable(
* name="accompanying_periods_scopes",
* joinColumns={@ORM\JoinColumn(name="accompanying_period_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
*
* @Groups({"read", "docgen:read"})
*
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED}, minMessage="A course must be associated to at least one scope")
*/
private Collection $scopes;
/**
* @var Collection<SocialIssue>
*
* @ORM\ManyToMany(
* targetEntity=SocialIssue::class
* )
*
* @ORM\JoinTable(
* name="chill_person_accompanying_period_social_issues"
* )
*
* @Groups({"read", "docgen:read"})
*
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED}, minMessage="A course must contains at least one social issue")
*/
private Collection $socialIssues;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*
* @Groups({"read"})
*
* @var AccompanyingPeriod::STEP_*
*/
private string $step = self::STEP_DRAFT;
/**
* @var Collection<AccompanyingPeriodStepHistory>
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodStepHistory::class,
* mappedBy="period", cascade={"persist", "remove"}, orphanRemoval=true)
*/
@@ -377,7 +427,7 @@ class AccompanyingPeriod implements
/**
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
*/
private ?DateTimeInterface $updatedAt = null;
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\ManyToOne(
@@ -388,7 +438,9 @@ class AccompanyingPeriod implements
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "write", "docgen:read"})
*/
private ?User $user = null;
@@ -412,10 +464,12 @@ class AccompanyingPeriod implements
/**
* @var Collection<AccompanyingPeriodWork>
*
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWork::class,
* mappedBy="accompanyingPeriod"
* )
*
* @Assert\Valid(traverse=true)
*/
private Collection $works;
@@ -423,11 +477,9 @@ class AccompanyingPeriod implements
/**
* AccompanyingPeriod constructor.
*
* @param DateTime $dateOpening
*
* @uses AccompanyingPeriod::setClosingDate()
*/
public function __construct(?DateTime $dateOpening = null)
public function __construct(\DateTime $dateOpening = null)
{
$this->calendars = new ArrayCollection(); // TODO we cannot add a dependency between AccompanyingPeriod and calendars
$this->participations = new ArrayCollection();
@@ -439,7 +491,7 @@ class AccompanyingPeriod implements
$this->userHistories = new ArrayCollection();
$this->locationHistories = new ArrayCollection();
$this->stepHistories = new ArrayCollection();
$this->setOpeningDate($dateOpening ?? new DateTime('now'));
$this->setOpeningDate($dateOpening ?? new \DateTime('now'));
}
/**
@@ -462,7 +514,7 @@ class AccompanyingPeriod implements
foreach ($participations as $p) {
$households[] = $p->getPerson()->getCurrentHousehold();
}
$households = array_unique($households, SORT_REGULAR);
$households = array_unique($households, \SORT_REGULAR);
$array = [];
@@ -492,7 +544,7 @@ class AccompanyingPeriod implements
public function addLocationHistory(AccompanyingPeriodLocationHistory $history): self
{
if ($this->getStep() === self::STEP_DRAFT) {
if (self::STEP_DRAFT === $this->getStep()) {
return $this;
}
@@ -505,7 +557,7 @@ class AccompanyingPeriod implements
$criteria = new Criteria();
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
/** @var Iterator $locations */
/** @var \Iterator $locations */
$locations = $this->getLocationHistories()->matching($criteria)->getIterator();
$locations->rewind();
@@ -523,7 +575,7 @@ class AccompanyingPeriod implements
return $this;
}
public function addPerson(?Person $person = null): self
public function addPerson(Person $person = null): self
{
if (null !== $person) {
$this->createParticipationFor($person);
@@ -574,7 +626,7 @@ class AccompanyingPeriod implements
*/
public function canBeReOpened(Person $person): bool
{
if ($this->isOpen() === true) {
if (true === $this->isOpen()) {
return false;
}
@@ -600,7 +652,7 @@ class AccompanyingPeriod implements
$participation = $this->getOpenParticipationContainsPerson($person);
if ($participation instanceof AccompanyingPeriodParticipation) {
$participation->setEndDate(new DateTime('now'));
$participation->setEndDate(new \DateTime('now'));
}
return $participation;
@@ -660,7 +712,7 @@ class AccompanyingPeriod implements
public function getCenter(): ?Center
{
if ($this->getPersons()->count() === 0) {
if (0 === $this->getPersons()->count()) {
return null;
}
@@ -674,7 +726,7 @@ class AccompanyingPeriod implements
foreach ($this->getPersons() as $person) {
if (
null !== $person->getCenter()
&& !array_key_exists(spl_object_hash($person->getCenter()), $centers)
&& !\array_key_exists(spl_object_hash($person->getCenter()), $centers)
) {
$centers[spl_object_hash($person->getCenter())] = $person->getCenter();
}
@@ -685,10 +737,8 @@ class AccompanyingPeriod implements
/**
* Get closingDate.
*
* @return DateTime
*/
public function getClosingDate(): ?DateTime
public function getClosingDate(): ?\DateTime
{
return $this->closingDate;
}
@@ -700,6 +750,7 @@ class AccompanyingPeriod implements
/**
* @Groups({"read"})
*
* @return ReadableCollection<(int|string), Comment>
*/
public function getComments(): ReadableCollection
@@ -714,7 +765,7 @@ class AccompanyingPeriod implements
;
}
public function getCreatedAt(): ?DateTimeInterface
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
@@ -734,17 +785,17 @@ class AccompanyingPeriod implements
public function getGroupSequence()
{
if ($this->getStep() === self::STEP_DRAFT) {
if (self::STEP_DRAFT === $this->getStep()) {
return [[self::STEP_DRAFT]];
}
if (str_starts_with($this->getStep(), 'CONFIRM')) {
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
}
if ($this->getStep() === self::STEP_CLOSED) {
if (self::STEP_CLOSED === $this->getStep()) {
return [[self::STEP_DRAFT, self::STEP_CONFIRMED, self::STEP_CLOSED]];
}
throw new LogicException('no validation group permitted with this step: ' . $this->getStep());
throw new \LogicException('no validation group permitted with this step: '.$this->getStep());
}
public function getId(): ?int
@@ -778,7 +829,7 @@ class AccompanyingPeriod implements
*
* @Groups({"read"})
*/
public function getLocation(?DateTimeImmutable $at = null): ?Address
public function getLocation(\DateTimeImmutable $at = null): ?Address
{
if ($this->getPersonLocation() instanceof Person) {
return $this->getPersonLocation()->getCurrentPersonAddress();
@@ -799,6 +850,7 @@ class AccompanyingPeriod implements
* Get where the location is.
*
* @Groups({"read"})
*
* @return 'person'|'address'|'none'
*/
public function getLocationStatus(): string
@@ -816,10 +868,10 @@ class AccompanyingPeriod implements
public function getNextCalendarsForPerson(Person $person, $limit = 5): ReadableCollection
{
$today = new DateTimeImmutable('today');
$today = new \DateTimeImmutable('today');
$criteria = Criteria::create()
->where(Criteria::expr()->gte('startDate', $today))
//->andWhere(Criteria::expr()->memberOf('persons', $person))
// ->andWhere(Criteria::expr()->memberOf('persons', $person))
->orderBy(['startDate' => 'DESC'])
->setMaxResults($limit * 2);
@@ -834,10 +886,8 @@ class AccompanyingPeriod implements
/**
* Get openingDate.
*
* @return DateTime
*/
public function getOpeningDate(): ?DateTime
public function getOpeningDate(): ?\DateTime
{
return $this->openingDate;
}
@@ -877,6 +927,7 @@ class AccompanyingPeriod implements
/**
* Get Participations Collection.
*
* @return Collection<AccompanyingPeriodParticipation>
*/
public function getParticipations(): Collection
@@ -886,6 +937,7 @@ class AccompanyingPeriod implements
/**
* Get the participation containing a person.
*
* @return ReadableCollection<(int|string), AccompanyingPeriodParticipation>
*/
public function getParticipationsContainsPerson(Person $person): ReadableCollection
@@ -934,7 +986,7 @@ class AccompanyingPeriod implements
/**
* @return Collection|SocialAction[] All the descendant social actions of all
* the descendants of the entity
* the descendants of the entity
*/
public function getRecursiveSocialActions(): Collection
{
@@ -1109,11 +1161,11 @@ class AccompanyingPeriod implements
public function isOpen(): bool
{
if ($this->getOpeningDate() > new DateTimeImmutable('now')) {
if ($this->getOpeningDate() > new \DateTimeImmutable('now')) {
return false;
}
if ($this->getClosingDate() === null) {
if (null === $this->getClosingDate()) {
return true;
}
@@ -1205,7 +1257,7 @@ class AccompanyingPeriod implements
/**
* @Groups({"write"})
*/
public function setAddressLocation(?Address $addressLocation = null): self
public function setAddressLocation(Address $addressLocation = null): self
{
if ($this->addressLocation !== $addressLocation) {
$this->addressLocation = $addressLocation;
@@ -1214,7 +1266,7 @@ class AccompanyingPeriod implements
$this->setPersonLocation(null);
$locationHistory = new AccompanyingPeriodLocationHistory();
$locationHistory
->setStartDate(new DateTimeImmutable('now'))
->setStartDate(new \DateTimeImmutable('now'))
->setAddressLocation($addressLocation);
$this->addLocationHistory($locationHistory);
@@ -1236,7 +1288,6 @@ class AccompanyingPeriod implements
*
* For closing a Person file, you should use Person::setClosed instead.
*
*
* @return AccompanyingPeriod
*/
public function setClosingDate(mixed $closingDate)
@@ -1246,7 +1297,7 @@ class AccompanyingPeriod implements
return $this;
}
public function setClosingMotive(?ClosingMotive $closingMotive = null): self
public function setClosingMotive(ClosingMotive $closingMotive = null): self
{
$this->closingMotive = $closingMotive;
@@ -1260,7 +1311,7 @@ class AccompanyingPeriod implements
return $this;
}
public function setCreatedAt(DateTimeInterface $datetime): self
public function setCreatedAt(\DateTimeInterface $datetime): self
{
$this->createdAt = $datetime;
@@ -1298,7 +1349,6 @@ class AccompanyingPeriod implements
/**
* Set openingDate.
*
*
* @return AccompanyingPeriod
*/
public function setOpeningDate(mixed $openingDate)
@@ -1322,7 +1372,7 @@ class AccompanyingPeriod implements
/**
* @Groups({"write"})
*/
public function setPersonLocation(?Person $person = null): self
public function setPersonLocation(Person $person = null): self
{
if ($this->personLocation !== $person) {
$this->personLocation = $person;
@@ -1331,7 +1381,7 @@ class AccompanyingPeriod implements
$this->setAddressLocation(null);
$locationHistory = new AccompanyingPeriodLocationHistory();
$locationHistory
->setStartDate(new DateTimeImmutable('now'))
->setStartDate(new \DateTimeImmutable('now'))
->setPersonLocation($person);
$this->addLocationHistory($locationHistory);
@@ -1344,7 +1394,7 @@ class AccompanyingPeriod implements
/**
* @Groups({"write"})
*/
public function setPinnedComment(?Comment $comment = null): self
public function setPinnedComment(Comment $comment = null): self
{
if (null !== $this->pinnedComment) {
$this->addComment($this->pinnedComment);
@@ -1355,7 +1405,7 @@ class AccompanyingPeriod implements
return $this;
}
public function setRemark(?string $remark = null): self
public function setRemark(string $remark = null): self
{
$this->remark = (string) $remark;
@@ -1369,7 +1419,9 @@ class AccompanyingPeriod implements
* instance of Person
*
* @param $requestor Person|ThirdParty
*
* @throw UnexpectedValueException if the requestor is not a Person or ThirdParty
*
* @Groups({"write"})
*/
public function setRequestor($requestor): self
@@ -1384,7 +1436,7 @@ class AccompanyingPeriod implements
$this->setRequestorPerson(null);
$this->setRequestorThirdParty(null);
} else {
throw new UnexpectedValueException('requestor is not an instance of Person or ThirdParty');
throw new \UnexpectedValueException('requestor is not an instance of Person or ThirdParty');
}
return $this;
@@ -1410,7 +1462,7 @@ class AccompanyingPeriod implements
if (self::STEP_DRAFT !== $this->step && $previous !== $step) {
// we create a new history
$history = new AccompanyingPeriodStepHistory();
$history->setStep($this->step)->setStartDate(new DateTimeImmutable('now'));
$history->setStep($this->step)->setStartDate(new \DateTimeImmutable('now'));
$this->addStepHistory($history);
}
@@ -1418,7 +1470,7 @@ class AccompanyingPeriod implements
return $this;
}
public function setUpdatedAt(DateTimeInterface $datetime): self
public function setUpdatedAt(\DateTimeInterface $datetime): self
{
$this->updatedAt = $datetime;
@@ -1441,7 +1493,7 @@ class AccompanyingPeriod implements
foreach ($this->userHistories as $history) {
if (null === $history->getEndDate()) {
$history->setEndDate(new DateTimeImmutable('now'));
$history->setEndDate(new \DateTimeImmutable('now'));
}
}
@@ -1471,7 +1523,7 @@ class AccompanyingPeriod implements
// first location history
$locationHistory = new AccompanyingPeriodLocationHistory();
$locationHistory
->setStartDate(new DateTimeImmutable('now'))
->setStartDate(new \DateTimeImmutable('now'))
->setPersonLocation($this->getPersonLocation())
->setAddressLocation($this->getAddressLocation());
$this->addLocationHistory($locationHistory);
@@ -1483,7 +1535,7 @@ class AccompanyingPeriod implements
$criteria = new Criteria();
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
/** @var Iterator $steps */
/** @var \Iterator $steps */
$steps = $this->getStepHistories()->matching($criteria)->getIterator();
$steps->rewind();
@@ -1498,7 +1550,7 @@ class AccompanyingPeriod implements
if ($this->getOpeningDate()->format('Y-m-d') !== $current->getStartDate()->format('Y-m-d')
&& ($this->getOpeningDate() <= $current->getEndDate() || null === $current->getEndDate())) {
$current->setStartDate(DateTimeImmutable::createFromMutable($this->getOpeningDate()));
$current->setStartDate(\DateTimeImmutable::createFromMutable($this->getOpeningDate()));
}
// then we set all the end date to the start date of the next one
@@ -1514,14 +1566,14 @@ class AccompanyingPeriod implements
} while ($steps->valid());
}
private function setRequestorPerson(?Person $requestorPerson = null): self
private function setRequestorPerson(Person $requestorPerson = null): self
{
$this->requestorPerson = $requestorPerson;
return $this;
}
private function setRequestorThirdParty(?ThirdParty $requestorThirdParty = null): self
private function setRequestorThirdParty(ThirdParty $requestorThirdParty = null): self
{
$this->requestorThirdParty = $requestorThirdParty;

View File

@@ -16,7 +16,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\Mapping as ORM;
/**
* Informations about AccompanyingPeriod
* Informations about AccompanyingPeriod.
*
* This entity allow access to some basic information about the AccompanyingPeriod. It is
* populated from a SQL view, dynamically build from various sources.
@@ -26,6 +26,7 @@ use Doctrine\ORM\Mapping as ORM;
* - get the user involved with an accompanying period
*
* @ORM\Entity()
*
* @ORM\Table(name="view_chill_person_accompanying_period_info")
*/
class AccompanyingPeriodInfo
@@ -33,44 +34,53 @@ class AccompanyingPeriodInfo
public function __construct(
/**
* @var AccompanyingPeriod
*
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
*/
public readonly AccompanyingPeriod $accompanyingPeriod,
/**
* @var string
*
* @ORM\Column(type="text")
*
* @ORM\Id
*/
public readonly string $relatedEntity,
/**
* @var int
*
* @ORM\Column(type="integer")
*
* @ORM\Id
*/
public readonly int $relatedEntityId,
/**
* @var User
*
* @ORM\ManyToOne(targetEntity=User::class)
*/
public readonly ?User $user,
public readonly ?User $user,
/**
* @var \DateTimeImmutable
*
* @ORM\Column(type="datetime_immutable")
*/
public readonly \DateTimeImmutable $infoDate,
/**
* @var array
*
* @ORM\Column(type="json")
*/
public readonly array $metadata,
/**
* @var string
*
* @ORM\Column(type="text")
*/
public readonly string $discriminator,

View File

@@ -16,11 +16,11 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*
* @ORM\Table("chill_person_accompanying_period_location_history")
*/
class AccompanyingPeriodLocationHistory implements TrackCreationInterface
@@ -35,11 +35,13 @@ class AccompanyingPeriodLocationHistory implements TrackCreationInterface
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
@@ -57,14 +59,14 @@ class AccompanyingPeriodLocationHistory implements TrackCreationInterface
/**
* @ORM\Column(type="date_immutable")
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function getAddressLocation(): ?Address
{
return $this->addressLocation;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -84,7 +86,7 @@ class AccompanyingPeriodLocationHistory implements TrackCreationInterface
return $this->personLocation;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -96,7 +98,7 @@ class AccompanyingPeriodLocationHistory implements TrackCreationInterface
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): AccompanyingPeriodLocationHistory
public function setEndDate(?\DateTimeImmutable $endDate): AccompanyingPeriodLocationHistory
{
$this->endDate = $endDate;
@@ -120,7 +122,7 @@ class AccompanyingPeriodLocationHistory implements TrackCreationInterface
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): AccompanyingPeriodLocationHistory
public function setStartDate(?\DateTimeImmutable $startDate): AccompanyingPeriodLocationHistory
{
$this->startDate = $startDate;

View File

@@ -17,11 +17,11 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*
* @ORM\Table("chill_person_accompanying_period_step_history")
*/
class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpdateInterface
@@ -33,11 +33,13 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
@@ -50,14 +52,14 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
/**
* @ORM\Column(type="date_immutable")
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="text", nullable=false)
*/
private string $step;
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -72,7 +74,7 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
return $this->period;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -82,7 +84,7 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
return $this->step;
}
public function setEndDate(?DateTimeImmutable $endDate): self
public function setEndDate(?\DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
@@ -99,7 +101,7 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): self
public function setStartDate(?\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;

View File

@@ -22,19 +22,18 @@ use Chill\PersonBundle\Entity\SocialWork\Result;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_work")
*
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
@@ -46,7 +45,9 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
{
/**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
*
* @Serializer\Groups({"read", "read:accompanyingPeriodWork:light"})
*
* @Serializer\Context(normalizationContext={"groups": {"read"}}, groups={"read:accompanyingPeriodWork:light"})
*/
private ?AccompanyingPeriod $accompanyingPeriod = null;
@@ -58,8 +59,11 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
* cascade={"remove", "persist"},
* orphanRemoval=true
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @ORM\OrderBy({"startDate": "DESC", "id": "DESC"})
*
* @var Collection<AccompanyingPeriodWorkEvaluation>
*
* @internal /!\ the serialization for write evaluations is handled in `AccompanyingPeriodWorkDenormalizer`
@@ -68,48 +72,57 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\Column(type="datetime_immutable")
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*/
private ?DateTimeImmutable $createdAt = null;
private ?\DateTimeImmutable $createdAt = null;
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*/
private bool $createdAutomatically = false;
/**
* @ORM\Column(type="text")
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*/
private string $createdAutomaticallyReason = '';
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*/
private ?User $createdBy = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*
* @Assert\GreaterThanOrEqual(propertyPath="startDate",
* message="accompanying_course_work.The endDate should be greater or equal than the start date"
* )
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @var Collection<AccompanyingPeriodWorkGoal>
*
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWorkGoal::class,
* mappedBy="accompanyingPeriodWork",
* cascade={"persist"},
* orphanRemoval=true
* )
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
@@ -117,6 +130,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*
@@ -126,22 +140,29 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light", "read:evaluation:include-work"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="text")
*
* @Serializer\Groups({"read", "accompanying_period_work:edit", "docgen:read"})
*/
private string $note = '';
/**
* @var Collection<Person>
*
* @ORM\ManyToMany(targetEntity=Person::class)
*
* @ORM\JoinTable(name="chill_person_accompanying_period_work_person")
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"accompanying_period_work:create"})
@@ -150,20 +171,25 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable", columnPrefix="privateComment_")
*
* @Serializer\Groups({"read", "accompanying_period_work:edit"})
*/
private PrivateCommentEmbeddable $privateComment;
/**
* @var Collection<int, AccompanyingPeriodWorkReferrerHistory>
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodWorkReferrerHistory::class, cascade={"persist", "remove"}, mappedBy="accompanyingPeriodWork", orphanRemoval=true)
*/
private Collection $referrersHistory;
/**
* @var Collection<Result>
*
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
*
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
@@ -171,26 +197,32 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\ManyToOne(targetEntity=SocialAction::class)
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
* @Serializer\Groups({"accompanying_period_work:create"})
*
* @Serializer\Context(normalizationContext={"groups": {"read"}}, groups={"read:accompanyingPeriodWork:light"})
*/
private ?SocialAction $socialAction = null;
/**
* @ORM\Column(type="date_immutable")
*
* @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
/**
* @var Collection<ThirdParty>
*
* @ORM\ManyToMany(targetEntity=ThirdParty::class)
*
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
*
* In schema : intervenants
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
@@ -198,13 +230,16 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @ORM\Column(type="datetime_immutable")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?DateTimeImmutable $updatedAt = null;
private ?\DateTimeImmutable $updatedAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?User $updatedBy = null;
@@ -253,7 +288,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
{
if (!$this->getReferrers()->contains($referrer)) {
$this->referrersHistory[] =
new AccompanyingPeriodWorkReferrerHistory($this, $referrer, new DateTimeImmutable('today'));
new AccompanyingPeriodWorkReferrerHistory($this, $referrer, new \DateTimeImmutable('today'));
}
return $this;
@@ -290,7 +325,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this->accompanyingPeriodWorkEvaluations;
}
public function getCreatedAt(): ?DateTimeImmutable
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
@@ -310,7 +345,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this->createdBy;
}
public function getEndDate(): ?DateTimeInterface
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
@@ -350,6 +385,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @return ReadableCollection<int, User>
*
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"accompanying_period_work:create"})
@@ -366,7 +402,6 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this->referrersHistory;
}
/**
* @return Collection<int, Result>
*/
@@ -385,7 +420,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return new ArrayCollection([$this->getSocialAction()->getIssue()]);
}
public function getStartDate(): ?DateTimeInterface
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
@@ -403,7 +438,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this->getThirdParties();
}
public function getUpdatedAt(): ?DateTimeImmutable
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
@@ -445,7 +480,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
{
foreach ($this->referrersHistory as $history) {
if ($history->isOpen() && $referrer === $history->getUser()) {
$history->setEndDate(new DateTimeImmutable('today'));
$history->setEndDate(new \DateTimeImmutable('today'));
if ($history->isDateRangeEmpty()) {
$history->removeAccompanyingPeriodWork();
@@ -488,7 +523,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
$this->accompanyingPeriod instanceof AccompanyingPeriod
&& $accompanyingPeriod !== $this->accompanyingPeriod
) {
throw new LogicException('A work cannot change accompanyingPeriod');
throw new \LogicException('A work cannot change accompanyingPeriod');
}
$this->accompanyingPeriod = $accompanyingPeriod;
@@ -496,7 +531,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this;
}
public function setCreatedAt(DateTimeInterface $createdAt): self
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
@@ -524,7 +559,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this;
}
public function setEndDate(?DateTimeInterface $endDate = null): self
public function setEndDate(\DateTimeInterface $endDate = null): self
{
$this->endDate = $endDate;
@@ -559,14 +594,14 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
return $this;
}
public function setStartDate(DateTimeInterface $startDate): self
public function setStartDate(\DateTimeInterface $startDate): self
{
$this->startDate = $startDate;
return $this;
}
public function setUpdatedAt(DateTimeInterface $datetime): TrackUpdateInterface
public function setUpdatedAt(\DateTimeInterface $datetime): TrackUpdateInterface
{
$this->updatedAt = $datetime;

View File

@@ -16,18 +16,16 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
use DateInterval;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use RuntimeException;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table("chill_person_accompanying_period_work_evaluation")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_work_evaluation": AccompanyingPeriodWorkEvaluation::class,
* })
@@ -39,13 +37,16 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
* targetEntity=AccompanyingPeriodWork::class,
* inversedBy="accompanyingPeriodWorkEvaluations"
* )
*
* @Serializer\Groups({"read:evaluation:include-work"})
*
* @Serializer\Context(normalizationContext={"groups": {"read:accompanyingPeriodWork:light"}}, groups={"read:evaluation:include-work"})
*/
private ?AccompanyingPeriodWork $accompanyingPeriodWork = null;
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
@@ -54,14 +55,16 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?DateTimeImmutable $createdAt = null;
private ?\DateTimeImmutable $createdAt = null;
/**
* @ORM\ManyToOne(
* targetEntity=User::class
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?User $createdBy = null;
@@ -77,24 +80,29 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
* cascade={"remove", "persist"},
* orphanRemoval=true
* )
*
* @ORM\OrderBy({"createdAt": "DESC", "id": "DESC"})
*
* @Serializer\Groups({"read"})
*
* @var Collection<AccompanyingPeriodWorkEvaluationDocument>
*/
private Collection $documents;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\ManyToOne(
* targetEntity=Evaluation::class
* )
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
@@ -102,8 +110,11 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
@@ -118,51 +129,55 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*
* @var mixed
*/
private $key;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
private ?DateTimeImmutable $maxDate = null;
private ?\DateTimeImmutable $maxDate = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?DateTimeImmutable $updatedAt = null;
private ?\DateTimeImmutable $updatedAt = null;
/**
* @ORM\ManyToOne(
* targetEntity=User::class
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?User $updatedBy = null;
/**
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
private ?DateInterval $warningInterval = null;
private ?\DateInterval $warningInterval = null;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @Serializer\Groups({"read", "docgen:read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
@@ -194,7 +209,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this->comment;
}
public function getCreatedAt(): ?DateTimeImmutable
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
@@ -212,7 +227,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this->documents;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -229,25 +244,23 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
/**
* Arbitrary data, used for client.
*
* @return mixed
*/
public function getKey()
{
return $this->key;
}
public function getMaxDate(): ?DateTimeImmutable
public function getMaxDate(): ?\DateTimeImmutable
{
return $this->maxDate;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
public function getUpdatedAt(): ?DateTimeImmutable
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
@@ -260,7 +273,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
/**
* @Serializer\Groups({"docgen:read"})
*/
public function getWarningDate(): ?DateTimeImmutable
public function getWarningDate(): ?\DateTimeImmutable
{
if (null === $this->getEndDate() || null === $this->getWarningInterval()) {
return null;
@@ -269,7 +282,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this->getEndDate()->sub($this->getWarningInterval());
}
public function getWarningInterval(): ?DateInterval
public function getWarningInterval(): ?\DateInterval
{
return $this->warningInterval;
}
@@ -294,8 +307,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
&& $this->accompanyingPeriodWork instanceof AccompanyingPeriodWork
&& $this->accompanyingPeriodWork->getId() !== $accompanyingPeriodWork->getId()
) {
throw new RuntimeException('Changing the ' .
'accompanyingPeriodWork is not allowed');
throw new \RuntimeException('Changing the accompanyingPeriodWork is not allowed');
}
$this->accompanyingPeriodWork = $accompanyingPeriodWork;
@@ -311,11 +323,9 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
}
/**
* @param DateTimeImmutable|null $createdAt
*
* @return AccompanyingPeriodWorkEvaluation
* @param \DateTimeImmutable|null $createdAt
*/
public function setCreatedAt(DateTimeInterface $createdAt): self
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
@@ -329,7 +339,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): AccompanyingPeriodWorkEvaluation
public function setEndDate(?\DateTimeImmutable $endDate): AccompanyingPeriodWorkEvaluation
{
$this->endDate = $endDate;
@@ -354,7 +364,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
) {
$cl = AccompanyingPeriodWorkEvaluation::class;
throw new LogicException("once set, an {$cl} cannot
throw new \LogicException("once set, an {$cl} cannot
change or remove the linked Evaluation::class");
}
@@ -365,8 +375,6 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
/**
* Arbitrary data, used for client.
*
*
*/
public function setKey(mixed $key): self
{
@@ -375,14 +383,14 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this;
}
public function setMaxDate(?DateTimeImmutable $maxDate): AccompanyingPeriodWorkEvaluation
public function setMaxDate(?\DateTimeImmutable $maxDate): AccompanyingPeriodWorkEvaluation
{
$this->maxDate = $maxDate;
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): AccompanyingPeriodWorkEvaluation
public function setStartDate(?\DateTimeImmutable $startDate): AccompanyingPeriodWorkEvaluation
{
$this->startDate = $startDate;
@@ -390,11 +398,9 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
}
/**
* @param DateTimeImmutable|null $updatedAt
*
* @return AccompanyingPeriodWorkEvaluation
* @param \DateTimeImmutable|null $updatedAt
*/
public function setUpdatedAt(DateTimeInterface $updatedAt): self
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
@@ -408,7 +414,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
return $this;
}
public function setWarningInterval(?DateInterval $warningInterval): AccompanyingPeriodWorkEvaluation
public function setWarningInterval(?\DateInterval $warningInterval): AccompanyingPeriodWorkEvaluation
{
$this->warningInterval = $warningInterval;

View File

@@ -16,13 +16,14 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Doctrine\ORM\Mapping as ORM;
use RuntimeException;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table("chill_person_accompanying_period_work_evaluation_document")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_work_evaluation_document": AccompanyingPeriodWorkEvaluationDocument::class
* })
@@ -43,11 +44,15 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @internal the default name exceeds 64 characters, we must set manually:
*
* @ORM\SequenceGenerator(sequenceName="chill_person_social_work_eval_doc_id_seq", allocationSize=1, initialValue=1000)
*
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
@@ -63,8 +68,6 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*
* @var mixed
*/
private $key;
@@ -72,9 +75,11 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
* @ORM\ManyToOne(
* targetEntity=StoredObject::class,
* )
*
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*
* @Assert\Valid
*/
private ?StoredObject $storedObject = null;
@@ -83,6 +88,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
* @ORM\ManyToOne(
* targetEntity=DocGeneratorTemplate::class
* )
*
* @Serializer\Groups({"read"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
*/
@@ -90,6 +96,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
*
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
@@ -106,9 +113,6 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
return $this->id;
}
/**
* @return mixed
*/
public function getKey()
{
return $this->key;
@@ -138,7 +142,7 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
&& $accompanyingPeriodWorkEvaluation instanceof AccompanyingPeriodWorkEvaluation
) {
if ($this->accompanyingPeriodWorkEvaluation !== $accompanyingPeriodWorkEvaluation) {
throw new RuntimeException('It is not allowed to change the evaluation for a document');
throw new \RuntimeException('It is not allowed to change the evaluation for a document');
}
}
$this->accompanyingPeriodWorkEvaluation = $accompanyingPeriodWorkEvaluation;

View File

@@ -16,12 +16,13 @@ use Chill\PersonBundle\Entity\SocialWork\Result;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_work_goal")
*
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
@@ -38,6 +39,7 @@ class AccompanyingPeriodWorkGoal
/**
* @ORM\ManyToOne(targetEntity=Goal::class)
*
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read", "docgen:read"})
*/
@@ -45,14 +47,18 @@ class AccompanyingPeriodWorkGoal
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="text")
*
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read"})
*/
@@ -60,8 +66,11 @@ class AccompanyingPeriodWorkGoal
/**
* @var Collection<Result>
*
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
*
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
*
* @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read", "docgen:read"})
*/
@@ -123,7 +132,7 @@ class AccompanyingPeriodWorkGoal
&& $accompanyingPeriodWork !== $this->accompanyingPeriodWork
&& null !== $accompanyingPeriodWork
) {
throw new LogicException('Change accompanying period work is not allowed');
throw new \LogicException('Change accompanying period work is not allowed');
}
$this->accompanyingPeriodWork = $accompanyingPeriodWork;

View File

@@ -20,6 +20,7 @@ use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_work_referrer")
*/
class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, TrackUpdateInterface
@@ -29,13 +30,14 @@ class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, T
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @var \DateTimeImmutable|null
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?\DateTimeImmutable $endDate = null;
@@ -47,11 +49,13 @@ class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, T
private ?AccompanyingPeriodWork $accompanyingPeriodWork,
/**
* @var User
*
* @ORM\ManyToOne(targetEntity=User::class)
*/
private User $user,
/**
* @var \DateTimeImmutable
*
* @ORM\Column(type="date_immutable", nullable=false)
*/
private \DateTimeImmutable $startDate
@@ -70,6 +74,7 @@ class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, T
public function setEndDate(?\DateTimeImmutable $endDate): AccompanyingPeriodWorkReferrerHistory
{
$this->endDate = $endDate;
return $this;
}
@@ -89,9 +94,7 @@ class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, T
}
/**
* to be used when the history is removed (when startDate = endDate)
*
* @return self
* to be used when the history is removed (when startDate = endDate).
*/
public function removeAccompanyingPeriodWork(): self
{
@@ -111,7 +114,7 @@ class AccompanyingPeriodWorkReferrerHistory implements TrackCreationInterface, T
/**
* return true if the date range is empty (start date and end date are equal).
*
* @return bool true if the start date and end date are equal.
* @return bool true if the start date and end date are equal
*/
public function isDateRangeEmpty(): bool
{

View File

@@ -20,6 +20,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
* ClosingMotive give an explanation why we closed the Accompanying period.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_closingmotive")
*/
class ClosingMotive
@@ -33,6 +34,7 @@ class ClosingMotive
* Child Accompanying periods.
*
* @var Collection<ClosingMotive>
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
* mappedBy="parent")
@@ -40,18 +42,21 @@ class ClosingMotive
private Collection $children;
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Serializer\Groups({"docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $name = [];
@@ -62,8 +67,6 @@ class ClosingMotive
private float $ordering = 0.0;
/**
* @var self
*
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
* inversedBy="children")
@@ -155,7 +158,7 @@ class ClosingMotive
public function isLeaf(): bool
{
return $this->children->count() === 0;
return 0 === $this->children->count();
}
public function isParent(): bool
@@ -229,7 +232,7 @@ class ClosingMotive
$this->parent = $parent;
if (null !== $parent) {
//$parent->addChildren($this);
// $parent->addChildren($this);
}
return $this;

View File

@@ -15,7 +15,6 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
@@ -23,7 +22,9 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_comment")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_comment": Comment::class
* })
@@ -34,48 +35,61 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
* inversedBy="comments")
*
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private ?AccompanyingPeriod $accompanyingPeriod = null;
/**
* @ORM\Column(type="text")
*
* @Groups({"read", "write", "docgen:read"})
*
* @Assert\NotBlank
*
* @Assert\NotNull
*/
private ?string $content = null;
/**
* @ORM\Column(type="datetime")
*
* @Groups({"read", "docgen:read"})
*/
private ?DateTimeInterface $createdAt = null;
private ?\DateTimeInterface $createdAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"read", "docgen:read"})
*/
private ?User $creator = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="datetime")
*
* @Groups({"read"})
*/
private ?DateTimeInterface $updatedAt = null;
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"read"})
*/
private ?User $updatedBy = null;
@@ -90,7 +104,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
return $this->content;
}
public function getCreatedAt(): ?DateTimeInterface
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
@@ -105,7 +119,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
return $this->id;
}
public function getUpdatedAt(): ?DateTimeInterface
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
@@ -134,7 +148,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function setCreatedAt(DateTimeInterface $createdAt): self
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
@@ -153,7 +167,7 @@ class Comment implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function setUpdatedAt(DateTimeInterface $updatedAt): self
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;

View File

@@ -11,13 +11,14 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_origin")
*
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
@@ -28,24 +29,30 @@ class Origin
{
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $label = [];
/**
* @ORM\Column(type="date_immutable", nullable=true)
*
* @Serializer\Groups({"read"})
*/
private ?DateTimeImmutable $noActiveAfter = null;
private ?\DateTimeImmutable $noActiveAfter = null;
public function getId(): ?int
{
@@ -57,7 +64,7 @@ class Origin
return $this->label;
}
public function getNoActiveAfter(): ?DateTimeImmutable
public function getNoActiveAfter(): ?\DateTimeImmutable
{
return $this->noActiveAfter;
}
@@ -69,7 +76,7 @@ class Origin
return $this;
}
public function setNoActiveAfter(?DateTimeImmutable $noActiveAfter): self
public function setNoActiveAfter(?\DateTimeImmutable $noActiveAfter): self
{
$this->noActiveAfter = $noActiveAfter;

View File

@@ -17,19 +17,21 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use UnexpectedValueException;
/**
* **About denormalization**: this operation is operated by @see{AccompanyingPeriodResourdeNormalizer}.
*
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_accompanying_period_resource",
* uniqueConstraints={
*
* @ORM\UniqueConstraint(name="person_unique", columns={"person_id", "accompanyingperiod_id"}),
* @ORM\UniqueConstraint(name="thirdparty_unique", columns={"thirdparty_id", "accompanyingperiod_id"})
* }
* )
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_resource": Resource::class
* })
@@ -41,34 +43,43 @@ class Resource
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
* inversedBy="resources"
* )
*
* @ORM\JoinColumn(nullable=false)
*/
private ?AccompanyingPeriod $accompanyingPeriod = null;
/**
* @ORM\Column(type="text", nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?string $comment = '';
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"docgen:read"})
*/
private ?Person $person = null;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"docgen:read"})
*/
private ?ThirdParty $thirdParty = null;
@@ -113,7 +124,7 @@ class Resource
return $this;
}
public function setComment(?string $comment = null): self
public function setComment(string $comment = null): self
{
$this->comment = (string) $comment;
@@ -135,12 +146,7 @@ class Resource
$this->setPerson(null);
$this->setThirdParty(null);
} else {
throw new UnexpectedValueException(sprintf(
'the resource ' .
'should be an instance of %s or %s',
Person::class,
ThirdParty::class
));
throw new \UnexpectedValueException(sprintf('the resource should be an instance of %s or %s', Person::class, ThirdParty::class));
}
return $this;

View File

@@ -15,11 +15,11 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*
* @ORM\Table("chill_person_accompanying_period_user_history")
*/
class UserHistory implements TrackCreationInterface
@@ -29,11 +29,13 @@ class UserHistory implements TrackCreationInterface
/**
* @ORM\Column(type="datetime_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -41,11 +43,13 @@ class UserHistory implements TrackCreationInterface
public function __construct(
/**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, inversedBy="userHistories")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod,
private ?AccompanyingPeriod $accompanyingPeriod,
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private User $user,
@@ -53,7 +57,7 @@ class UserHistory implements TrackCreationInterface
/**
* @ORM\Column(type="datetime_immutable", nullable=false, options={"default": "now()"})
*/
private DateTimeImmutable $startDate = new DateTimeImmutable('now')
private \DateTimeImmutable $startDate = new \DateTimeImmutable('now')
) {}
public function getAccompanyingPeriod(): AccompanyingPeriod
@@ -61,7 +65,7 @@ class UserHistory implements TrackCreationInterface
return $this->accompanyingPeriod;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -71,7 +75,7 @@ class UserHistory implements TrackCreationInterface
return $this->id;
}
public function getStartDate(): DateTimeImmutable
public function getStartDate(): \DateTimeImmutable
{
return $this->startDate;
}
@@ -81,7 +85,7 @@ class UserHistory implements TrackCreationInterface
return $this->user;
}
public function setEndDate(?DateTimeImmutable $endDate): UserHistory
public function setEndDate(?\DateTimeImmutable $endDate): UserHistory
{
$this->endDate = $endDate;

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
@@ -21,7 +19,9 @@ use Symfony\Component\Serializer\Annotation\Groups;
* AccompanyingPeriodParticipation Class.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_accompanying_period_participation")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "accompanying_period_participation": AccompanyingPeriodParticipation::class
* })
@@ -30,36 +30,44 @@ class AccompanyingPeriodParticipation
{
/**
* @ORM\Column(type="date", nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?DateTime $endDate = null;
private ?\DateTime $endDate = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="date", nullable=false)
*
* @Groups({"read", "docgen:read"})
*/
private ?DateTime $startDate = null;
private ?\DateTime $startDate = null;
public function __construct(/**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, inversedBy="participations", cascade={"persist"})
*
* @ORM\JoinColumn(name="accompanyingperiod_id", referencedColumnName="id", nullable=false)
*/
private ?\Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod, /**
private ?AccompanyingPeriod $accompanyingPeriod, /**
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodParticipations")
*
* @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false)
*
* @Groups({"read", "docgen:read"})
*/
private ?\Chill\PersonBundle\Entity\Person $person
private ?Person $person
) {
$this->startDate = new DateTime('now');
$this->startDate = new \DateTime('now');
$person->getAccompanyingPeriodParticipations()->add($this);
}
@@ -68,7 +76,7 @@ class AccompanyingPeriodParticipation
return $this->accompanyingPeriod;
}
public function getEndDate(): ?DateTimeInterface
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
@@ -83,7 +91,7 @@ class AccompanyingPeriodParticipation
return $this->person;
}
public function getStartDate(): ?DateTimeInterface
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
@@ -100,7 +108,7 @@ class AccompanyingPeriodParticipation
return $this;
}
public function setEndDate(?DateTime $endDate): self
public function setEndDate(?\DateTime $endDate): self
{
$this->endDate = $endDate;

View File

@@ -18,5 +18,5 @@ interface HasPerson
{
public function getPerson(): ?Person;
public function setPerson(?Person $person = null): HasPerson;
public function setPerson(Person $person = null): HasPerson;
}

View File

@@ -11,14 +11,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Household;
use ArrayIterator;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
@@ -27,18 +23,19 @@ use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function count;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household": Household::class
* })
*
* @MaxHolder(groups={"household_memberships"})
*/
class Household
@@ -47,11 +44,15 @@ class Household
* Addresses.
*
* @var Collection<Address>
*
* @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove", "merge", "detach"})
*
* @ORM\JoinTable(name="chill_person_household_to_addresses")
*
* @ORM\OrderBy({"validFrom": "DESC", "id": "DESC"})
*
* @Serializer\Groups({"write"})
*/
private Collection $addresses;
@@ -63,46 +64,56 @@ class Household
/**
* @var Collection&Selectable<int, HouseholdComposition>
*
* @ORM\OneToMany(
* targetEntity=HouseholdComposition::class,
* mappedBy="household",
* orphanRemoval=true,
* cascade={"persist"}
* )
*
* @ORM\OrderBy({"startDate": "DESC"})
*
* @Assert\Valid(traverse=true, groups={"household_composition"})
*/
private Collection&Selectable $compositions;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @var Collection<HouseholdMember>
*
* @ORM\OneToMany(
* targetEntity=HouseholdMember::class,
* mappedBy="household"
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private Collection $members;
/**
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
*
* @Serializer\Groups({"docgen:read"})
*/
private bool $waitingForBirth = false;
/**
* @ORM\Column(type="date_immutable", name="waiting_for_birth_date", nullable=true, options={"default": null})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $waitingForBirthDate = null;
private ?\DateTimeImmutable $waitingForBirthDate = null;
public function __construct()
{
@@ -200,11 +211,12 @@ class Household
/**
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\SerializedName("current_address")
*/
public function getCurrentAddress(?DateTime $at = null): ?Address
public function getCurrentAddress(\DateTime $at = null): ?Address
{
$at ??= new DateTime('today');
$at ??= new \DateTime('today');
$addrs = $this->getAddresses()->filter(static fn (Address $a) => $a->getValidFrom() <= $at && (
null === $a->getValidTo() || $a->getValidTo() > $at
@@ -219,11 +231,12 @@ class Household
/**
* @Serializer\Groups({"docgen:read"})
*
* @Serializer\SerializedName("current_composition")
*/
public function getCurrentComposition(?DateTimeImmutable $at = null): ?HouseholdComposition
public function getCurrentComposition(\DateTimeImmutable $at = null): ?HouseholdComposition
{
$at ??= new DateTimeImmutable('today');
$at ??= new \DateTimeImmutable('today');
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -249,12 +262,12 @@ class Household
/**
* @Serializer\Groups({"docgen:read"})
*/
public function getCurrentMembers(?DateTimeImmutable $now = null): Collection
public function getCurrentMembers(\DateTimeImmutable $now = null): Collection
{
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
}
public function getCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -270,9 +283,10 @@ class Household
* Used in serialization
*
* @Serializer\Groups({"read"})
*
* @Serializer\SerializedName("current_members_id")
*/
public function getCurrentMembersIds(?DateTimeImmutable $now = null): ReadableCollection
public function getCurrentMembersIds(\DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)->map(
static fn (HouseholdMember $m) => $m->getId()
@@ -282,22 +296,22 @@ class Household
/**
* @return HouseholdMember[]
*/
public function getCurrentMembersOrdered(?DateTimeImmutable $now = null): Collection
public function getCurrentMembersOrdered(\DateTimeImmutable $now = null): Collection
{
$members = $this->getCurrentMembers($now);
$members->getIterator()
->uasort(
static function (HouseholdMember $a, HouseholdMember $b) {
if ($a->getPosition() === null) {
if ($b->getPosition() === null) {
if (null === $a->getPosition()) {
if (null === $b->getPosition()) {
return 0;
}
return -1;
}
if ($b->getPosition() === null) {
if (null === $b->getPosition()) {
return 1;
}
@@ -324,7 +338,7 @@ class Household
return $members;
}
public function getCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
public function getCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -341,7 +355,7 @@ class Household
*
* @return ReadableCollection<(int|string), Person>
*/
public function getCurrentPersons(?DateTimeImmutable $now = null): ReadableCollection
public function getCurrentPersons(\DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)
->map(static fn (HouseholdMember $m) => $m->getPerson());
@@ -387,7 +401,7 @@ class Household
return $this->getMembers()->matching($criteria);
}
public function getMembersOnRange(DateTimeImmutable $from, ?DateTimeImmutable $to): ReadableCollection
public function getMembersOnRange(\DateTimeImmutable $from, ?\DateTimeImmutable $to): ReadableCollection
{
return $this->getMembers()->filter(static function (HouseholdMember $m) use ($from, $to) {
if (null === $m->getEndDate() && null !== $to) {
@@ -410,11 +424,11 @@ class Household
});
}
public function getNonCurrentMembers(?DateTimeImmutable $now = null): Collection
public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now ?? new DateTimeImmutable('today');
$date = $now ?? new \DateTimeImmutable('today');
$criteria
->where(
@@ -430,7 +444,7 @@ class Household
return $this->getMembers()->matching($criteria);
}
public function getNonCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -440,7 +454,7 @@ class Household
return $this->getNonCurrentMembers($now)->matching($criteria);
}
public function getNonCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
public function getNonCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -474,7 +488,7 @@ class Household
public function getPreviousAddressOf(Address $address): ?Address
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator = new \ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
while ($iterator->valid()) {
@@ -496,7 +510,7 @@ class Household
return $this->waitingForBirth;
}
public function getWaitingForBirthDate(): ?DateTimeImmutable
public function getWaitingForBirthDate(): ?\DateTimeImmutable
{
return $this->waitingForBirthDate;
}
@@ -513,7 +527,7 @@ class Household
static fn (HouseholdComposition $a, HouseholdComposition $b) => $a->getStartDate() <=> $b->getStartDate()
);
$iterator = new ArrayIterator($compositionOrdered);
$iterator = new \ArrayIterator($compositionOrdered);
$iterator->rewind();
/** @var ?HouseholdComposition $previous */
@@ -535,7 +549,7 @@ class Household
public function makeAddressConsistent(): void
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator = new \ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
@@ -597,7 +611,7 @@ class Household
*/
public function setForceAddress(Address $address)
{
$address->setValidFrom(new DateTime('today'));
$address->setValidFrom(new \DateTime('today'));
$this->addAddress($address);
}
@@ -608,7 +622,7 @@ class Household
return $this;
}
public function setWaitingForBirthDate(?DateTimeImmutable $waitingForBirthDate): self
public function setWaitingForBirthDate(?\DateTimeImmutable $waitingForBirthDate): self
{
$this->waitingForBirthDate = $waitingForBirthDate;
@@ -620,7 +634,7 @@ class Household
$addresses = $this->getAddresses();
$cond = true;
for ($i = 0; count($addresses) - 1 > $i; ++$i) {
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
if ($addresses[$i]->getValidFrom() !== $addresses[$i + 1]->getValidTo()) {
$cond = false;
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
@@ -630,11 +644,11 @@ class Household
}
}
private function buildCriteriaCurrentMembers(?DateTimeImmutable $now = null): Criteria
private function buildCriteriaCurrentMembers(\DateTimeImmutable $now = null): Criteria
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now ?? new DateTimeImmutable('today');
$date = $now ?? new \DateTimeImmutable('today');
$criteria
->where($expr->orX(

View File

@@ -16,16 +16,17 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_composition"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_composition_type": HouseholdCompositionType::class
* })
@@ -43,46 +44,59 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Assert\GreaterThanOrEqual(propertyPath="startDate", groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\ManyToOne(targetEntity=Household::class, inversedBy="compositions")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?Household $household = null;
/**
* @ORM\ManyToOne(targetEntity=HouseholdCompositionType::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Serializer\Groups({"docgen:read"})
*/
private ?HouseholdCompositionType $householdCompositionType = null;
private ?HouseholdCompositionType $householdCompositionType = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": null})
*
* @Assert\NotNull
*
* @Assert\GreaterThanOrEqual(0, groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?int $numberOfChildren = null;
/**
* @ORM\Column(type="date_immutable", nullable=false)
*
* @Assert\NotNull(groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function __construct()
{
@@ -94,7 +108,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -119,7 +133,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this->numberOfChildren;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -131,7 +145,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): HouseholdComposition
public function setEndDate(?\DateTimeImmutable $endDate): HouseholdComposition
{
$this->endDate = $endDate;
@@ -163,7 +177,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): HouseholdComposition
public function setStartDate(?\DateTimeImmutable $startDate): HouseholdComposition
{
$this->startDate = $startDate;

View File

@@ -16,9 +16,11 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_composition_type"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_composition_type": HouseholdCompositionType::class
* })
@@ -32,15 +34,20 @@ class HouseholdCompositionType
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $label = [];

View File

@@ -12,14 +12,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Household;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_members"
* )
@@ -28,59 +27,71 @@ class HouseholdMember
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?string $comment = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Assert\GreaterThanOrEqual(
* propertyPath="startDate",
* message="household_membership.The end date must be after start date",
* groups={"household_memberships"}
* )
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private bool $holder = false;
/**
* @var Household
* @ORM\ManyToOne(
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
* )
*
* @Assert\Valid(groups={"household_memberships"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?Household $household = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @var Person
* @ORM\ManyToOne(
* targetEntity="\Chill\PersonBundle\Entity\Person"
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"docgen:person:with-household": false})
*
* @Assert\Valid(groups={"household_memberships"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?Person $person = null;
/**
* @ORM\ManyToOne(targetEntity=Position::class)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?Position $position = null;
@@ -92,17 +103,19 @@ class HouseholdMember
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function getComment(): ?string
{
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -135,14 +148,14 @@ class HouseholdMember
return $this->shareHousehold;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
public function isCurrent(?DateTimeImmutable $at = null): bool
public function isCurrent(\DateTimeImmutable $at = null): bool
{
$at ??= new DateTimeImmutable('now');
$at ??= new \DateTimeImmutable('now');
return $this->getStartDate() < $at && (
null === $this->getEndDate() || $this->getEndDate() > $at
@@ -161,7 +174,7 @@ class HouseholdMember
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate = null): self
public function setEndDate(\DateTimeImmutable $endDate = null): self
{
$this->endDate = $endDate;
@@ -178,8 +191,7 @@ class HouseholdMember
public function setHousehold(?Household $household): self
{
if ($this->household instanceof Household) {
throw new LogicException('You cannot change household ' .
'on a membership');
throw new \LogicException('You cannot change household on a membership');
}
$this->household = $household;
@@ -190,8 +202,7 @@ class HouseholdMember
public function setPerson(?Person $person): self
{
if ($this->person instanceof Person) {
throw new LogicException('You cannot change person ' .
'on a membership');
throw new \LogicException('You cannot change person on a membership');
}
$this->person = $person;
@@ -203,8 +214,7 @@ class HouseholdMember
public function setPosition(?Position $position): self
{
if ($this->position instanceof Position && $this->position !== $position) {
throw new LogicException('The position is already set. You cannot change ' .
'a position of a membership');
throw new \LogicException('The position is already set. You cannot change a position of a membership');
}
$this->position = $position;
@@ -223,7 +233,7 @@ class HouseholdMember
return $this;
}
public function setStartDate(DateTimeImmutable $startDate): self
public function setStartDate(\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;

View File

@@ -13,8 +13,6 @@ namespace Chill\PersonBundle\Entity\Household;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -42,27 +40,34 @@ use Doctrine\ORM\Mapping as ORM;
* 3. 3st entity: from 2021-12-01 to NULL, household V, address T;
*
* @ORM\Entity(readOnly=true)
*
* @ORM\Table(name="view_chill_person_household_address")
*/
class PersonHouseholdAddress
{
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Address::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\MainBundle\Entity\Address $address = null;
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Household::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\PersonBundle\Entity\Household\Household $household = null;
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\PersonBundle\Entity\Person $person = null;
@@ -98,7 +103,7 @@ class PersonHouseholdAddress
* (this is not the startdate of the household, not
* the startdate of the address)
*/
public function getValidFrom(): ?DateTimeInterface
public function getValidFrom(): ?\DateTimeInterface
{
return $this->validFrom;
}
@@ -109,7 +114,7 @@ class PersonHouseholdAddress
* (this is not the enddate of the household, not
* the enddate of the address)
*/
public function getValidTo(): ?DateTimeImmutable
public function getValidTo(): ?\DateTimeImmutable
{
return $this->validTo;
}

View File

@@ -16,7 +16,9 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_household_position")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_position": Position::class
* })
@@ -25,33 +27,41 @@ class Position
{
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({ "read" })
*/
private bool $allowHolder = false;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $label = [];
/**
* @ORM\Column(type="float")
*
* @Serializer\Groups({"read"})
*/
private float $ordering = 0.00;
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({"read"})
*/
private bool $shareHouseHold = true;

View File

@@ -17,15 +17,16 @@ use Doctrine\ORM\Mapping as ORM;
* MaritalStatus.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_marital_status")
*
* @ORM\HasLifecycleCallbacks
*/
class MaritalStatus
{
/**
* @var string
*
* @ORM\Id
*
* @ORM\Column(type="string", length=7)
*/
private ?string $id;

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity;
use ArrayIterator;
use Chill\BudgetBundle\Entity\Charge;
use Chill\BudgetBundle\Entity\Resource;
use Chill\CalendarBundle\Entity\Calendar;
@@ -37,27 +36,23 @@ use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequen
use Chill\PersonBundle\Validator\Constraints\Person\Birthdate;
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use UnexpectedValueException;
use function count;
use function in_array;
/**
* Person Class.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_person",
* indexes={
*
* @ORM\Index(
* name="person_names",
* columns={"firstName", "lastName"}
@@ -67,11 +62,15 @@ use function in_array;
* columns={"birthdate"}
* )
* })
*
* @ORM\HasLifecycleCallbacks
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "person": Person::class
* })
*
* @PersonHasCenter
*
* @HouseholdMembershipSequential(
* groups={"household_memberships"}
* )
@@ -94,8 +93,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Accept receiving email.
*
* @var bool
*
* @ORM\Column(type="boolean", options={"default": false})
*/
private ?bool $acceptEmail = false;
@@ -103,8 +100,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Accept short text message (aka SMS).
*
* @var bool
*
* @ORM\Column(type="boolean", options={"default": false})
*/
private ?bool $acceptSMS = false;
@@ -117,6 +112,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
* mappedBy="person",
* cascade={"persist", "remove", "merge", "detach"})
*
* @ORM\OrderBy({"startDate": "DESC"})
*/
private Collection $accompanyingPeriodParticipations;
@@ -139,7 +135,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove", "merge", "detach"})
*
* @ORM\JoinTable(name="chill_person_persons_to_addresses")
*
* @ORM\OrderBy({"validFrom": "DESC"})
*/
private Collection $addresses;
@@ -159,12 +157,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's birthdate.
*
* @ORM\Column(type="date", nullable=true)
*
* @Birthdate
*/
private ?\DateTime $birthdate = null;
/**
* @var Collection<Charge>
*
* @ORM\OneToMany(
* targetEntity=Charge::class,
* mappedBy="person"
@@ -173,7 +173,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private Collection $budgetCharges;
/**
* @var Collection<Resource>
* @var Collection<resource>
*
* @ORM\OneToMany(
* targetEntity=Resource::class,
* mappedBy="person"
@@ -183,6 +184,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* @var Collection<int, Calendar>
*
* @ORM\ManyToMany(
* targetEntity="Chill\CalendarBundle\Entity\Calendar",
* mappedBy="persons"
@@ -214,7 +216,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Array where customfield's data are stored.
*
*
* @ORM\Column(type="json")
*/
private ?array $cFData = null;
@@ -222,8 +223,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The marital status of the person.
*
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\MainBundle\Entity\Civility $civility = null;
@@ -231,7 +232,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Contact information for contacting the person.
*
*
* @ORM\Column(type="text", nullable=true)
*/
private string $contactInfo = '';
@@ -239,10 +239,10 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's country of birth.
*
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
*
* sf4 check: option inversedBy="birthsIn" return error mapping !!
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\MainBundle\Entity\Country $countryOfBirth = null;
@@ -254,6 +254,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\MainBundle\Entity\User $createdBy = null;
@@ -280,20 +281,21 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's deathdate.
*
* @var DateTimeImmutable
*
* @ORM\Column(type="date_immutable", nullable=true)
*
* @Assert\Date
*
* @Assert\GreaterThanOrEqual(propertyPath="birthdate")
*
* @Assert\LessThanOrEqual("today")
*/
private ?DateTimeImmutable $deathdate = null;
private ?\DateTimeImmutable $deathdate = null;
/**
* The person's email.
*
*
* @ORM\Column(type="text", nullable=true)
*
* @Assert\Email()
*/
private string $email = '';
@@ -302,7 +304,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's first name.
*
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="The firstname cannot be empty")
*
* @Assert\Length(
* max=255,
* )
@@ -320,8 +324,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's gender.
*
*
* @ORM\Column(type="string", length=9, nullable=true)
*
* @Assert\NotNull(message="The gender must be set")
*/
private ?string $gender = null;
@@ -337,6 +341,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* Read-only field, computed by the database.
*
* @var Collection<PersonHouseholdAddress>
*
* @ORM\OneToMany(
* targetEntity=PersonHouseholdAddress::class,
* mappedBy="person"
@@ -358,7 +363,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's id.
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -367,7 +374,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's last name.
*
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="The lastname cannot be empty")
*
* @Assert\Length(
* max=255,
* )
@@ -377,8 +386,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The marital status of the person.
*
*
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\PersonBundle\Entity\MaritalStatus $maritalStatus = null;
@@ -394,14 +403,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The date of the last marital status change of the person.
*
* @ORM\Column(type="date", nullable=true)
*
* @Assert\Date
*/
private ?DateTime $maritalStatusDate = null;
private ?\DateTime $maritalStatusDate = null;
/**
* A remark over the person.
*
*
* @ORM\Column(type="text")
*/
private string $memo = ''; // TO-CHANGE in remark
@@ -410,6 +419,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's mobile phone number.
*
* @PhonenumberConstraint(type="mobile")
*
* @ORM\Column(type="phone_number", nullable=true)
*/
private ?PhoneNumber $mobilenumber = null;
@@ -417,10 +427,10 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's nationality.
*
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
*
* sf4 check: option inversedBy="nationals" return error mapping !!
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\MainBundle\Entity\Country $nationality = null;
@@ -428,8 +438,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Number of children.
*
* @var int
*
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $numberOfChildren = null;
@@ -443,6 +451,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* cascade={"persist", "remove", "merge", "detach"},
* orphanRemoval=true
* )
*
* @Assert\Valid(
* traverse=true,
* )
@@ -454,6 +463,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* targetEntity=AccompanyingPeriod::class,
* mappedBy="personLocation"
* )
*
* @var Collection<AccompanyingPeriod>
*/
private Collection $periodLocatedOn;
@@ -462,6 +472,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's phonenumber.
*
* @ORM\Column(type="phone_number", nullable=true)
*
* @PhonenumberConstraint(
* type="landline",
* )
@@ -471,17 +482,16 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's place of birth.
*
*
* @ORM\Column(type="string", length=255, name="place_of_birth")
*/
private string $placeOfBirth = '';
/**
*
* @deprecated
*
* @ORM\Column(type="boolean")
*/
private bool $proxyAccompanyingPeriodOpenState = false; //TO-DELETE ?
private bool $proxyAccompanyingPeriodOpenState = false; // TO-DELETE ?
/**
* @ORM\OneToMany(targetEntity=PersonResource::class, mappedBy="personOwner")
@@ -496,6 +506,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @var Collection<Language>
*
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\Language")
*
* @ORM\JoinTable(
* name="persons_spoken_languages",
* joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
@@ -539,9 +550,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$this->centerHistory = new ArrayCollection();
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getLabel();
@@ -616,13 +624,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* the person are not collapsing (i.e. have not shared days) or having
* a period after an open period.
*
* @return true | array True if the accompanying periods are not collapsing,
* an array with data for displaying the error
* @return true|array True if the accompanying periods are not collapsing,
* an array with data for displaying the error
*/
public function checkAccompanyingPeriodsAreNotCollapsing(): array|bool
{
$periods = $this->getAccompanyingPeriodsOrdered();
$periodsNbr = count($periods);
$periodsNbr = \count($periods);
$i = 0;
while ($periodsNbr - 1 > $i) {
@@ -661,9 +669,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*
* To check if the Person and its accompanying period are consistent, use validation.
*
* @throws Exception if two lines of the accompanying period are open.
* @throws \Exception if two lines of the accompanying period are open
*/
public function close(?AccompanyingPeriod $accompanyingPeriod = null): void
public function close(AccompanyingPeriod $accompanyingPeriod = null): void
{
$this->proxyAccompanyingPeriodOpenState = false;
}
@@ -701,7 +709,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
}
}
if (0 < count($closeCandidates)) {
if (0 < \count($closeCandidates)) {
return $closeCandidates[0];
}
@@ -725,7 +733,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* * as participant, only for opened participation;
*
* @param bool $asParticipantOpen add participation which are still opened
* @param bool $asRequestor add accompanying period where the person is requestor
* @param bool $asRequestor add accompanying period where the person is requestor
*
* @return AccompanyingPeriod[]|Collection
*/
@@ -737,8 +745,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
if ($asParticipantOpen) {
foreach ($this->getAccompanyingPeriodParticipations()
->map(fn (AccompanyingPeriodParticipation $app) => $app->getAccompanyingPeriod())
as $period
->map(fn (AccompanyingPeriodParticipation $app) => $app->getAccompanyingPeriod()) as $period
) {
if (!$result->contains($period)) {
$result->add($period);
@@ -763,7 +770,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
): int {
// TODO should be optimized to avoid loading accompanying period ?
return $this->getAccompanyingPeriodInvolved($asParticipantOpen, $asRequestor)
->filter(fn (AccompanyingPeriod $p) => $p->getStep() !== AccompanyingPeriod::STEP_DRAFT)
->filter(fn (AccompanyingPeriod $p) => AccompanyingPeriod::STEP_DRAFT !== $p->getStep())
->count();
}
@@ -793,7 +800,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$accompanyingPeriods = [];
foreach ($this->accompanyingPeriodParticipations as $participation) {
/** @var AccompanyingPeriodParticipation $participation */
/* @var AccompanyingPeriodParticipation $participation */
$accompanyingPeriods[] = $participation->getAccompanyingPeriod();
}
@@ -807,7 +814,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
{
$periods = $this->getAccompanyingPeriods();
//order by date :
// order by date :
usort($periods, static function ($a, $b) {
$dateA = $a->getOpeningDate();
$dateB = $b->getOpeningDate();
@@ -845,17 +852,17 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*
* @deprecated since chill2.0, address is linked to the household. Use @see{Person::getCurrentHouseholdAddress}
*
* @throws Exception
* @throws \Exception
*/
public function getAddressAt(?DateTimeInterface $at = null): ?Address
public function getAddressAt(\DateTimeInterface $at = null): ?Address
{
$at ??= new DateTime('now');
$at ??= new \DateTime('now');
if ($at instanceof DateTimeImmutable) {
$at = DateTime::createFromImmutable($at);
if ($at instanceof \DateTimeImmutable) {
$at = \DateTime::createFromImmutable($at);
}
/** @var ArrayIterator $addressesIterator */
/** @var \ArrayIterator $addressesIterator */
$addressesIterator = $this->getAddresses()
->filter(static fn (Address $address): bool => $address->getValidFrom() <= $at)
->getIterator();
@@ -883,12 +890,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*
* If the person has a deathdate, calculate the age at the deathdate.
*
* @param string $at A valid string to create a DateTime.
* @param string $at a valid string to create a DateTime
*/
public function getAge(string $at = 'now'): ?int
{
if ($this->birthdate instanceof DateTimeInterface) {
if ($this->deathdate instanceof DateTimeInterface) {
if ($this->birthdate instanceof \DateTimeInterface) {
if ($this->deathdate instanceof \DateTimeInterface) {
return (int) date_diff($this->birthdate, $this->deathdate)->format('%y');
}
@@ -903,7 +910,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->altNames;
}
public function getBirthdate(): ?DateTime
public function getBirthdate(): ?\DateTime
{
return $this->birthdate;
}
@@ -987,7 +994,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->countryOfBirth;
}
public function getCreatedAt(): ?DateTimeInterface
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
@@ -1015,7 +1022,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
public function getCurrentAccompanyingPeriods(): array
{
$currentAccompanyingPeriods = [];
$currentDate = new DateTime();
$currentDate = new \DateTime();
foreach ($this->accompanyingPeriodParticipations as $participation) {
$endDate = $participation->getEndDate();
@@ -1028,7 +1035,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $currentAccompanyingPeriods;
}
public function getCurrentHousehold(?DateTimeImmutable $at = null): ?Household
public function getCurrentHousehold(\DateTimeImmutable $at = null): ?Household
{
$participation = $this->getCurrentHouseholdParticipationShareHousehold($at);
@@ -1043,11 +1050,11 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* if the given date is 'now', use instead @see{getCurrentPersonAddress}, which is optimized on
* database side.
*/
public function getCurrentHouseholdAddress(?DateTimeImmutable $at = null): ?Address
public function getCurrentHouseholdAddress(\DateTimeImmutable $at = null): ?Address
{
if (
null === $at
|| $at->format('Ymd') === (new DateTime('today'))->format('Ymd')
|| $at->format('Ymd') === (new \DateTime('today'))->format('Ymd')
) {
return $this->currentPersonAddress instanceof PersonCurrentAddress
? $this->currentPersonAddress->getAddress() : null;
@@ -1077,11 +1084,11 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return null;
}
public function getCurrentHouseholdParticipationShareHousehold(?DateTimeImmutable $at = null): ?HouseholdMember
public function getCurrentHouseholdParticipationShareHousehold(\DateTimeImmutable $at = null): ?HouseholdMember
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $at ?? new DateTimeImmutable('today');
$date = $at ?? new \DateTimeImmutable('today');
$datef = $date->format('Y-m-d');
if (
@@ -1121,7 +1128,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->currentPersonAddress->getAddress();
}
public function getDeathdate(): ?DateTimeInterface
public function getDeathdate(): ?\DateTimeInterface
{
return $this->deathdate;
}
@@ -1236,20 +1243,20 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
public function getLabel()
{
return $this->getFirstName() . ' ' . $this->getLastName();
return $this->getFirstName().' '.$this->getLastName();
}
/**
* @deprecated Use @see{Person::getCurrentPersonAddress} or @see{Person::getCurrentHouseholdAddress} instead
*
* @throws Exception
*
* @return false|mixed|null
*
* @throws \Exception
*/
public function getLastAddress(?DateTime $from = null)
public function getLastAddress(\DateTime $from = null)
{
return $this->getCurrentHouseholdAddress(
null !== $from ? DateTimeImmutable::createFromMutable($from) : null
null !== $from ? \DateTimeImmutable::createFromMutable($from) : null
);
}
@@ -1268,7 +1275,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->maritalStatusComment;
}
public function getMaritalStatusDate(): ?DateTimeInterface
public function getMaritalStatusDate(): ?\DateTimeInterface
{
return $this->maritalStatusDate;
}
@@ -1298,7 +1305,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
public function getOpenedAccompanyingPeriod(): ?AccompanyingPeriod
{
if ($this->isOpen() === false) {
if (false === $this->isOpen()) {
return null;
}
@@ -1324,7 +1331,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$criteria = Criteria::create();
$criteria
->andWhere(Criteria::expr()->eq('endDate', null))
->orWhere(Criteria::expr()->gt('endDate', new DateTime('now')));
->orWhere(Criteria::expr()->gt('endDate', new \DateTime('now')));
return $this->getAccompanyingPeriodParticipations()
->matching($criteria)
@@ -1364,7 +1371,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->spokenLanguages;
}
public function getUpdatedAt(): ?DateTimeInterface
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
@@ -1374,7 +1381,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->updatedBy;
}
public function hasCurrentHouseholdAddress(?DateTimeImmutable $at = null): bool
public function hasCurrentHouseholdAddress(\DateTimeImmutable $at = null): bool
{
return null !== $this->getCurrentHouseholdAddress($at);
}
@@ -1390,7 +1397,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
foreach ($this->addresses as $ad) {
$validDate = $ad->getValidFrom()->format('Y-m-d');
if (in_array($validDate, $validYMDDates, true)) {
if (\in_array($validDate, $validYMDDates, true)) {
return true;
}
$validYMDDates[] = $validDate;
@@ -1461,7 +1468,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return false;
}
public function isSharingHousehold(?DateTimeImmutable $at = null): bool
public function isSharingHousehold(\DateTimeImmutable $at = null): bool
{
return null !== $this->getCurrentHousehold($at);
}
@@ -1490,7 +1497,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$participation = $this->participationsContainAccompanyingPeriod($accompanyingPeriod);
if (!null === $participation) {
$participation->setEndDate(new DateTime());
$participation->setEndDate(new \DateTime());
$this->accompanyingPeriodParticipations->removeElement($participation);
}
}
@@ -1555,7 +1562,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
}
/**
* @param DateTime $birthdate
* @param \DateTime $birthdate
*/
public function setBirthdate($birthdate): self
{
@@ -1571,7 +1578,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
public function setCenter(?Center $center): self
{
$modification = new DateTimeImmutable('now');
$modification = new \DateTimeImmutable('now');
foreach ($this->centerHistory as $centerHistory) {
if (null === $centerHistory->getEndDate()) {
@@ -1601,6 +1608,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$this->centerHistory[] = $newCenterHistory;
$newCenterHistory->setPerson($this);
}
return $this;
}
@@ -1611,7 +1619,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setCivility(?Civility $civility = null): self
public function setCivility(Civility $civility = null): self
{
$this->civility = $civility;
@@ -1629,14 +1637,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setCountryOfBirth(?Country $countryOfBirth = null): self
public function setCountryOfBirth(Country $countryOfBirth = null): self
{
$this->countryOfBirth = $countryOfBirth;
return $this;
}
public function setCreatedAt(DateTimeInterface $datetime): self
public function setCreatedAt(\DateTimeInterface $datetime): self
{
$this->createdAt = $datetime;
@@ -1650,7 +1658,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setDeathdate(?DateTimeInterface $deathdate): self
public function setDeathdate(?\DateTimeInterface $deathdate): self
{
$this->deathdate = $deathdate;
@@ -1699,7 +1707,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setMaritalStatus(?MaritalStatus $maritalStatus = null): self
public function setMaritalStatus(MaritalStatus $maritalStatus = null): self
{
$this->maritalStatus = $maritalStatus;
@@ -1713,7 +1721,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setMaritalStatusDate(?DateTimeInterface $maritalStatusDate): self
public function setMaritalStatusDate(?\DateTimeInterface $maritalStatusDate): self
{
$this->maritalStatusDate = $maritalStatusDate;
@@ -1740,7 +1748,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setNationality(?Country $nationality = null): self
public function setNationality(Country $nationality = null): self
{
$this->nationality = $nationality;
@@ -1789,7 +1797,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
public function setUpdatedAt(DateTimeInterface $datetime): self
public function setUpdatedAt(\DateTimeInterface $datetime): self
{
$this->updatedAt = $datetime;
@@ -1810,7 +1818,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
}
$criteria = Criteria::create();
$now = new DateTimeImmutable('now');
$now = new \DateTimeImmutable('now');
$criteria->where(Criteria::expr()->lte('startDate', $now))
->andWhere(Criteria::expr()->orX(
Criteria::expr()->isNull('endDate'),
@@ -1822,7 +1830,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return match ($histories->count()) {
0 => null,
1 => $histories->first(),
default => throw new UnexpectedValueException('It should not contains more than one center at a time'),
default => throw new \UnexpectedValueException('It should not contains more than one center at a time'),
};
}

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -23,7 +22,9 @@ use Doctrine\ORM\Mapping as ORM;
* using a SQL view.
*
* @ORM\Entity(readOnly=true)
*
* @ORM\Table(name="view_chill_person_person_center_history_current")
*
* @psalm-internal Chill\PersonBundle\Entity
*/
class PersonCenterCurrent
@@ -36,10 +37,11 @@ class PersonCenterCurrent
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Id
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
@@ -52,7 +54,7 @@ class PersonCenterCurrent
/**
* @ORM\Column(type="date_immutable", nullable=false)
*/
private DateTimeImmutable $startDate;
private \DateTimeImmutable $startDate;
/**
* Populate the properties person, center, start and end date from history.
@@ -75,7 +77,7 @@ class PersonCenterCurrent
return $this->center;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -93,7 +95,7 @@ class PersonCenterCurrent
return $this->person;
}
public function getStartDate(): DateTimeImmutable
public function getStartDate(): \DateTimeImmutable
{
return $this->startDate;
}

View File

@@ -17,13 +17,13 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* Associate a Person with a Center. The association may change on date intervals.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_person_center_history")
*/
class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterface
@@ -35,11 +35,13 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
@@ -48,11 +50,11 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
/**
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="centerHistory")
*/
private ?\Chill\PersonBundle\Entity\Person $person = null,
private ?Person $person = null,
/**
* @ORM\ManyToOne(targetEntity=Center::class)
*/
private ?\Chill\MainBundle\Entity\Center $center = null,
private ?Center $center = null,
/**
* @ORM\Column(type="date_immutable", nullable=false)
*/
@@ -64,7 +66,7 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
return $this->center;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -79,7 +81,7 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
return $this->person;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -91,7 +93,7 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): self
public function setEndDate(?\DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
@@ -105,7 +107,7 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): self
public function setStartDate(?\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;

View File

@@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -26,6 +25,7 @@ use Doctrine\ORM\Mapping as ORM;
* household membership and address validity. See @see{PersonHouseholdAddress}
*
* @ORM\Entity(readOnly=true)
*
* @ORM\Table("view_chill_person_current_address")
*/
class PersonCurrentAddress
@@ -37,7 +37,9 @@ class PersonCurrentAddress
/**
* @ORM\Id
*
* @ORM\OneToOne(targetEntity=Person::class, inversedBy="currentPersonAddress")
*
* @ORM\JoinColumn(name="person_id", referencedColumnName="id")
*/
protected Person $person;
@@ -45,12 +47,12 @@ class PersonCurrentAddress
/**
* @ORM\Column(name="valid_from", type="date_immutable")
*/
protected DateTimeImmutable $validFrom;
protected \DateTimeImmutable $validFrom;
/**
* @ORM\Column(name="valid_to", type="date_immutable")
*/
protected ?DateTimeImmutable $validTo = null;
protected ?\DateTimeImmutable $validTo = null;
public function getAddress(): Address
{
@@ -66,7 +68,7 @@ class PersonCurrentAddress
* This date is the intersection of household membership
* and address validity.
*/
public function getValidFrom(): DateTimeImmutable
public function getValidFrom(): \DateTimeImmutable
{
return $this->validFrom;
}
@@ -75,7 +77,7 @@ class PersonCurrentAddress
* This date is the intersection of household membership
* and address validity.
*/
public function getValidTo(): ?DateTimeImmutable
public function getValidTo(): ?\DateTimeImmutable
{
return $this->validTo;
}

View File

@@ -26,7 +26,9 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_resource")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "personResource": personResource::class
* })
@@ -39,27 +41,34 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private CommentEmbeddable $comment;
/**
* @ORM\Column(type="text", nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?string $freeText = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=PersonResourceKind::class, inversedBy="personResources")
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?PersonResourceKind $kind = null;
@@ -68,7 +77,9 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
* The person which host the owner of this resource.
*
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?Person $person = null;
@@ -77,14 +88,18 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
* The person linked with this resource.
*
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="resources")
*
* @ORM\JoinColumn(nullable=false)
*
* @Groups({"read"})
*/
private ?Person $personOwner = null;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class, inversedBy="personResources")
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read", "docgen:read"})
*/
private ?ThirdParty $thirdParty = null;

View File

@@ -16,14 +16,18 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_resource_kind")
*/
class PersonResourceKind
{
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"docgen:read"})
*/
private ?int $id = null;
@@ -35,7 +39,9 @@ class PersonResourceKind
/**
* @ORM\Column(type="json", length=255)
*
* @Serializer\Groups({"docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $title;

View File

@@ -16,20 +16,22 @@ use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=ResidentialAddressRepository::class)
*
* @ORM\Table(name="chill_person_residential_address")
*/
class ResidentialAddress
{
/**
* @ORM\ManyToOne(targetEntity=Address::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read"})
*/
private ?Address $address = null;
@@ -41,43 +43,53 @@ class ResidentialAddress
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*
* @Groups({"read"})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read"})
*
* @Context(normalizationContext={"groups": {"minimal"}})
*/
private ?Person $hostPerson = null;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
*
* @ORM\JoinColumn(nullable=true)
*
* @Groups({"read"})
*/
private ?ThirdParty $hostThirdParty = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private Person $person;
/**
* @ORM\Column(type="datetime_immutable")
*
* @Groups({"read"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function __construct()
{
@@ -94,7 +106,7 @@ class ResidentialAddress
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -119,7 +131,7 @@ class ResidentialAddress
return $this->person;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -138,7 +150,7 @@ class ResidentialAddress
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): self
public function setEndDate(?\DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
@@ -166,7 +178,7 @@ class ResidentialAddress
return $this;
}
public function setStartDate(DateTimeImmutable $startDate): self
public function setStartDate(\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;

View File

@@ -18,31 +18,30 @@ use Symfony\Component\Serializer\Annotation\Groups;
* PersonAltName.
*
* @ORM\Table(name="chill_person_alt_name")
*
* @ORM\Entity
*/
class PersonAltName
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @var string
*
* @ORM\Column(name="key", type="string", length=255)
*
* @Groups({"write"})
*/
private ?string $key = null;
/**
* @var string
*
* @ORM\Column(name="label", type="text")
*
* @Groups({"write"})
*/
private ?string $label = null;
@@ -121,7 +120,7 @@ class PersonAltName
/**
* @return $this
*/
public function setPerson(?Person $person = null)
public function setPerson(Person $person = null)
{
$this->person = $person;

View File

@@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
* PersonNotDuplicate.
*
* @ORM\Table(name="chill_person_not_duplicate")
*
* @ORM\Entity
*/
class PersonNotDuplicate
@@ -31,10 +32,10 @@ class PersonNotDuplicate
/**
* The person's id.
*
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -56,7 +57,7 @@ class PersonNotDuplicate
public function __construct()
{
$this->date = new DateTime();
$this->date = new \DateTime();
}
public function getDate()
@@ -84,7 +85,7 @@ class PersonNotDuplicate
return $this->user;
}
public function setDate(DateTime $date)
public function setDate(\DateTime $date)
{
$this->date = $date;
}

View File

@@ -19,8 +19,10 @@ use libphonenumber\PhoneNumber;
* Person Phones.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_person_phone",
* indexes={
*
* @ORM\Index(name="phonenumber", columns={"phonenumber"})
* })
*/
@@ -29,7 +31,7 @@ class PersonPhone
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private DateTime $date;
private \DateTime $date;
/**
* @ORM\Column(type="text", nullable=true)
@@ -38,7 +40,9 @@ class PersonPhone
/**
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -63,10 +67,10 @@ class PersonPhone
public function __construct()
{
$this->date = new DateTime();
$this->date = new \DateTime();
}
public function getDate(): DateTime
public function getDate(): \DateTime
{
return $this->date;
}
@@ -102,7 +106,7 @@ class PersonPhone
&& null === $this->getPhonenumber();
}
public function setDate(DateTime $date): void
public function setDate(\DateTime $date): void
{
$this->date = $date;
}

View File

@@ -17,7 +17,9 @@ use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_relations")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "relation": Relation::class
* })
@@ -26,28 +28,36 @@ class Relation
{
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*
* @Serializer\Groups({"read"})
*/
private bool $isActive = true;
/**
* @ORM\Column(type="json", nullable=true)
*
* @Serializer\Groups({"read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $reverseTitle = [];
/**
* @ORM\Column(type="json", nullable=true)
*
* @Serializer\Groups({"read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $title = [];

View File

@@ -16,8 +16,6 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Relationship\RelationshipNoDuplicate;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use RuntimeException;
@@ -27,11 +25,15 @@ use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_relationships")
*
* @DiscriminatorColumn(name="relation_id", type="integer")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "relationship": Relationship::class
* })
*
* @RelationshipNoDuplicate
*/
class Relationship implements TrackCreationInterface, TrackUpdateInterface
@@ -39,52 +41,67 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="datetime_immutable")
*/
private ?DateTimeImmutable $createdAt = null;
private ?\DateTimeImmutable $createdAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?User $createdBy = null;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Assert\NotNull
*
* @Serializer\Groups({"read", "write"})
*/
private ?Person $fromPerson = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read"})
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Relation::class)
*
* @ORM\JoinColumn(nullable=false, name="relation_id", referencedColumnName="id")
*
* @Assert\NotNull
*
* @Serializer\Groups({"read", "write"})
*/
private ?Relation $relation = null;
/**
* @ORM\Column(type="boolean")
*
* @Assert\Type(
* type="bool",
* message="This must be of type boolean"
* )
*
* @Serializer\Groups({"read", "write"})
*/
private bool $reverse;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Assert\NotNull
*
* @Serializer\Groups({"read", "write"})
*/
private ?Person $toPerson = null;
@@ -92,14 +109,14 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private ?DateTimeImmutable $updatedAt = null;
private ?\DateTimeImmutable $updatedAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private ?User $updatedBy = null;
public function getCreatedAt(): ?DateTimeImmutable
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
@@ -130,7 +147,7 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
public function getOpposite(Person $counterpart): Person
{
if ($this->fromPerson !== $counterpart && $this->toPerson !== $counterpart) {
throw new RuntimeException('the counterpart is neither the from nor to person for this relationship');
throw new \RuntimeException('the counterpart is neither the from nor to person for this relationship');
}
if ($this->fromPerson === $counterpart) {
@@ -155,7 +172,7 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
return $this->toPerson;
}
public function getUpdatedAt(): ?DateTimeImmutable
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
@@ -165,7 +182,7 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
return $this->updatedBy;
}
public function setCreatedAt(DateTimeInterface $createdAt): self
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
@@ -207,7 +224,7 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function setUpdatedAt(?DateTimeInterface $updatedAt): self
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;

View File

@@ -19,7 +19,9 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_social_work_evaluation")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "social_work_evaluation": Evaluation::class
* })
@@ -33,26 +35,32 @@ class Evaluation
/**
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read"})
*/
private ?DateInterval $delay = null;
private ?\DateInterval $delay = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read"})
*/
private ?DateInterval $notificationDelay = null;
private ?\DateInterval $notificationDelay = null;
/**
* @var Collection<SocialAction>
*
* @ORM\ManyToMany(
* targetEntity=SocialAction::class,
* mappedBy="evaluations"
@@ -62,13 +70,16 @@ class Evaluation
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $title = [];
/**
* @ORM\Column(type="text", nullable=true)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?string $url = null;
@@ -90,7 +101,7 @@ class Evaluation
return $this;
}
public function getDelay(): ?DateInterval
public function getDelay(): ?\DateInterval
{
return $this->delay;
}
@@ -100,7 +111,7 @@ class Evaluation
return $this->id;
}
public function getNotificationDelay(): ?DateInterval
public function getNotificationDelay(): ?\DateInterval
{
return $this->notificationDelay;
}
@@ -146,14 +157,14 @@ class Evaluation
return $this;
}
public function setDelay(?DateInterval $delay): self
public function setDelay(?\DateInterval $delay): self
{
$this->delay = $delay;
return $this;
}
public function setNotificationDelay(?DateInterval $notificationDelay): self
public function setNotificationDelay(?\DateInterval $notificationDelay): self
{
$this->notificationDelay = $notificationDelay;

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\SocialWork;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@@ -19,7 +18,9 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_social_work_goal")
*
* @Serializer\DiscriminatorMap(
* typeProperty="type",
* mapping={
@@ -36,28 +37,36 @@ class Goal
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @var Collection<Result>
*
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="goals")
*
* @ORM\JoinTable(name="chill_person_social_work_goal_result")
*/
private Collection $results;
/**
* @var Collection<SocialAction>
*
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="goals")
*/
private Collection $socialActions;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $title = [];
@@ -86,7 +95,7 @@ class Goal
return $this;
}
public function getDesactivationDate(): ?DateTimeInterface
public function getDesactivationDate(): ?\DateTimeInterface
{
return $this->desactivationDate;
}
@@ -131,7 +140,7 @@ class Goal
return $this;
}
public function setDesactivationDate(?DateTimeInterface $desactivationDate): self
public function setDesactivationDate(?\DateTimeInterface $desactivationDate): self
{
$this->desactivationDate = $desactivationDate;

Some files were not shown because too many files have changed in this diff Show More