mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge remote-tracking branch 'origin/master' into issue162_ACCent_display_addresses
This commit is contained in:
commit
6dd74287a8
@ -10,14 +10,16 @@ and this project adheres to
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
<!-- write down unreleased development here -->
|
||||||
|
* unnecessary whitespace removed from person banner after person-id + double parentheses removed (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/290)
|
||||||
|
* [person]: delete accompanying period work, including related objects (cascade) (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/36)
|
||||||
* [address]: Display of incomplete address adjusted.
|
* [address]: Display of incomplete address adjusted.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Test releases
|
## Test releases
|
||||||
|
|
||||||
### Test release 2021-11-08
|
### Test release 2021-11-08
|
||||||
|
|
||||||
|
* [person]: Display the name of a user when searching after a User (TMS)
|
||||||
* [person]: Add civility to the person
|
* [person]: Add civility to the person
|
||||||
* [person]: Various improvements on the edit person form
|
* [person]: Various improvements on the edit person form
|
||||||
* [person]: Set available_languages and available_countries as parameters for use in the edit person form
|
* [person]: Set available_languages and available_countries as parameters for use in the edit person form
|
||||||
@ -44,6 +46,7 @@ and this project adheres to
|
|||||||
* [household]: household addresses ordered by ValidFrom date and by id to show the last created address on top.
|
* [household]: household addresses ordered by ValidFrom date and by id to show the last created address on top.
|
||||||
* [socialWorkAction]: display of social issue and parent issues + banner context added.
|
* [socialWorkAction]: display of social issue and parent issues + banner context added.
|
||||||
* [DBAL dependencies] Upgrade to DBAL 3.1
|
* [DBAL dependencies] Upgrade to DBAL 3.1
|
||||||
|
* [person]: double parentheses removed around age in banner + whitespace
|
||||||
|
|
||||||
|
|
||||||
### Test release 2021-10-27
|
### Test release 2021-10-27
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
"doctrine/doctrine-fixtures-bundle": "^3.3",
|
"doctrine/doctrine-fixtures-bundle": "^3.3",
|
||||||
"fakerphp/faker": "^1.13",
|
"fakerphp/faker": "^1.13",
|
||||||
"nelmio/alice": "^3.8",
|
"nelmio/alice": "^3.8",
|
||||||
|
"phpstan/extension-installer": "^1.1",
|
||||||
|
"phpstan/phpstan": "^1.0",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1.0",
|
||||||
"phpunit/phpunit": "^7.0",
|
"phpunit/phpunit": "^7.0",
|
||||||
"symfony/debug-bundle": "^5.1",
|
"symfony/debug-bundle": "^5.1",
|
||||||
"symfony/dotenv": "^5.1",
|
"symfony/dotenv": "^5.1",
|
||||||
|
1542
phpstan-baseline.neon
Normal file
1542
phpstan-baseline.neon
Normal file
File diff suppressed because it is too large
Load Diff
21
phpstan.neon.dist
Normal file
21
phpstan.neon.dist
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
parameters:
|
||||||
|
level: 1
|
||||||
|
paths:
|
||||||
|
- src/
|
||||||
|
excludePaths:
|
||||||
|
- src/Bundle/*/Tests/*
|
||||||
|
- src/Bundle/*/Test/*
|
||||||
|
- src/Bundle/*/config/*
|
||||||
|
- src/Bundle/*/migrations/*
|
||||||
|
- src/Bundle/*/translations/*
|
||||||
|
- src/Bundle/*/Resources/*
|
||||||
|
- src/Bundle/*/src/Tests/*
|
||||||
|
- src/Bundle/*/src/Test/*
|
||||||
|
- src/Bundle/*/src/config/*
|
||||||
|
- src/Bundle/*/src/migrations/*
|
||||||
|
- src/Bundle/*/src/translations/*
|
||||||
|
- src/Bundle/*/src/Resources/*
|
||||||
|
|
||||||
|
includes:
|
||||||
|
- phpstan-baseline.neon
|
||||||
|
|
@ -29,27 +29,27 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|||||||
use Doctrine\ORM\Query\Expr\Join;
|
use Doctrine\ORM\Query\Expr\Join;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
class ActivityTypeAggregator implements AggregatorInterface
|
class ActivityTypeAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var EntityRepository
|
* @var EntityRepository
|
||||||
*/
|
*/
|
||||||
protected $typeRepository;
|
protected $typeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TranslatableStringHelper
|
* @var TranslatableStringHelper
|
||||||
*/
|
*/
|
||||||
protected $stringHelper;
|
protected $stringHelper;
|
||||||
|
|
||||||
const KEY = 'activity_type_aggregator';
|
const KEY = 'activity_type_aggregator';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EntityRepository $typeRepository,
|
EntityRepository $typeRepository,
|
||||||
TranslatableStringHelper $stringHelper
|
TranslatableStringHelper $stringHelper
|
||||||
@ -57,19 +57,19 @@ class ActivityTypeAggregator implements AggregatorInterface
|
|||||||
$this->typeRepository = $typeRepository;
|
$this->typeRepository = $typeRepository;
|
||||||
$this->stringHelper = $stringHelper;
|
$this->stringHelper = $stringHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
// add select element
|
// add select element
|
||||||
$qb->addSelect(sprintf('IDENTITY(activity.type) AS %s', self::KEY));
|
$qb->addSelect(sprintf('IDENTITY(activity.type) AS %s', self::KEY));
|
||||||
|
|
||||||
// add the "group by" part
|
// add the "group by" part
|
||||||
$groupBy = $qb->addGroupBy(self::KEY);
|
$groupBy = $qb->addGroupBy(self::KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a join between Activity and another alias
|
* Check if a join between Activity and another alias
|
||||||
*
|
*
|
||||||
* @param Join[] $joins
|
* @param Join[] $joins
|
||||||
* @param string $alias the alias to search for
|
* @param string $alias the alias to search for
|
||||||
* @return boolean
|
* @return boolean
|
||||||
@ -81,7 +81,7 @@ class ActivityTypeAggregator implements AggregatorInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,18 +99,18 @@ class ActivityTypeAggregator implements AggregatorInterface
|
|||||||
{
|
{
|
||||||
return "Aggregate by activity type";
|
return "Aggregate by activity type";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRole()
|
public function addRole()
|
||||||
{
|
{
|
||||||
return new Role(ActivityStatsVoter::STATS);
|
return new Role(ActivityStatsVoter::STATS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data): \Closure
|
||||||
{
|
{
|
||||||
// for performance reason, we load data from db only once
|
// for performance reason, we load data from db only once
|
||||||
$this->typeRepository->findBy(array('id' => $values));
|
$this->typeRepository->findBy(array('id' => $values));
|
||||||
|
|
||||||
return function($value) use ($data) {
|
return function($value): string {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return 'Activity type';
|
return 'Activity type';
|
||||||
}
|
}
|
||||||
@ -120,12 +120,11 @@ class ActivityTypeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
return $this->stringHelper->localize($t->getName());
|
return $this->stringHelper->localize($t->getName());
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryKeys($data)
|
public function getQueryKeys($data): array
|
||||||
{
|
{
|
||||||
return array(self::KEY);
|
return [self::KEY];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
},
|
},
|
||||||
{ 'title': 'Users concerned'|trans,
|
{ 'title': 'Users concerned'|trans,
|
||||||
'items': entity.users,
|
'items': entity.users,
|
||||||
'path' : 'admin_user_show',
|
|
||||||
'key' : 'id'
|
'key' : 'id'
|
||||||
},
|
},
|
||||||
] %}
|
] %}
|
||||||
@ -58,6 +57,7 @@
|
|||||||
<ul class="list-content">
|
<ul class="list-content">
|
||||||
{% for item in bloc.items %}
|
{% for item in bloc.items %}
|
||||||
<li>
|
<li>
|
||||||
|
{% if bloc.path is defined %}
|
||||||
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
||||||
<span class="{% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
<span class="{% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
||||||
{{ item|chill_entity_render_box({
|
{{ item|chill_entity_render_box({
|
||||||
@ -66,6 +66,14 @@
|
|||||||
}) }}
|
}) }}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="{% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
||||||
|
{{ item|chill_entity_render_box({
|
||||||
|
'render': 'raw',
|
||||||
|
'addAltNames': false
|
||||||
|
}) }}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
@ -85,6 +93,7 @@
|
|||||||
<ul class="list-content">
|
<ul class="list-content">
|
||||||
{% for item in bloc.items %}
|
{% for item in bloc.items %}
|
||||||
<li>
|
<li>
|
||||||
|
{% if bloc.path is defined %}
|
||||||
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
||||||
<span class="{% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
<span class="{% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
||||||
{{ item|chill_entity_render_box({
|
{{ item|chill_entity_render_box({
|
||||||
@ -93,6 +102,12 @@
|
|||||||
}) }}
|
}) }}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{{ item|chill_entity_render_box({
|
||||||
|
'render': 'raw',
|
||||||
|
'addAltNames': false
|
||||||
|
}) }}
|
||||||
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
@ -114,12 +129,19 @@
|
|||||||
{% for item in bloc.items %}
|
{% for item in bloc.items %}
|
||||||
|
|
||||||
<span class="wl-item {% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
<span class="wl-item {% if (badge_person is defined and badge_person == true) %}badge-person{% else %}badge bg-primary{% endif %}">
|
||||||
|
{% if bloc.path is defined %}
|
||||||
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
<a href="{{ _self.href(bloc.path, bloc.key, item.id) }}">
|
||||||
{{ item|chill_entity_render_box({
|
{{ item|chill_entity_render_box({
|
||||||
'render': 'raw',
|
'render': 'raw',
|
||||||
'addAltNames': false
|
'addAltNames': false
|
||||||
}) }}
|
}) }}
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
{{ item|chill_entity_render_box({
|
||||||
|
'render': 'raw',
|
||||||
|
'addAltNames': false
|
||||||
|
}) }}
|
||||||
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
'title' : 'Remove activity'|trans,
|
'title' : 'Remove activity'|trans,
|
||||||
'confirm_question' : 'Are you sure you want to remove the activity about "%name%" ?'|trans({ '%name%' : accompanyingCourse.id } ),
|
'confirm_question' : 'Are you sure you want to remove the activity about "%name%" ?'|trans({ '%name%' : accompanyingCourse.id } ),
|
||||||
'cancel_route' : 'chill_activity_activity_list',
|
'cancel_route' : 'chill_activity_activity_list',
|
||||||
'cancel_parameters' : { 'accompanying_course_id' : accompanyingCourse.id, 'id' : activity.id },
|
'cancel_parameters' : { 'accompanying_period_id' : accompanyingCourse.id, 'id' : activity.id },
|
||||||
'form' : delete_form
|
'form' : delete_form
|
||||||
} ) }}
|
} ) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -19,8 +19,6 @@ final class ChillAsideActivityExtension extends Extension implements PrependExte
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @phpstan-ignore-next-line
|
|
||||||
*/
|
*/
|
||||||
public function load(array $configs, ContainerBuilder $container): void
|
public function load(array $configs, ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
@ -111,4 +109,4 @@ final class ChillAsideActivityExtension extends Extension implements PrependExte
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ final class CategoryRender implements ChillEntityRenderInterface
|
|||||||
{
|
{
|
||||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||||
|
|
||||||
$titles[] = $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
|
$titles = [
|
||||||
|
$this->translatableStringHelper->localize($asideActivityCategory->getTitle()),
|
||||||
|
];
|
||||||
|
|
||||||
while ($asideActivityCategory->hasParent()) {
|
while ($asideActivityCategory->hasParent()) {
|
||||||
$asideActivityCategory = $asideActivityCategory->getParent();
|
$asideActivityCategory = $asideActivityCategory->getParent();
|
||||||
|
@ -97,9 +97,9 @@ class CalendarController extends AbstractController
|
|||||||
'calendarItems' => $calendarItems,
|
'calendarItems' => $calendarItems,
|
||||||
'user' => $user
|
'user' => $user
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
} elseif ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
||||||
|
|
||||||
$total = $this->calendarRepository->countByAccompanyingPeriod($accompanyingPeriod);
|
$total = $this->calendarRepository->countByAccompanyingPeriod($accompanyingPeriod);
|
||||||
$paginator = $this->paginator->create($total);
|
$paginator = $this->paginator->create($total);
|
||||||
$calendarItems = $this->calendarRepository->findBy(
|
$calendarItems = $this->calendarRepository->findBy(
|
||||||
@ -117,6 +117,8 @@ class CalendarController extends AbstractController
|
|||||||
'paginator' => $paginator
|
'paginator' => $paginator
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \Exception('Unable to list actions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,27 +28,31 @@ class ChillCustomFieldsExtension extends Extension implements PrependExtensionIn
|
|||||||
$loader->load('services/fixtures.yaml');
|
$loader->load('services/fixtures.yaml');
|
||||||
$loader->load('services/controller.yaml');
|
$loader->load('services/controller.yaml');
|
||||||
$loader->load('services/command.yaml');
|
$loader->load('services/command.yaml');
|
||||||
|
|
||||||
//add at least a blank array at 'customizable_entities' options
|
//add at least a blank array at 'customizable_entities' options
|
||||||
//$customizable_entities = (isset($config['customizables_entities'])
|
//$customizable_entities = (isset($config['customizables_entities'])
|
||||||
// && $config['customizables_entities'] !== FALSE)
|
// && $config['customizables_entities'] !== FALSE)
|
||||||
// ? $config['customizables_entities'] : array();
|
// ? $config['customizables_entities'] : array();
|
||||||
|
|
||||||
$container->setParameter('chill_custom_fields.customizables_entities',
|
$container->setParameter('chill_custom_fields.customizables_entities',
|
||||||
$config['customizables_entities']);
|
$config['customizables_entities']);
|
||||||
$container->setParameter('chill_custom_fields.show_empty_values',
|
$container->setParameter('chill_custom_fields.show_empty_values',
|
||||||
$config['show_empty_values_in_views']);
|
$config['show_empty_values_in_views']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-PHPdoc)
|
/* (non-PHPdoc)
|
||||||
* @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend()
|
* @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend()
|
||||||
*/
|
*/
|
||||||
public function prepend(ContainerBuilder $container)
|
public function prepend(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
// add form layout to twig resources
|
// add form layout to twig resources
|
||||||
$twigConfig['form_themes'][] = 'ChillCustomFieldsBundle:Form:fields.html.twig';
|
$twigConfig = [
|
||||||
|
'form_themes' => [
|
||||||
|
'ChillCustomFieldsBundle:Form:fields.html.twig',
|
||||||
|
],
|
||||||
|
];
|
||||||
$container->prependExtensionConfig('twig', $twigConfig);
|
$container->prependExtensionConfig('twig', $twigConfig);
|
||||||
|
|
||||||
//add routes for custom bundle
|
//add routes for custom bundle
|
||||||
$container->prependExtensionConfig('chill_main', array(
|
$container->prependExtensionConfig('chill_main', array(
|
||||||
'routing' => array(
|
'routing' => array(
|
||||||
|
@ -145,5 +145,7 @@ class DocGeneratorTemplateController extends AbstractController
|
|||||||
} catch (TransferException $e) {
|
} catch (TransferException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \Exception('Unable to generate document.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Chill\DocStoreBundle\Repository;
|
declare(strict_types=1);
|
||||||
|
|
||||||
use App\Entity\AccompanyingCourseDocument;
|
namespace Chill\DocStoreBundle\EntityRepository;
|
||||||
|
|
||||||
|
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
|||||||
*/
|
*/
|
||||||
class ParticipationController extends AbstractController
|
class ParticipationController extends AbstractController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Psr\Log\LoggerInterface
|
* @var \Psr\Log\LoggerInterface
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParticipationController constructor.
|
* ParticipationController constructor.
|
||||||
*
|
*
|
||||||
@ -54,10 +54,10 @@ class ParticipationController extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a form to add a participation
|
* Show a form to add a participation
|
||||||
*
|
*
|
||||||
* This function parse the person_id / persons_ids query argument
|
* This function parse the person_id / persons_ids query argument
|
||||||
* and decide if it should process a single or multiple participation. Depending
|
* and decide if it should process a single or multiple participation. Depending
|
||||||
* on this, the appropriate layout and form.
|
* on this, the appropriate layout and form.
|
||||||
@ -67,46 +67,46 @@ class ParticipationController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function newAction(Request $request)
|
public function newAction(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
// test the request is correct
|
// test the request is correct
|
||||||
try {
|
try {
|
||||||
$this->testRequest($request);
|
$this->testRequest($request);
|
||||||
} catch (\RuntimeException $ex) {
|
} catch (\RuntimeException $ex) {
|
||||||
$this->logger->warning($ex->getMessage());
|
$this->logger->warning($ex->getMessage());
|
||||||
|
|
||||||
return (new Response())
|
return (new Response())
|
||||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||||
->setContent($ex->getMessage());
|
->setContent($ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// forward to other action
|
// forward to other action
|
||||||
$single = $request->query->has('person_id');
|
$single = $request->query->has('person_id');
|
||||||
$multiple = $request->query->has('persons_ids');
|
$multiple = $request->query->has('persons_ids');
|
||||||
|
|
||||||
if ($single === true) {
|
if ($single === true) {
|
||||||
return $this->newSingle($request);
|
return $this->newSingle($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($multiple === true) {
|
if ($multiple === true) {
|
||||||
|
|
||||||
return $this->newMultiple($request);
|
return $this->newMultiple($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// at this point, we miss the required fields. Throw an error
|
// at this point, we miss the required fields. Throw an error
|
||||||
return (new Response())
|
return (new Response())
|
||||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||||
->setContent("You must provide either 'person_id' or "
|
->setContent("You must provide either 'person_id' or "
|
||||||
. "'persons_ids' argument in query");
|
. "'persons_ids' argument in query");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Test that the query parameters are valid :
|
* Test that the query parameters are valid :
|
||||||
*
|
*
|
||||||
* - an `event_id` is existing ;
|
* - an `event_id` is existing ;
|
||||||
* - `person_id` and `persons_ids` are **not** both present ;
|
* - `person_id` and `persons_ids` are **not** both present ;
|
||||||
* - `persons_id` is correct (contains only numbers and a ','.
|
* - `persons_id` is correct (contains only numbers and a ','.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @throws \RuntimeException if an error is detected
|
* @throws \RuntimeException if an error is detected
|
||||||
*/
|
*/
|
||||||
@ -114,64 +114,64 @@ class ParticipationController extends AbstractController
|
|||||||
{
|
{
|
||||||
$single = $request->query->has('person_id');
|
$single = $request->query->has('person_id');
|
||||||
$multiple = $request->query->has('persons_ids');
|
$multiple = $request->query->has('persons_ids');
|
||||||
|
|
||||||
if ($single === true AND $multiple === true) {
|
if ($single === true AND $multiple === true) {
|
||||||
// we are not allowed to have both person_id and persons_ids
|
// we are not allowed to have both person_id and persons_ids
|
||||||
throw new \RuntimeException("You are not allow to provide both 'person_id' and "
|
throw new \RuntimeException("You are not allow to provide both 'person_id' and "
|
||||||
. "'persons_ids' simulaneously");
|
. "'persons_ids' simulaneously");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($multiple === true) {
|
if ($multiple === true) {
|
||||||
$persons_ids = $request->query->get('persons_ids');
|
$persons_ids = $request->query->get('persons_ids');
|
||||||
|
|
||||||
if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', $persons_ids)) {
|
if (!preg_match('/^([0-9]{1,},{0,1}){1,}[0-9]{0,}$/', $persons_ids)) {
|
||||||
throw new \RuntimeException("The persons_ids value should "
|
throw new \RuntimeException("The persons_ids value should "
|
||||||
. "contains int separated by ','");
|
. "contains int separated by ','");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for event_id - this could be removed later
|
// check for event_id - this could be removed later
|
||||||
if ($request->query->has('event_id') === FALSE) {
|
if ($request->query->has('event_id') === FALSE) {
|
||||||
throw new \RuntimeException("You must provide an event_id");
|
throw new \RuntimeException("You must provide an event_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a form with single participation.
|
* Show a form with single participation.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
protected function newSingle(Request $request)
|
protected function newSingle(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$returnPath = $request->query->get('return_path') ?
|
$returnPath = $request->query->get('return_path') ?
|
||||||
$request->query->get('return_path') : null;
|
$request->query->get('return_path') : null;
|
||||||
|
|
||||||
$participation = $this->handleRequest($request, new Participation(), false);
|
$participation = $this->handleRequest($request, new Participation(), false);
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||||
$participation, 'The user is not allowed to create this participation');
|
$participation, 'The user is not allowed to create this participation');
|
||||||
|
|
||||||
$form = $this->createCreateForm($participation, $returnPath);
|
$form = $this->createCreateForm($participation, $returnPath);
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation,
|
'participation' => $participation,
|
||||||
'ignored_participations' => array() // this is required, see self::newMultiple
|
'ignored_participations' => array() // this is required, see self::newMultiple
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a form with multiple participation.
|
* Show a form with multiple participation.
|
||||||
*
|
*
|
||||||
* If a person is already participating on the event (if a participation with
|
* If a person is already participating on the event (if a participation with
|
||||||
* the same person is associated with the event), the participation is ignored.
|
* the same person is associated with the event), the participation is ignored.
|
||||||
*
|
*
|
||||||
* If all but one participation is ignored, the page show the same response
|
* If all but one participation is ignored, the page show the same response
|
||||||
* than the newSingle function.
|
* than the newSingle function.
|
||||||
*
|
*
|
||||||
* If all participations must be ignored, an error is shown and the method redirects
|
* If all participations must be ignored, an error is shown and the method redirects
|
||||||
* to the event 'show' view with an appropriate flash message.
|
* to the event 'show' view with an appropriate flash message.
|
||||||
*
|
*
|
||||||
@ -181,24 +181,24 @@ class ParticipationController extends AbstractController
|
|||||||
protected function newMultiple(Request $request)
|
protected function newMultiple(Request $request)
|
||||||
{
|
{
|
||||||
$participations = $this->handleRequest($request, new Participation(), true);
|
$participations = $this->handleRequest($request, new Participation(), true);
|
||||||
|
$ignoredParticipations = $newParticipations = [];
|
||||||
|
|
||||||
foreach ($participations as $i => $participation) {
|
foreach ($participations as $i => $participation) {
|
||||||
// check for authorization
|
// check for authorization
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||||
$participation, 'The user is not allowed to create this participation');
|
$participation, 'The user is not allowed to create this participation');
|
||||||
|
|
||||||
// create a collection of person's id participating to the event
|
// create a collection of person's id participating to the event
|
||||||
/* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */
|
/* @var $peopleParticipating \Doctrine\Common\Collections\ArrayCollection */
|
||||||
$peopleParticipating = isset($peopleParticipating) ? $peopleParticipating :
|
$peopleParticipating = isset($peopleParticipating) ? $peopleParticipating :
|
||||||
$participation->getEvent()->getParticipations()->map(
|
$participation->getEvent()->getParticipations()->map(
|
||||||
function(Participation $p) { return $p->getPerson()->getId(); }
|
function(Participation $p) { return $p->getPerson()->getId(); }
|
||||||
);
|
);
|
||||||
// check that the user is not already in the event
|
// check that the user is not already in the event
|
||||||
if ($peopleParticipating->contains($participation->getPerson()->getId())) {
|
if ($peopleParticipating->contains($participation->getPerson()->getId())) {
|
||||||
$ignoredParticipations[] = $participation
|
$ignoredParticipations[] = $participation
|
||||||
->getEvent()->getParticipations()->filter(
|
->getEvent()->getParticipations()->filter(
|
||||||
function (Participation $p) use ($participation) {
|
function (Participation $p) use ($participation) {
|
||||||
return $p->getPerson()->getId() === $participation->getPerson()->getId();
|
return $p->getPerson()->getId() === $participation->getPerson()->getId();
|
||||||
}
|
}
|
||||||
)->first();
|
)->first();
|
||||||
@ -206,15 +206,15 @@ class ParticipationController extends AbstractController
|
|||||||
$newParticipations[] = $participation;
|
$newParticipations[] = $participation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is where the function redirect depending on valid participation
|
// this is where the function redirect depending on valid participation
|
||||||
|
|
||||||
if (!isset($newParticipations)) {
|
if ([] === $newParticipations) {
|
||||||
// if we do not have nay participants, redirect to event view
|
// if we do not have nay participants, redirect to event view
|
||||||
$this->addFlash('error', $this->get('translator')->trans(
|
$this->addFlash('error', $this->get('translator')->trans(
|
||||||
'None of the requested people may participate '
|
'None of the requested people may participate '
|
||||||
. 'the event: they are maybe already participating.'));
|
. 'the event: they are maybe already participating.'));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show', array(
|
return $this->redirectToRoute('chill_event__event_show', array(
|
||||||
'event_id' => $request->query->getInt('event_id', 0)
|
'event_id' => $request->query->getInt('event_id', 0)
|
||||||
));
|
));
|
||||||
@ -222,24 +222,29 @@ class ParticipationController extends AbstractController
|
|||||||
// if we have multiple participations, show a form with multiple participations
|
// if we have multiple participations, show a form with multiple participations
|
||||||
$form = $this->createCreateFormMultiple($newParticipations);
|
$form = $this->createCreateFormMultiple($newParticipations);
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array(
|
return $this->render(
|
||||||
|
'ChillEventBundle:Participation:new-multiple.html.twig',
|
||||||
|
[
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participations' => $newParticipations,
|
'participations' => $newParticipations,
|
||||||
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
'ignored_participations' => $ignoredParticipations
|
||||||
));
|
]
|
||||||
} else {
|
);
|
||||||
// if we have only one participation, show the same form than for single participation
|
}
|
||||||
$form = $this->createCreateForm($participation);
|
|
||||||
|
// if we have only one participation, show the same form than for single participation
|
||||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
$form = $this->createCreateForm($participation);
|
||||||
|
|
||||||
|
return $this->render(
|
||||||
|
'ChillEventBundle:Participation:new.html.twig',
|
||||||
|
[
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation,
|
'participation' => $participation,
|
||||||
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
'ignored_participations' => $ignoredParticipations,
|
||||||
));
|
]
|
||||||
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||||
@ -251,32 +256,32 @@ class ParticipationController extends AbstractController
|
|||||||
$this->testRequest($request);
|
$this->testRequest($request);
|
||||||
} catch (\RuntimeException $ex) {
|
} catch (\RuntimeException $ex) {
|
||||||
$this->logger->warning($ex->getMessage());
|
$this->logger->warning($ex->getMessage());
|
||||||
|
|
||||||
return (new Response())
|
return (new Response())
|
||||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||||
->setContent($ex->getMessage());
|
->setContent($ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// forward to other action
|
// forward to other action
|
||||||
$single = $request->query->has('person_id');
|
$single = $request->query->has('person_id');
|
||||||
$multiple = $request->query->has('persons_ids');
|
$multiple = $request->query->has('persons_ids');
|
||||||
|
|
||||||
if ($single === true) {
|
if ($single === true) {
|
||||||
return $this->createSingle($request);
|
return $this->createSingle($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($multiple === true) {
|
if ($multiple === true) {
|
||||||
|
|
||||||
return $this->createMultiple($request);
|
return $this->createMultiple($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// at this point, we miss the required fields. Throw an error
|
// at this point, we miss the required fields. Throw an error
|
||||||
return (new Response())
|
return (new Response())
|
||||||
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
->setStatusCode(Response::HTTP_BAD_REQUEST)
|
||||||
->setContent("You must provide either 'person_id' or "
|
->setContent("You must provide either 'person_id' or "
|
||||||
. "'persons_ids' argument in query");
|
. "'persons_ids' argument in query");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||||
@ -284,41 +289,41 @@ class ParticipationController extends AbstractController
|
|||||||
public function createSingle(Request $request)
|
public function createSingle(Request $request)
|
||||||
{
|
{
|
||||||
$participation = $this->handleRequest($request, new Participation(), false);
|
$participation = $this->handleRequest($request, new Participation(), false);
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||||
$participation, 'The user is not allowed to create this participation');
|
$participation, 'The user is not allowed to create this participation');
|
||||||
|
|
||||||
$form = $this->createCreateForm($participation);
|
$form = $this->createCreateForm($participation);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$em->persist($participation);
|
$em->persist($participation);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans(
|
$this->addFlash('success', $this->get('translator')->trans(
|
||||||
'The participation was created'
|
'The participation was created'
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($request->query->get('return_path'))
|
if ($request->query->get('return_path'))
|
||||||
{
|
{
|
||||||
return $this->redirect($request->query->get('return_path'));
|
return $this->redirect($request->query->get('return_path'));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return $this->redirectToRoute('chill_event__event_show', array(
|
return $this->redirectToRoute('chill_event__event_show', array(
|
||||||
'event_id' => $participation->getEvent()->getId()
|
'event_id' => $participation->getEvent()->getId()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation
|
'participation' => $participation
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||||
@ -326,56 +331,56 @@ class ParticipationController extends AbstractController
|
|||||||
public function createMultiple(Request $request)
|
public function createMultiple(Request $request)
|
||||||
{
|
{
|
||||||
$participations = $this->handleRequest($request, new Participation(), true);
|
$participations = $this->handleRequest($request, new Participation(), true);
|
||||||
|
|
||||||
foreach($participations as $participation) {
|
foreach($participations as $participation) {
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
$this->denyAccessUnlessGranted(ParticipationVoter::CREATE,
|
||||||
$participation, 'The user is not allowed to create this participation');
|
$participation, 'The user is not allowed to create this participation');
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createCreateFormMultiple($participations);
|
$form = $this->createCreateFormMultiple($participations);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
foreach($data['participations'] as $participation) {
|
foreach($data['participations'] as $participation) {
|
||||||
$em->persist($participation);
|
$em->persist($participation);
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans(
|
$this->addFlash('success', $this->get('translator')->trans(
|
||||||
'The participations were created'
|
'The participations were created'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show', array(
|
return $this->redirectToRoute('chill_event__event_show', array(
|
||||||
'event_id' => $participations[0]->getEvent()->getId()
|
'event_id' => $participations[0]->getEvent()->getId()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation
|
'participation' => $participation
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Handle the request to adapt $participation.
|
* Handle the request to adapt $participation.
|
||||||
*
|
*
|
||||||
* If the request is multiple, the $participation object is cloned.
|
* If the request is multiple, the $participation object is cloned.
|
||||||
* Limitations: the $participation should not be persisted.
|
* Limitations: the $participation should not be persisted.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Participation $participation
|
* @param Participation $participation
|
||||||
* @param boolean $multiple (default false)
|
* @param boolean $multiple (default false)
|
||||||
* @return Participation|Participations[] return one single participation if $multiple == false
|
* @return Participation|Participations[] return one single participation if $multiple == false
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the event/person is not found
|
||||||
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
|
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException if the user does not have access to event/person
|
||||||
*/
|
*/
|
||||||
protected function handleRequest(
|
protected function handleRequest(
|
||||||
Request $request,
|
Request $request,
|
||||||
Participation $participation,
|
Participation $participation,
|
||||||
$multiple = false)
|
$multiple = false)
|
||||||
{
|
{
|
||||||
@ -384,37 +389,37 @@ class ParticipationController extends AbstractController
|
|||||||
throw new \LogicException("The participation object should not be managed by "
|
throw new \LogicException("The participation object should not be managed by "
|
||||||
. "the object manager using the method ".__METHOD__);
|
. "the object manager using the method ".__METHOD__);
|
||||||
}
|
}
|
||||||
|
|
||||||
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
|
$event_id = $request->query->getInt('event_id', 0); // sf4 check:
|
||||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
||||||
|
|
||||||
if ($event_id !== NULL) {
|
if ($event_id !== NULL) {
|
||||||
$event = $em->getRepository('ChillEventBundle:Event')
|
$event = $em->getRepository('ChillEventBundle:Event')
|
||||||
->find($event_id);
|
->find($event_id);
|
||||||
|
|
||||||
if ($event === NULL) {
|
if ($event === NULL) {
|
||||||
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
|
throw $this->createNotFoundException('The event with id '.$event_id.' is not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event,
|
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event,
|
||||||
'The user is not allowed to see the event');
|
'The user is not allowed to see the event');
|
||||||
|
|
||||||
$participation->setEvent($event);
|
$participation->setEvent($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this script should be able to handle multiple, so we translate
|
// this script should be able to handle multiple, so we translate
|
||||||
// single person_id in an array
|
// single person_id in an array
|
||||||
$persons_ids = $request->query->has('person_id') ?
|
$persons_ids = $request->query->has('person_id') ?
|
||||||
[$request->query->getInt('person_id', 0)] // sf4 check:
|
[$request->query->getInt('person_id', 0)] // sf4 check:
|
||||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
||||||
: explode(',', $request->query->get('persons_ids'));
|
: explode(',', $request->query->get('persons_ids'));
|
||||||
$participations = array();
|
$participations = array();
|
||||||
|
|
||||||
foreach($persons_ids as $person_id) {
|
foreach($persons_ids as $person_id) {
|
||||||
|
|
||||||
// clone if we have to reuse the $participation
|
// clone if we have to reuse the $participation
|
||||||
$participation = count($persons_ids) > 1 ? clone $participation : $participation;
|
$participation = count($persons_ids) > 1 ? clone $participation : $participation;
|
||||||
|
|
||||||
if ($person_id !== NULL) {
|
if ($person_id !== NULL) {
|
||||||
$person = $em->getRepository('ChillPersonBundle:Person')
|
$person = $em->getRepository('ChillPersonBundle:Person')
|
||||||
->find($person_id);
|
->find($person_id);
|
||||||
@ -428,13 +433,13 @@ class ParticipationController extends AbstractController
|
|||||||
|
|
||||||
$participation->setPerson($person);
|
$participation->setPerson($person);
|
||||||
}
|
}
|
||||||
|
|
||||||
$participations[] = $participation;
|
$participations[] = $participation;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $multiple ? $participations : $participations[0];
|
return $multiple ? $participations : $participations[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Participation $participation
|
* @param Participation $participation
|
||||||
* @param null $return_path
|
* @param null $return_path
|
||||||
@ -442,7 +447,7 @@ class ParticipationController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function createCreateForm(Participation $participation, $return_path = null)
|
public function createCreateForm(Participation $participation, $return_path = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$form = $this->createForm(ParticipationType::class, $participation, array(
|
$form = $this->createForm(ParticipationType::class, $participation, array(
|
||||||
'event_type' => $participation->getEvent()->getType(),
|
'event_type' => $participation->getEvent()->getType(),
|
||||||
'action' => $this->generateUrl('chill_event_participation_create', array(
|
'action' => $this->generateUrl('chill_event_participation_create', array(
|
||||||
@ -451,14 +456,14 @@ class ParticipationController extends AbstractController
|
|||||||
'person_id' => $participation->getPerson()->getId()
|
'person_id' => $participation->getPerson()->getId()
|
||||||
))
|
))
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('submit', SubmitType::class, array(
|
$form->add('submit', SubmitType::class, array(
|
||||||
'label' => 'Create'
|
'label' => 'Create'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $participations
|
* @param array $participations
|
||||||
* @return \Symfony\Component\Form\FormInterface
|
* @return \Symfony\Component\Form\FormInterface
|
||||||
@ -470,7 +475,7 @@ class ParticipationController extends AbstractController
|
|||||||
'action' => $this->generateUrl('chill_event_participation_create', array(
|
'action' => $this->generateUrl('chill_event_participation_create', array(
|
||||||
'event_id' => current($participations)->getEvent()->getId(),
|
'event_id' => current($participations)->getEvent()->getId(),
|
||||||
'persons_ids' => implode(',', array_map(
|
'persons_ids' => implode(',', array_map(
|
||||||
function(Participation $p) { return $p->getPerson()->getId(); },
|
function(Participation $p) { return $p->getPerson()->getId(); },
|
||||||
$participations))
|
$participations))
|
||||||
)
|
)
|
||||||
)));
|
)));
|
||||||
@ -481,90 +486,90 @@ class ParticipationController extends AbstractController
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$form->add('submit', SubmitType::class, array(
|
$form->add('submit', SubmitType::class, array(
|
||||||
'label' => 'Create'
|
'label' => 'Create'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show an edit form for the participation with the given id.
|
* show an edit form for the participation with the given id.
|
||||||
*
|
*
|
||||||
* @param int $participation_id
|
* @param int $participation_id
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the participation is not found
|
||||||
* @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation
|
* @throws \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException if the user is not allowed to edit the participation
|
||||||
*/
|
*/
|
||||||
public function editAction($participation_id)
|
public function editAction($participation_id)
|
||||||
{
|
{
|
||||||
/* @var $participation Participation */
|
/* @var $participation Participation */
|
||||||
$participation = $this->getDoctrine()->getManager()
|
$participation = $this->getDoctrine()->getManager()
|
||||||
->getRepository('ChillEventBundle:Participation')
|
->getRepository('ChillEventBundle:Participation')
|
||||||
->find($participation_id);
|
->find($participation_id);
|
||||||
|
|
||||||
if ($participation === NULL) {
|
if ($participation === NULL) {
|
||||||
throw $this->createNotFoundException('The participation is not found');
|
throw $this->createNotFoundException('The participation is not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||||
'You are not allowed to edit this participation');
|
'You are not allowed to edit this participation');
|
||||||
|
|
||||||
$form = $this->createEditForm($participation);
|
$form = $this->createEditForm($participation);
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation
|
'participation' => $participation
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $participation_id
|
* @param $participation_id
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||||
*/
|
*/
|
||||||
public function updateAction($participation_id, Request $request)
|
public function updateAction($participation_id, Request $request)
|
||||||
{
|
{
|
||||||
/* @var $participation Participation */
|
/* @var $participation Participation */
|
||||||
$participation = $this->getDoctrine()->getManager()
|
$participation = $this->getDoctrine()->getManager()
|
||||||
->getRepository('ChillEventBundle:Participation')
|
->getRepository('ChillEventBundle:Participation')
|
||||||
->find($participation_id);
|
->find($participation_id);
|
||||||
|
|
||||||
if ($participation === NULL) {
|
if ($participation === NULL) {
|
||||||
throw $this->createNotFoundException('The participation is not found');
|
throw $this->createNotFoundException('The participation is not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||||
'You are not allowed to edit this participation');
|
'You are not allowed to edit this participation');
|
||||||
|
|
||||||
$form = $this->createEditForm($participation);
|
$form = $this->createEditForm($participation);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans(
|
$this->addFlash('success', $this->get('translator')->trans(
|
||||||
'The participation was updated'
|
'The participation was updated'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show', array(
|
return $this->redirectToRoute('chill_event__event_show', array(
|
||||||
'event_id' => $participation->getEvent()->getId()
|
'event_id' => $participation->getEvent()->getId()
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:edit.html.twig', array(
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation
|
'participation' => $participation
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Participation $participation
|
* @param Participation $participation
|
||||||
* @return \Symfony\Component\Form\FormInterface
|
* @return \Symfony\Component\Form\FormInterface
|
||||||
*/
|
*/
|
||||||
@ -576,14 +581,14 @@ class ParticipationController extends AbstractController
|
|||||||
'participation_id' => $participation->getId()
|
'participation_id' => $participation->getId()
|
||||||
))
|
))
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('submit', SubmitType::class, array(
|
$form->add('submit', SubmitType::class, array(
|
||||||
'label' => 'Edit'
|
'label' => 'Edit'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show a form to edit multiple participation for the same event.
|
* show a form to edit multiple participation for the same event.
|
||||||
*
|
*
|
||||||
@ -594,84 +599,84 @@ class ParticipationController extends AbstractController
|
|||||||
{
|
{
|
||||||
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
||||||
->find($event_id);
|
->find($event_id);
|
||||||
|
|
||||||
if ($event === null) {
|
if ($event === null) {
|
||||||
throw $this->createNotFoundException("The event with id $event_id is not found");
|
throw $this->createNotFoundException("The event with id $event_id is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for ACL, on Event level and on Participation Level
|
// check for ACL, on Event level and on Participation Level
|
||||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
||||||
. "to see this event");
|
. "to see this event");
|
||||||
foreach ($event->getParticipations() as $participation) {
|
foreach ($event->getParticipations() as $participation) {
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||||
"You are not allowed to update participation with id ".$participation->getId());
|
"You are not allowed to update participation with id ".$participation->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch ($event->getParticipations()->count()) {
|
switch ($event->getParticipations()->count()) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
// if there aren't any participation, redirect to the 'show' view with an add flash
|
// if there aren't any participation, redirect to the 'show' view with an add flash
|
||||||
$this->addFlash('warning', $this->get('translator')
|
$this->addFlash('warning', $this->get('translator')
|
||||||
->trans( "There are no participation to edit for this event"));
|
->trans( "There are no participation to edit for this event"));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show',
|
return $this->redirectToRoute('chill_event__event_show',
|
||||||
array('event_id' => $event->getId()));
|
array('event_id' => $event->getId()));
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// redirect to the form for a single participation
|
// redirect to the form for a single participation
|
||||||
return $this->redirectToRoute('chill_event_participation_edit', array(
|
return $this->redirectToRoute('chill_event_participation_edit', array(
|
||||||
'participation_id' => $event->getParticipations()->current()->getId()
|
'participation_id' => $event->getParticipations()->current()->getId()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
'participations' => $event->getParticipations(),
|
'participations' => $event->getParticipations(),
|
||||||
'form' => $form->createView()
|
'form' => $form->createView()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMultipleAction($event_id, Request $request)
|
public function updateMultipleAction($event_id, Request $request)
|
||||||
{
|
{
|
||||||
/* @var $event \Chill\EventBundle\Entity\Event */
|
/* @var $event \Chill\EventBundle\Entity\Event */
|
||||||
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
$event = $this->getDoctrine()->getRepository('ChillEventBundle:Event')
|
||||||
->find($event_id);
|
->find($event_id);
|
||||||
|
|
||||||
if ($event === null) {
|
if ($event === null) {
|
||||||
throw $this->createNotFoundException("The event with id $event_id is not found");
|
throw $this->createNotFoundException("The event with id $event_id is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
$this->denyAccessUnlessGranted('CHILL_EVENT_SEE', $event, "You are not allowed "
|
||||||
. "to see this event");
|
. "to see this event");
|
||||||
foreach ($event->getParticipations() as $participation) {
|
foreach ($event->getParticipations() as $participation) {
|
||||||
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
$this->denyAccessUnlessGranted(ParticipationVoter::UPDATE, $participation,
|
||||||
"You are not allowed to update participation with id ".$participation->getId());
|
"You are not allowed to update participation with id ".$participation->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
$form = $this->createEditFormMultiple($event->getParticipations(), $event);
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$this->getDoctrine()->getManager()->flush();
|
$this->getDoctrine()->getManager()->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')->trans("The participations "
|
$this->addFlash('success', $this->get('translator')->trans("The participations "
|
||||||
. "have been successfully updated."));
|
. "have been successfully updated."));
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show',
|
return $this->redirectToRoute('chill_event__event_show',
|
||||||
array('event_id' => $event->getId()));
|
array('event_id' => $event->getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
return $this->render('ChillEventBundle:Participation:edit-multiple.html.twig', array(
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
'participations' => $event->getParticipations(),
|
'participations' => $event->getParticipations(),
|
||||||
'form' => $form->createView()
|
'form' => $form->createView()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ArrayIterator $participations
|
* @param ArrayIterator $participations
|
||||||
* @param Event $event
|
* @param Event $event
|
||||||
@ -679,14 +684,14 @@ class ParticipationController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function createEditFormMultiple(ArrayIterator $participations, Event $event)
|
protected function createEditFormMultiple(ArrayIterator $participations, Event $event)
|
||||||
{
|
{
|
||||||
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
|
$form = $this->createForm(\Symfony\Component\Form\Extension\Core\Type\FormType::class,
|
||||||
array('participations' => $participations), array(
|
array('participations' => $participations), array(
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'action' => $this->generateUrl('chill_event_participation_update_multiple', array(
|
'action' => $this->generateUrl('chill_event_participation_update_multiple', array(
|
||||||
'event_id' => $event->getId()
|
'event_id' => $event->getId()
|
||||||
))
|
))
|
||||||
));
|
));
|
||||||
|
|
||||||
$form->add('participations', CollectionType::class, array(
|
$form->add('participations', CollectionType::class, array(
|
||||||
'entry_type' => ParticipationType::class,
|
'entry_type' => ParticipationType::class,
|
||||||
'entry_options' => array(
|
'entry_options' => array(
|
||||||
@ -694,14 +699,14 @@ class ParticipationController extends AbstractController
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$form->add('submit', SubmitType::class, array(
|
$form->add('submit', SubmitType::class, array(
|
||||||
'label' => 'Update'
|
'label' => 'Update'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param integer $participation_id
|
* @param integer $participation_id
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@ -713,28 +718,28 @@ class ParticipationController extends AbstractController
|
|||||||
$participation = $em->getRepository('ChillEventBundle:Participation')->findOneBy([
|
$participation = $em->getRepository('ChillEventBundle:Participation')->findOneBy([
|
||||||
'id' => $participation_id
|
'id' => $participation_id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! $participation) {
|
if (! $participation) {
|
||||||
throw $this->createNotFoundException('Unable to find participation.');
|
throw $this->createNotFoundException('Unable to find participation.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Event $event */
|
/** @var Event $event */
|
||||||
$event = $participation->getEvent();
|
$event = $participation->getEvent();
|
||||||
|
|
||||||
$form = $this->createDeleteForm($participation_id);
|
$form = $this->createDeleteForm($participation_id);
|
||||||
|
|
||||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
|
|
||||||
$em->remove($participation);
|
$em->remove($participation);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
$this->addFlash('success', $this->get('translator')
|
$this->addFlash('success', $this->get('translator')
|
||||||
->trans("The participation has been sucessfully removed")
|
->trans("The participation has been sucessfully removed")
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->redirectToRoute('chill_event__event_show', [
|
return $this->redirectToRoute('chill_event__event_show', [
|
||||||
'event_id' => $event->getId()
|
'event_id' => $event->getId()
|
||||||
]);
|
]);
|
||||||
@ -744,9 +749,9 @@ class ParticipationController extends AbstractController
|
|||||||
'event_id' => $event->getId(),
|
'event_id' => $event->getId(),
|
||||||
'delete_form' => $form->createView()
|
'delete_form' => $form->createView()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $participation_id
|
* @param $participation_id
|
||||||
* @return \Symfony\Component\Form\FormInterface
|
* @return \Symfony\Component\Form\FormInterface
|
||||||
@ -762,5 +767,5 @@ class ParticipationController extends AbstractController
|
|||||||
->getForm()
|
->getForm()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -504,6 +504,8 @@ class ApiController extends AbstractCRUDController
|
|||||||
$this->getContextForSerializationPostAlter($action, $request, $_format, $entity, [$postedData])
|
$this->getContextForSerializationPostAlter($action, $request, $_format, $entity, [$postedData])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \Exception('Unable to handle such request method.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,18 +10,18 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop
|
* @author Julien Fastré <julien.fastre@champs-libres.coop
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class LoadCountriesCommand extends Command
|
class LoadCountriesCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityManager
|
* @var EntityManager
|
||||||
*/
|
*/
|
||||||
private $entityManager;
|
private $entityManager;
|
||||||
|
|
||||||
private $availableLanguages;
|
private $availableLanguages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LoadCountriesCommand constructor.
|
* LoadCountriesCommand constructor.
|
||||||
*
|
*
|
||||||
@ -34,7 +34,7 @@ class LoadCountriesCommand extends Command
|
|||||||
$this->availableLanguages=$availableLanguages;
|
$this->availableLanguages=$availableLanguages;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-PHPdoc)
|
* (non-PHPdoc)
|
||||||
* @see \Symfony\Component\Console\Command\Command::configure()
|
* @see \Symfony\Component\Console\Command\Command::configure()
|
||||||
@ -45,7 +45,7 @@ class LoadCountriesCommand extends Command
|
|||||||
->setDescription('Load or update countries in db. This command does not delete existing countries, '.
|
->setDescription('Load or update countries in db. This command does not delete existing countries, '.
|
||||||
'but will update names according to available languages');
|
'but will update names according to available languages');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-PHPdoc)
|
* (non-PHPdoc)
|
||||||
* @see \Symfony\Component\Console\Command\Command::execute()
|
* @see \Symfony\Component\Console\Command\Command::execute()
|
||||||
@ -54,43 +54,44 @@ class LoadCountriesCommand extends Command
|
|||||||
{
|
{
|
||||||
$countries = static::prepareCountryList($this->availableLanguages);
|
$countries = static::prepareCountryList($this->availableLanguages);
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
|
|
||||||
foreach($countries as $country) {
|
foreach($countries as $country) {
|
||||||
$countryStored = $em->getRepository('ChillMainBundle:Country')
|
$countryStored = $em->getRepository('ChillMainBundle:Country')
|
||||||
->findOneBy(array('countryCode' => $country->getCountryCode()));
|
->findOneBy(array('countryCode' => $country->getCountryCode()));
|
||||||
|
|
||||||
if (NULL === $countryStored) {
|
if (NULL === $countryStored) {
|
||||||
$em->persist($country);
|
$em->persist($country);
|
||||||
} else {
|
} else {
|
||||||
$countryStored->setName($country->getName());
|
$countryStored->setName($country->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function prepareCountryList($languages)
|
public static function prepareCountryList($languages)
|
||||||
{
|
{
|
||||||
$regionBundle = Intl::getRegionBundle();
|
$regionBundle = Intl::getRegionBundle();
|
||||||
|
$countries = [];
|
||||||
|
|
||||||
foreach ($languages as $language) {
|
foreach ($languages as $language) {
|
||||||
$countries[$language] = $regionBundle->getCountryNames($language);
|
$countries[$language] = $regionBundle->getCountryNames($language);
|
||||||
}
|
}
|
||||||
|
|
||||||
$countryEntities = array();
|
$countryEntities = array();
|
||||||
|
|
||||||
foreach ($countries[$languages[0]] as $countryCode => $name) {
|
foreach ($countries[$languages[0]] as $countryCode => $name) {
|
||||||
$names = array();
|
$names = array();
|
||||||
|
|
||||||
foreach ($languages as $language) {
|
foreach ($languages as $language) {
|
||||||
$names[$language] = $countries[$language][$countryCode];
|
$names[$language] = $countries[$language][$countryCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
$country = new \Chill\MainBundle\Entity\Country();
|
$country = new \Chill\MainBundle\Entity\Country();
|
||||||
$country->setName($names)->setCountryCode($countryCode);
|
$country->setName($names)->setCountryCode($countryCode);
|
||||||
$countryEntities[] = $country;
|
$countryEntities[] = $country;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $countryEntities;
|
return $countryEntities;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,26 +24,26 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
|
|||||||
// Array of ancien languages (to exclude)
|
// Array of ancien languages (to exclude)
|
||||||
private $ancientToExclude = ["ang", "egy", "fro", "goh", "grc", "la", "non", "peo", "pro", "sga",
|
private $ancientToExclude = ["ang", "egy", "fro", "goh", "grc", "la", "non", "peo", "pro", "sga",
|
||||||
"dum", "enm", "frm", "gmh", "mga", "akk", "phn", "zxx", "got", "und"];
|
"dum", "enm", "frm", "gmh", "mga", "akk", "phn", "zxx", "got", "und"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var ContainerInterface
|
* @var ContainerInterface
|
||||||
*/
|
*/
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
public function setContainer(ContainerInterface $container = null)
|
public function setContainer(ContainerInterface $container = null)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder() {
|
public function getOrder() {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager) {
|
public function load(ObjectManager $manager) {
|
||||||
|
|
||||||
echo "loading languages... \n";
|
echo "loading languages... \n";
|
||||||
|
|
||||||
foreach (Intl::getLanguageBundle()->getLanguageNames() as $code => $language) {
|
foreach (Intl::getLanguageBundle()->getLanguageNames() as $code => $language) {
|
||||||
if (
|
if (
|
||||||
!in_array($code, $this->regionalVersionToInclude)
|
!in_array($code, $this->regionalVersionToInclude)
|
||||||
@ -58,23 +58,24 @@ class LoadLanguages extends AbstractFixture implements ContainerAwareInterface,
|
|||||||
$manager->persist($lang);
|
$manager->persist($lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepare names for languages
|
* Prepare names for languages.
|
||||||
*
|
*
|
||||||
* @param string $languageCode
|
|
||||||
* @return string[] languages name indexed by available language code
|
* @return string[] languages name indexed by available language code
|
||||||
*/
|
*/
|
||||||
private function prepareName($languageCode) {
|
private function prepareName(string $languageCode): array {
|
||||||
|
$names = [];
|
||||||
|
|
||||||
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
foreach ($this->container->getParameter('chill_main.available_languages') as $lang) {
|
||||||
$names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode);
|
$names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $names;
|
return $names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
*/
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Chill\MainBundle\Form\PermissionsGroupType;
|
use Chill\MainBundle\Form\PermissionsGroupType;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use LogicException;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
|
||||||
*/
|
|
||||||
class ACLFlagsCompilerPass implements CompilerPassInterface
|
class ACLFlagsCompilerPass implements CompilerPassInterface
|
||||||
{
|
{
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$permissionGroupType = $container->getDefinition(PermissionsGroupType::class);
|
$permissionGroupType = $container->getDefinition(PermissionsGroupType::class);
|
||||||
|
|
||||||
foreach($container->findTaggedServiceIds('chill_main.flags') as $id => $tags) {
|
foreach($container->findTaggedServiceIds('chill_main.flags') as $id => $tags) {
|
||||||
$reference = new Reference($id);
|
$reference = new Reference($id);
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
switch($tag['scope']) {
|
switch($tag['scope']) {
|
||||||
case PermissionsGroupType::FLAG_SCOPE:
|
case PermissionsGroupType::FLAG_SCOPE:
|
||||||
|
|
||||||
$permissionGroupType->addMethodCall('addFlagProvider', [ $reference ]);
|
$permissionGroupType->addMethodCall('addFlagProvider', [ $reference ]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \LogicalException(sprintf(
|
throw new LogicException(sprintf(
|
||||||
"This tag 'scope' is not implemented: %s, on service with id %s", $tag['scope'], $id)
|
"This tag 'scope' is not implemented: %s, on service with id %s", $tag['scope'], $id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,11 @@ class Configuration implements ConfigurationInterface
|
|||||||
|
|
||||||
use AddWidgetConfigurationTrait;
|
use AddWidgetConfigurationTrait;
|
||||||
|
|
||||||
/**
|
private ContainerBuilder $containerBuilder;
|
||||||
*
|
|
||||||
* @var ContainerBuilder
|
|
||||||
*/
|
|
||||||
private $containerBuilder;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(array $widgetFactories = array(),
|
public function __construct(
|
||||||
|
array $widgetFactories,
|
||||||
ContainerBuilder $containerBuilder)
|
ContainerBuilder $containerBuilder)
|
||||||
{
|
{
|
||||||
$this->setWidgetFactories($widgetFactories);
|
$this->setWidgetFactories($widgetFactories);
|
||||||
|
@ -30,27 +30,27 @@ use Chill\MainBundle\DependencyInjection\Widget\HasWidgetFactoriesExtensionInter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile the configurations and inject required service into container.
|
* Compile the configurations and inject required service into container.
|
||||||
*
|
*
|
||||||
* The widgets are services tagged with :
|
* The widgets are services tagged with :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* { name: chill_widget, alias: my_alias, place: my_place }
|
* { name: chill_widget, alias: my_alias, place: my_place }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* Or, if the tag does not exist or if you need to add some config to your
|
* Or, if the tag does not exist or if you need to add some config to your
|
||||||
* service depending on the config, you should use a `WidgetFactory` (see
|
* service depending on the config, you should use a `WidgetFactory` (see
|
||||||
* `WidgetFactoryInterface`.
|
* `WidgetFactoryInterface`.
|
||||||
*
|
*
|
||||||
* To reuse this compiler pass, simple execute the doProcess metho in your
|
* To reuse this compiler pass, simple execute the doProcess metho in your
|
||||||
* compiler. Example :
|
* compiler. Example :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
* namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||||
*
|
*
|
||||||
* use Symfony\Component\DependencyInjection\ContainerBuilder;
|
* use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
* use Chill\MainBundle\DependencyInjection\Widget\AbstractWidgetsCompilerPass;
|
* use Chill\MainBundle\DependencyInjection\Widget\AbstractWidgetsCompilerPass;
|
||||||
* class WidgetsCompilerPass extends AbstractWidgetsCompilerPass {
|
* class WidgetsCompilerPass extends AbstractWidgetsCompilerPass {
|
||||||
*
|
*
|
||||||
* public function process(ContainerBuilder $container)
|
* public function process(ContainerBuilder $container)
|
||||||
* {
|
* {
|
||||||
* $this->doProcess($container, 'chill_main', 'chill_main.widgets');
|
* $this->doProcess($container, 'chill_main', 'chill_main.widgets');
|
||||||
@ -58,58 +58,58 @@ use Chill\MainBundle\DependencyInjection\Widget\HasWidgetFactoriesExtensionInter
|
|||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||||
{
|
{
|
||||||
private $widgetServices = array();
|
private $widgetServices = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var WidgetFactoryInterface[]
|
* @var WidgetFactoryInterface[]
|
||||||
*/
|
*/
|
||||||
private $widgetFactories;
|
private $widgetFactories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service which will manage the widgets
|
* The service which will manage the widgets
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const WIDGET_MANAGER = 'chill.main.twig.widget';
|
const WIDGET_MANAGER = 'chill.main.twig.widget';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the method wich register the widget into give service.
|
* the method wich register the widget into give service.
|
||||||
*/
|
*/
|
||||||
const WIDGET_MANAGER_METHOD_REGISTER = 'addWidget';
|
const WIDGET_MANAGER_METHOD_REGISTER = 'addWidget';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the value of the `name` key in service definitions's tag
|
* the value of the `name` key in service definitions's tag
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const WIDGET_SERVICE_TAG_NAME = 'chill_widget';
|
const WIDGET_SERVICE_TAG_NAME = 'chill_widget';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the key used to collect the alias in the service definition's tag.
|
* the key used to collect the alias in the service definition's tag.
|
||||||
* the alias must be
|
* the alias must be
|
||||||
* injected into the configuration under 'alias' key.
|
* injected into the configuration under 'alias' key.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const WIDGET_SERVICE_TAG_ALIAS = 'alias';
|
const WIDGET_SERVICE_TAG_ALIAS = 'alias';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the key used to collect the authorized place in the service definition's tag
|
* the key used to collect the authorized place in the service definition's tag
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const WIDGET_SERVICE_TAG_PLACES = 'place';
|
const WIDGET_SERVICE_TAG_PLACES = 'place';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the key to use to order widget for a given place
|
* the key to use to order widget for a given place
|
||||||
*/
|
*/
|
||||||
const WIDGET_CONFIG_ORDER = 'order';
|
const WIDGET_CONFIG_ORDER = 'order';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the key to use to identify widget for a given place
|
* the key to use to identify widget for a given place
|
||||||
*/
|
*/
|
||||||
@ -118,24 +118,25 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* process the configuration and the container to add the widget available
|
* process the configuration and the container to add the widget available
|
||||||
*
|
*
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param string $extension the extension of your bundle
|
* @param string $extension the extension of your bundle
|
||||||
* @param string $containerWidgetConfigParameterName the key under which we can use the widget configuration
|
* @param string $containerWidgetConfigParameterName the key under which we can use the widget configuration
|
||||||
* @throws \LogicException
|
* @throws \LogicException
|
||||||
* @throws \UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
|
* @throws \UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
|
||||||
* @throws \InvalidConfigurationException if there are errors in the config
|
|
||||||
*/
|
*/
|
||||||
public function doProcess(ContainerBuilder $container, $extension,
|
public function doProcess(
|
||||||
$containerWidgetConfigParameterName)
|
ContainerBuilder $container,
|
||||||
{
|
$extension,
|
||||||
|
$containerWidgetConfigParameterName
|
||||||
|
) {
|
||||||
if (!$container->hasDefinition(self::WIDGET_MANAGER)) {
|
if (!$container->hasDefinition(self::WIDGET_MANAGER)) {
|
||||||
throw new \LogicException("the service ".self::WIDGET_MANAGER." should".
|
throw new \LogicException("the service ".self::WIDGET_MANAGER." should".
|
||||||
" be present. It is required by ".self::class);
|
" be present. It is required by ".self::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
$managerDefinition = $container->getDefinition(self::WIDGET_MANAGER);
|
$managerDefinition = $container->getDefinition(self::WIDGET_MANAGER);
|
||||||
|
|
||||||
// collect the widget factories
|
// collect the widget factories
|
||||||
/* @var $extensionClass HasWidgetFactoriesExtensionInterface */
|
/* @var $extensionClass HasWidgetFactoriesExtensionInterface */
|
||||||
$extensionClass = $container->getExtension($extension);
|
$extensionClass = $container->getExtension($extension);
|
||||||
@ -148,19 +149,19 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
HasWidgetFactoriesExtensionInterface::class,
|
HasWidgetFactoriesExtensionInterface::class,
|
||||||
get_class($extensionClass)));
|
get_class($extensionClass)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->widgetFactories = $extensionClass->getWidgetFactories();
|
$this->widgetFactories = $extensionClass->getWidgetFactories();
|
||||||
|
|
||||||
// collect the availabled tagged services
|
// collect the availabled tagged services
|
||||||
$this->collectTaggedServices($container);
|
$this->collectTaggedServices($container);
|
||||||
|
|
||||||
// collect the widgets and their config :
|
// collect the widgets and their config :
|
||||||
$widgetParameters = $container->getParameter($containerWidgetConfigParameterName);
|
$widgetParameters = $container->getParameter($containerWidgetConfigParameterName);
|
||||||
|
|
||||||
// and add them to the delegated_block
|
// and add them to the delegated_block
|
||||||
foreach($widgetParameters as $place => $widgets) {
|
foreach($widgetParameters as $place => $widgets) {
|
||||||
|
|
||||||
foreach ($widgets as $param) {
|
foreach ($widgets as $param) {
|
||||||
$alias = $param[self::WIDGET_CONFIG_ALIAS];
|
$alias = $param[self::WIDGET_CONFIG_ALIAS];
|
||||||
// check that the service exists
|
// check that the service exists
|
||||||
@ -168,43 +169,43 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
throw new InvalidConfigurationException(sprintf("The alias %s".
|
throw new InvalidConfigurationException(sprintf("The alias %s".
|
||||||
" is not defined.", $alias));
|
" is not defined.", $alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the widget is allowed at this place
|
// check that the widget is allowed at this place
|
||||||
if (!$this->isPlaceAllowedForWidget($place, $alias, $container)) {
|
if (!$this->isPlaceAllowedForWidget($place, $alias, $container)) {
|
||||||
throw new \InvalidConfigurationException(sprintf(
|
throw new InvalidConfigurationException(sprintf(
|
||||||
"The widget with alias %s is not allowed at place %s",
|
"The widget with alias %s is not allowed at place %s",
|
||||||
$alias,
|
$alias,
|
||||||
$place
|
$place
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the order, eventually corrected
|
// get the order, eventually corrected
|
||||||
$order = $this->cacheAndGetOrdering($place, $param[self::WIDGET_CONFIG_ORDER]);
|
$order = $this->cacheAndGetOrdering($place, $param[self::WIDGET_CONFIG_ORDER]);
|
||||||
|
|
||||||
// register the widget with config to the service, using the method
|
// register the widget with config to the service, using the method
|
||||||
// `addWidget`
|
// `addWidget`
|
||||||
if ($this->widgetServices[$alias] instanceof WidgetFactoryInterface) {
|
if ($this->widgetServices[$alias] instanceof WidgetFactoryInterface) {
|
||||||
/* @var $factory WidgetFactoryInterface */
|
/* @var $factory WidgetFactoryInterface */
|
||||||
$factory = $this->widgetServices[$alias];
|
$factory = $this->widgetServices[$alias];
|
||||||
// get the config (under the key which equals to widget_alias
|
// get the config (under the key which equals to widget_alias
|
||||||
$config = isset($param[$factory->getWidgetAlias()]) ?
|
$config = isset($param[$factory->getWidgetAlias()]) ?
|
||||||
$param[$factory->getWidgetAlias()] : array();
|
$param[$factory->getWidgetAlias()] : array();
|
||||||
// register the service into the container
|
// register the service into the container
|
||||||
$serviceId =$this->registerServiceIntoContainer($container,
|
$serviceId =$this->registerServiceIntoContainer($container,
|
||||||
$factory, $place, $order, $config);
|
$factory, $place, $order, $config);
|
||||||
|
|
||||||
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||||
array(
|
array(
|
||||||
$place,
|
$place,
|
||||||
$order,
|
$order,
|
||||||
new Reference($serviceId),
|
new Reference($serviceId),
|
||||||
$config
|
$config
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||||
array(
|
array(
|
||||||
$place,
|
$place,
|
||||||
$order,
|
$order,
|
||||||
new Reference($this->widgetServices[$alias]),
|
new Reference($this->widgetServices[$alias]),
|
||||||
array() // the config is alway an empty array
|
array() // the config is alway an empty array
|
||||||
));
|
));
|
||||||
@ -212,10 +213,10 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register the service into container.
|
* register the service into container.
|
||||||
*
|
*
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @param WidgetFactoryInterface $factory
|
* @param WidgetFactoryInterface $factory
|
||||||
* @param string $place
|
* @param string $place
|
||||||
@ -231,28 +232,28 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
array $config
|
array $config
|
||||||
) {
|
) {
|
||||||
$serviceId = $factory->getServiceId($container, $place, $order, $config);
|
$serviceId = $factory->getServiceId($container, $place, $order, $config);
|
||||||
$definition = $factory->createDefinition($container, $place,
|
$definition = $factory->createDefinition($container, $place,
|
||||||
$order, $config);
|
$order, $config);
|
||||||
$container->setDefinition($serviceId, $definition);
|
$container->setDefinition($serviceId, $definition);
|
||||||
|
|
||||||
return $serviceId;
|
return $serviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache of ordering by place.
|
* cache of ordering by place.
|
||||||
*
|
*
|
||||||
* @internal used by function cacheAndGetOrdering
|
* @internal used by function cacheAndGetOrdering
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $cacheOrdering = array();
|
private $cacheOrdering = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the ordering has already be used for the given $place and,
|
* check if the ordering has already be used for the given $place and,
|
||||||
* if yes, correct the ordering by incrementation of 1 until the ordering
|
* if yes, correct the ordering by incrementation of 1 until the ordering
|
||||||
* has not be used.
|
* has not be used.
|
||||||
*
|
*
|
||||||
* recursive method.
|
* recursive method.
|
||||||
*
|
*
|
||||||
* @param string $place
|
* @param string $place
|
||||||
* @param float $ordering
|
* @param float $ordering
|
||||||
* @return float
|
* @return float
|
||||||
@ -262,7 +263,7 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
if (!array_key_exists($place, $this->cacheOrdering)) {
|
if (!array_key_exists($place, $this->cacheOrdering)) {
|
||||||
$this->cacheOrdering[$place] = array();
|
$this->cacheOrdering[$place] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the order exists
|
// check if the order exists
|
||||||
if (array_search($ordering, $this->cacheOrdering[$place])) {
|
if (array_search($ordering, $this->cacheOrdering[$place])) {
|
||||||
// if the order exists, increment of 1 and try again
|
// if the order exists, increment of 1 and try again
|
||||||
@ -270,14 +271,14 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
} else {
|
} else {
|
||||||
// cache the ordering
|
// cache the ordering
|
||||||
$this->cacheOrdering[$place][] = $ordering;
|
$this->cacheOrdering[$place][] = $ordering;
|
||||||
|
|
||||||
return $ordering;
|
return $ordering;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the places where the service is allowed
|
* get the places where the service is allowed
|
||||||
*
|
*
|
||||||
* @param Definition $definition
|
* @param Definition $definition
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
@ -288,7 +289,7 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
->getAllowedPlaces())) {
|
->getAllowedPlaces())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$definition = $container->findDefinition($this->widgetServices[$widgetAlias]);
|
$definition = $container->findDefinition($this->widgetServices[$widgetAlias]);
|
||||||
|
|
||||||
@ -300,17 +301,17 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method collect all service tagged with `self::WIDGET_SERVICE_TAG`, and
|
* This method collect all service tagged with `self::WIDGET_SERVICE_TAG`, and
|
||||||
* add also the widget defined by factories
|
* add also the widget defined by factories
|
||||||
*
|
*
|
||||||
* This method also check that the service is correctly tagged with `alias` and
|
* This method also check that the service is correctly tagged with `alias` and
|
||||||
* `places`, or the factory give a correct alias and more than one place.
|
* `places`, or the factory give a correct alias and more than one place.
|
||||||
*
|
*
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
* @throws InvalidConfigurationException
|
* @throws InvalidConfigurationException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
@ -320,13 +321,13 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
// first, check the service tagged in service definition
|
// first, check the service tagged in service definition
|
||||||
foreach ($container->findTaggedServiceIds(self::WIDGET_SERVICE_TAG_NAME) as $id => $attrs) {
|
foreach ($container->findTaggedServiceIds(self::WIDGET_SERVICE_TAG_NAME) as $id => $attrs) {
|
||||||
foreach ($attrs as $attr) {
|
foreach ($attrs as $attr) {
|
||||||
|
|
||||||
// check the alias is set
|
// check the alias is set
|
||||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_ALIAS])) {
|
if (!isset($attr[self::WIDGET_SERVICE_TAG_ALIAS])) {
|
||||||
throw new InvalidConfigurationException("you should add an ".self::WIDGET_SERVICE_TAG_ALIAS.
|
throw new InvalidConfigurationException("you should add an ".self::WIDGET_SERVICE_TAG_ALIAS.
|
||||||
" key on the service ".$id);
|
" key on the service ".$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the place is set
|
// check the place is set
|
||||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_PLACES])) {
|
if (!isset($attr[self::WIDGET_SERVICE_TAG_PLACES])) {
|
||||||
throw new InvalidConfigurationException(sprintf(
|
throw new InvalidConfigurationException(sprintf(
|
||||||
@ -335,54 +336,54 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
|||||||
$id
|
$id
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the alias does not exists yet
|
// check the alias does not exists yet
|
||||||
if (array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
|
if (array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
|
||||||
throw new InvalidArgumentException("a service has already be defined with the ".
|
throw new InvalidArgumentException("a service has already be defined with the ".
|
||||||
self::WIDGET_SERVICE_TAG_ALIAS." ".$attr[self::WIDGET_SERVICE_TAG_ALIAS]);
|
self::WIDGET_SERVICE_TAG_ALIAS." ".$attr[self::WIDGET_SERVICE_TAG_ALIAS]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the service as available
|
// register the service as available
|
||||||
$this->widgetServices[$attr[self::WIDGET_SERVICE_TAG_ALIAS]] = $id;
|
$this->widgetServices[$attr[self::WIDGET_SERVICE_TAG_ALIAS]] = $id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the services defined by factories
|
// add the services defined by factories
|
||||||
foreach($this->widgetFactories as $factory) {
|
foreach($this->widgetFactories as $factory) {
|
||||||
/* @var $factory WidgetFactoryInterface */
|
/* @var $factory WidgetFactoryInterface */
|
||||||
$alias = $factory->getWidgetAlias();
|
$alias = $factory->getWidgetAlias();
|
||||||
|
|
||||||
// check the alias is not empty
|
// check the alias is not empty
|
||||||
if (empty($alias)) {
|
if (empty($alias)) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
"the widget factory %s returns an empty alias",
|
"the widget factory %s returns an empty alias",
|
||||||
get_class($factory)));
|
get_class($factory)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the places are not empty
|
// check the places are not empty
|
||||||
if (!is_array($factory->getAllowedPlaces())) {
|
if (!is_array($factory->getAllowedPlaces())) {
|
||||||
throw new \UnexpectedValueException("the method 'getAllowedPlaces' "
|
throw new \UnexpectedValueException("the method 'getAllowedPlaces' "
|
||||||
. "should return a non-empty array. Unexpected value on ".
|
. "should return a non-empty array. Unexpected value on ".
|
||||||
get_class($factory));
|
get_class($factory));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($factory->getAllowedPlaces()) == 0) {
|
if (count($factory->getAllowedPlaces()) == 0) {
|
||||||
throw new \LengthException("The method 'getAllowedPlaces' should "
|
throw new \LengthException("The method 'getAllowedPlaces' should "
|
||||||
. "return a non-empty array, but returned 0 elements on ".
|
. "return a non-empty array, but returned 0 elements on ".
|
||||||
get_class($factory).'::getAllowedPlaces()');
|
get_class($factory).'::getAllowedPlaces()');
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the alias does not exists yet
|
// check the alias does not exists yet
|
||||||
if (array_key_exists($alias, $this->widgetServices)) {
|
if (array_key_exists($alias, $this->widgetServices)) {
|
||||||
throw new InvalidArgumentException("a service has already be defined with the ".
|
throw new InvalidArgumentException("a service has already be defined with the ".
|
||||||
self::WIDGET_SERVICE_TAG_ALIAS." ".$alias);
|
self::WIDGET_SERVICE_TAG_ALIAS." ".$alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the factory as available
|
// register the factory as available
|
||||||
$this->widgetServices[$factory->getWidgetAlias()] = $factory;
|
$this->widgetServices[$factory->getWidgetAlias()] = $factory;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,9 @@ namespace Chill\MainBundle\Doctrine\Model;
|
|||||||
|
|
||||||
use \JsonSerializable;
|
use \JsonSerializable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of Point
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Point implements JsonSerializable {
|
class Point implements JsonSerializable {
|
||||||
private ?float $lat = null;
|
private ?float $lat;
|
||||||
private ?float $lon = null;
|
private ?float $lon;
|
||||||
public static string $SRID = '4326';
|
public static string $SRID = '4326';
|
||||||
|
|
||||||
private function __construct(?float $lon, ?float $lat)
|
private function __construct(?float $lon, ?float $lat)
|
||||||
@ -22,6 +18,7 @@ class Point implements JsonSerializable {
|
|||||||
public function toGeoJson(): string
|
public function toGeoJson(): string
|
||||||
{
|
{
|
||||||
$array = $this->toArrayGeoJson();
|
$array = $this->toArrayGeoJson();
|
||||||
|
|
||||||
return \json_encode($array);
|
return \json_encode($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,60 +30,53 @@ class Point implements JsonSerializable {
|
|||||||
public function toArrayGeoJson(): array
|
public function toArrayGeoJson(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
"type" => "Point",
|
'type' => 'Point',
|
||||||
"coordinates" => [ $this->lon, $this->lat ]
|
'coordinates' => [$this->lon, $this->lat],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function toWKT(): string
|
public function toWKT(): string
|
||||||
{
|
{
|
||||||
return 'SRID='.self::$SRID.';POINT('.$this->lon.' '.$this->lat.')';
|
return sprintf("SRID=%s;POINT(%s %s)", self::$SRID, $this->lon, $this->lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function fromGeoJson(string $geojson): self
|
||||||
*
|
|
||||||
* @param type $geojson
|
|
||||||
* @return Point
|
|
||||||
*/
|
|
||||||
public static function fromGeoJson(string $geojson): Point
|
|
||||||
{
|
{
|
||||||
$a = json_decode($geojson);
|
$a = json_decode($geojson);
|
||||||
//check if the geojson string is correct
|
|
||||||
if (NULL === $a or !isset($a->type) or !isset($a->coordinates)){
|
if (null === $a) {
|
||||||
throw PointException::badJsonString($geojson);
|
throw PointException::badJsonString($geojson);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($a->type != 'Point'){
|
if (null === $a->type || null === $a->coordinates) {
|
||||||
|
throw PointException::badJsonString($geojson);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($a->type !== 'Point'){
|
||||||
throw PointException::badGeoType();
|
throw PointException::badGeoType();
|
||||||
}
|
}
|
||||||
|
|
||||||
$lat = $a->coordinates[1];
|
[$lon, $lat] = $a->coordinates;
|
||||||
$lon = $a->coordinates[0];
|
|
||||||
|
|
||||||
return Point::fromLonLat($lon, $lat);
|
return Point::fromLonLat($lon, $lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromLonLat(float $lon, float $lat): Point
|
public static function fromLonLat(float $lon, float $lat): self
|
||||||
{
|
{
|
||||||
if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90))
|
if (($lon > -180 && $lon < 180) && ($lat > -90 && $lat < 90)) {
|
||||||
{
|
|
||||||
return new Point($lon, $lat);
|
return new Point($lon, $lat);
|
||||||
} else {
|
|
||||||
throw PointException::badCoordinates($lon, $lat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw PointException::badCoordinates($lon, $lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromArrayGeoJson(array $array): Point
|
public static function fromArrayGeoJson(array $array): self
|
||||||
{
|
{
|
||||||
if ($array['type'] == 'Point' &&
|
if ($array['type'] === 'Point' && isset($array['coordinates'])) {
|
||||||
isset($array['coordinates']))
|
|
||||||
{
|
|
||||||
return self::fromLonLat($array['coordinates'][0], $array['coordinates'][1]);
|
return self::fromLonLat($array['coordinates'][0], $array['coordinates'][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \Exception('Unable to build a point from input data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLat(): float
|
public function getLat(): float
|
||||||
|
@ -51,8 +51,10 @@ class CenterTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
|
||||||
if ($this->multiple) {
|
if ($this->multiple) {
|
||||||
$ids = \explode(',', $id);
|
$ids = explode(',', $id);
|
||||||
} else {
|
} else {
|
||||||
$ids[] = (int) $id;
|
$ids[] = (int) $id;
|
||||||
}
|
}
|
||||||
@ -68,9 +70,9 @@ class CenterTransformer implements DataTransformerInterface
|
|||||||
|
|
||||||
if ($this->multiple) {
|
if ($this->multiple) {
|
||||||
return new ArrayCollection($centers);
|
return new ArrayCollection($centers);
|
||||||
} else {
|
|
||||||
return $centers[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $centers[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transform($center)
|
public function transform($center)
|
||||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Repository;
|
namespace Chill\MainBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\GroupCenter;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
@ -139,7 +139,7 @@ class SearchApi
|
|||||||
return $nq->getResult();
|
return $nq->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareProviders($rawResults)
|
private function prepareProviders(array $rawResults)
|
||||||
{
|
{
|
||||||
$metadatas = [];
|
$metadatas = [];
|
||||||
foreach ($rawResults as $r) {
|
foreach ($rawResults as $r) {
|
||||||
@ -156,8 +156,10 @@ class SearchApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildResults($rawResults)
|
private function buildResults(array $rawResults): array
|
||||||
{
|
{
|
||||||
|
$items = [];
|
||||||
|
|
||||||
foreach ($rawResults as $r) {
|
foreach ($rawResults as $r) {
|
||||||
foreach ($this->providers as $k => $p) {
|
foreach ($this->providers as $k => $p) {
|
||||||
if ($p->supportsResult($r['key'], $r['metadata'])) {
|
if ($p->supportsResult($r['key'], $r['metadata'])) {
|
||||||
@ -170,6 +172,6 @@ class SearchApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $items ?? [];
|
return $items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,5 +98,7 @@ class PasswordRecoverVoter extends Voter
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
@ -12,31 +14,41 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|||||||
{
|
{
|
||||||
use NormalizerAwareTrait;
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Address $address
|
||||||
|
*/
|
||||||
public function normalize($address, string $format = null, array $context = [])
|
public function normalize($address, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
/** @var Address $address */
|
$data = [
|
||||||
$data['address_id'] = $address->getId();
|
'address_id' => $address->getId(),
|
||||||
$data['text'] = $address->isNoAddress() ? '' : $address->getStreetNumber().', '.$address->getStreet();
|
'text' => $address->isNoAddress() ? '' : $address->getStreetNumber().', '.$address->getStreet(),
|
||||||
$data['street'] = $address->getStreet();
|
'street' => $address->getStreet(),
|
||||||
$data['streetNumber'] = $address->getStreetNumber();
|
'streetNumber' => $address->getStreetNumber(),
|
||||||
$data['postcode']['id'] = $address->getPostCode()->getId();
|
'postcode' => [
|
||||||
$data['postcode']['name'] = $address->getPostCode()->getName();
|
'id' => $address->getPostCode()->getId(),
|
||||||
$data['postcode']['code'] = $address->getPostCode()->getCode();
|
'name' => $address->getPostCode()->getName(),
|
||||||
$data['country']['id'] = $address->getPostCode()->getCountry()->getId();
|
'code' => $address->getPostCode()->getCode(),
|
||||||
$data['country']['name'] = $address->getPostCode()->getCountry()->getName();
|
],
|
||||||
$data['country']['code'] = $address->getPostCode()->getCountry()->getCountryCode();
|
'country' => [
|
||||||
$data['floor'] = $address->getFloor();
|
'id' => $address->getPostCode()->getCountry()->getId(),
|
||||||
$data['corridor'] = $address->getCorridor();
|
'name' => $address->getPostCode()->getCountry()->getName(),
|
||||||
$data['steps'] = $address->getSteps();
|
'code' => $address->getPostCode()->getCountry()->getCountryCode(),
|
||||||
$data['flat'] = $address->getFlat();
|
],
|
||||||
$data['buildingName'] = $address->getBuildingName();
|
'floor' => $address->getFloor(),
|
||||||
$data['distribution'] = $address->getDistribution();
|
'corridor' => $address->getCorridor(),
|
||||||
$data['extra'] = $address->getExtra();
|
'steps' => $address->getSteps(),
|
||||||
$data['validFrom'] = $address->getValidFrom();
|
'flat' => $address->getFlat(),
|
||||||
$data['validTo'] = $address->getValidTo();
|
'buildingName' => $address->getBuildingName(),
|
||||||
$data['addressReference'] = $this->normalizer->normalize($address->getAddressReference(), $format, [
|
'distribution' => $address->getDistribution(),
|
||||||
AbstractNormalizer::GROUPS => ['read']
|
'extra' => $address->getExtra(),
|
||||||
]);
|
'validFrom' => $address->getValidFrom(),
|
||||||
|
'validTo' => $address->getValidTo(),
|
||||||
|
'addressReference' => $this->normalizer->normalize(
|
||||||
|
$address->getAddressReference(),
|
||||||
|
$format,
|
||||||
|
[AbstractNormalizer::GROUPS => ['read']]
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -9,32 +9,30 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
|||||||
|
|
||||||
class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
class CollectionNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
||||||
{
|
{
|
||||||
use NormalizerAwareTrait;
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $collection
|
||||||
|
*/
|
||||||
|
public function normalize($collection, string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
$paginator = $collection->getPaginator();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'count' => $paginator->getTotalItems(),
|
||||||
|
'pagination' => [
|
||||||
|
'first' => $paginator->getCurrentPageFirstItemNumber(),
|
||||||
|
'items_per_page' => $paginator->getItemsPerPage(),
|
||||||
|
'next' => $paginator->hasNextPage() ? $paginator->getNextPage()->generateUrl() : null,
|
||||||
|
'previous' => $paginator->hasPreviousPage() ? $paginator->getPreviousPage()->generateUrl() : null,
|
||||||
|
'more' => $paginator->hasNextPage(),
|
||||||
|
],
|
||||||
|
'results' => $this->normalizer->normalize($collection->getItems(), $format, $context),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, string $format = null): bool
|
public function supportsNormalization($data, string $format = null): bool
|
||||||
{
|
{
|
||||||
return $data instanceof Collection;
|
return $data instanceof Collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function normalize($collection, string $format = null, array $context = [])
|
|
||||||
{
|
|
||||||
/** @var $collection Collection */
|
|
||||||
$paginator = $collection->getPaginator();
|
|
||||||
|
|
||||||
$data['count'] = $paginator->getTotalItems();
|
|
||||||
$pagination['first'] = $paginator->getCurrentPageFirstItemNumber();
|
|
||||||
$pagination['items_per_page'] = $paginator->getItemsPerPage();
|
|
||||||
$pagination['next'] = $paginator->hasNextPage() ?
|
|
||||||
$paginator->getNextPage()->generateUrl() : null;
|
|
||||||
$pagination['previous'] = $paginator->hasPreviousPage() ?
|
|
||||||
$paginator->getPreviousPage()->generateUrl() : null;
|
|
||||||
$pagination['more'] = $paginator->hasNextPage();
|
|
||||||
$data['pagination'] = $pagination;
|
|
||||||
|
|
||||||
// normalize results
|
|
||||||
$data['results'] = $this->normalizer->normalize($collection->getItems(),
|
|
||||||
$format, $context);
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,18 @@ class DateRangeCoveringTest extends TestCase
|
|||||||
$this->assertNotContains(3, $cover->getIntersections()[0][2]);
|
$this->assertNotContains(3, $cover->getIntersections()[0][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCoveringWithMinCover1_NoCoveringWithNullDates()
|
||||||
|
{
|
||||||
|
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
$cover
|
||||||
|
->add(new \DateTime('2021-10-05'), new \DateTime('2021-10-18'), 521)
|
||||||
|
->add(new \DateTime('2021-10-26'), null, 663)
|
||||||
|
->compute()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertFalse($cover->hasIntersections());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCoveringWithMinCover1WithTwoIntersections()
|
public function testCoveringWithMinCover1WithTwoIntersections()
|
||||||
{
|
{
|
||||||
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
$cover = new DateRangeCovering(1, new \DateTimeZone('Europe/Brussels'));
|
||||||
|
@ -291,11 +291,12 @@ class TimelineBuilder implements ContainerAwareInterface
|
|||||||
$entitiesByType[$result['type']][$result['id']], //the entity
|
$entitiesByType[$result['type']][$result['id']], //the entity
|
||||||
$context,
|
$context,
|
||||||
$args);
|
$args);
|
||||||
$timelineEntry['date'] = new \DateTime($result['date']);
|
|
||||||
$timelineEntry['template'] = $data['template'];
|
|
||||||
$timelineEntry['template_data'] = $data['template_data'];
|
|
||||||
|
|
||||||
$timelineEntries[] = $timelineEntry;
|
$timelineEntries[] = [
|
||||||
|
'date' => new \DateTime($result['date']),
|
||||||
|
'template' => $data['template'],
|
||||||
|
'template_data' => $data['template_data']
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->container->get('templating')
|
return $this->container->get('templating')
|
||||||
|
@ -5,15 +5,15 @@ namespace Chill\MainBundle\Util;
|
|||||||
/**
|
/**
|
||||||
* Utilities to compare date periods
|
* Utilities to compare date periods
|
||||||
*
|
*
|
||||||
* This class allow to compare periods when there are period covering. The
|
* This class allow to compare periods when there are period covering. The
|
||||||
* argument `minCovers` allow to find also when there are more than 2 period
|
* argument `minCovers` allow to find also when there are more than 2 period
|
||||||
* which intersects.
|
* which intersects.
|
||||||
*
|
*
|
||||||
* Example: a team may have maximum 2 leaders on a same period: you will
|
* Example: a team may have maximum 2 leaders on a same period: you will
|
||||||
* find here all periods where there are more than 2 leaders.
|
* find here all periods where there are more than 2 leaders.
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
*
|
*
|
||||||
* ```php
|
* ```php
|
||||||
* $cover = new DateRangeCovering(2); // 2 means we will have periods
|
* $cover = new DateRangeCovering(2); // 2 means we will have periods
|
||||||
* // when there are 2+ periods intersecting
|
* // when there are 2+ periods intersecting
|
||||||
@ -73,7 +73,7 @@ class DateRangeCovering
|
|||||||
$this->addToSequence($start->getTimestamp(), $k, null);
|
$this->addToSequence($start->getTimestamp(), $k, null);
|
||||||
$this->addToSequence(
|
$this->addToSequence(
|
||||||
NULL === $end ? PHP_INT_MAX : $end->getTimestamp(), null, $k
|
NULL === $end ? PHP_INT_MAX : $end->getTimestamp(), null, $k
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -140,72 +140,11 @@ class DateRangeCovering
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function process(array $intersections): array
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
$starts = [];
|
|
||||||
$ends = [];
|
|
||||||
$metadatas = [];
|
|
||||||
|
|
||||||
while (null !== ($current = \array_pop($intersections))) {
|
|
||||||
list($cStart, $cEnd, $cMetadata) = $current;
|
|
||||||
$n = count($cMetadata);
|
|
||||||
|
|
||||||
foreach ($intersections as list($iStart, $iEnd, $iMetadata)) {
|
|
||||||
$start = max($cStart, $iStart);
|
|
||||||
$end = min($cEnd, $iEnd);
|
|
||||||
|
|
||||||
if ($start <= $end) {
|
|
||||||
if (FALSE !== ($key = \array_search($start, $starts))) {
|
|
||||||
if ($ends[$key] === $end) {
|
|
||||||
$metadatas[$key] = \array_unique(\array_merge($metadatas[$key], $iMetadata));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$starts[] = $start;
|
|
||||||
$ends[] = $end;
|
|
||||||
$metadatas[] = \array_unique(\array_merge($iMetadata, $cMetadata));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// recompose results
|
|
||||||
foreach ($starts as $k => $start) {
|
|
||||||
$result[] = [$start, $ends[$k], \array_unique($metadatas[$k])];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addToIntersections(array $intersections, array $intersection)
|
|
||||||
{
|
|
||||||
$foundExisting = false;
|
|
||||||
list($nStart, $nEnd, $nMetadata) = $intersection;
|
|
||||||
|
|
||||||
\array_walk($intersections,
|
|
||||||
function(&$i, $key) use ($nStart, $nEnd, $nMetadata, $foundExisting) {
|
|
||||||
if ($foundExisting) {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if ($i[0] === $nStart && $i[1] === $nEnd) {
|
|
||||||
$foundExisting = true;
|
|
||||||
$i[2] = \array_merge($i[2], $nMetadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$foundExisting) {
|
|
||||||
$intersections[] = $intersection;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $intersections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasIntersections(): bool
|
public function hasIntersections(): bool
|
||||||
{
|
{
|
||||||
if (!$this->computed) {
|
if (!$this->computed) {
|
||||||
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
||||||
"'process'", __METHOD));
|
"'process'", __METHOD__));
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($this->intersections) > 0;
|
return count($this->intersections) > 0;
|
||||||
@ -215,7 +154,7 @@ class DateRangeCovering
|
|||||||
{
|
{
|
||||||
if (!$this->computed) {
|
if (!$this->computed) {
|
||||||
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
throw new \LogicException(sprintf("You cannot call the method %s before ".
|
||||||
"'process'", __METHOD));
|
"'process'", __METHOD__));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->intersections;
|
return $this->intersections;
|
||||||
|
@ -1,20 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
* Copyright (C) 2016-2019 Champs-Libres <info@champs-libres.coop>
|
declare(strict_types=1);
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace Chill\PersonBundle\CRUD\Controller;
|
namespace Chill\PersonBundle\CRUD\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||||
@ -23,11 +10,8 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use BadMethodCallException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Controller for entities attached as one-to-on to a person
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class OneToOneEntityPersonCRUDController extends CRUDController
|
class OneToOneEntityPersonCRUDController extends CRUDController
|
||||||
{
|
{
|
||||||
protected function getTemplateFor($action, $entity, Request $request)
|
protected function getTemplateFor($action, $entity, Request $request)
|
||||||
@ -35,11 +19,11 @@ class OneToOneEntityPersonCRUDController extends CRUDController
|
|||||||
if (!empty($this->crudConfig[$action]['template'])) {
|
if (!empty($this->crudConfig[$action]['template'])) {
|
||||||
return $this->crudConfig[$action]['template'];
|
return $this->crudConfig[$action]['template'];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'new':
|
case 'new':
|
||||||
return '@ChillPerson/CRUD/new.html.twig';
|
return '@ChillPerson/CRUD/new.html.twig';
|
||||||
case 'edit':
|
case 'edit':
|
||||||
return '@ChillPerson/CRUD/edit.html.twig';
|
return '@ChillPerson/CRUD/edit.html.twig';
|
||||||
case 'index':
|
case 'index':
|
||||||
return '@ChillPerson/CRUD/index.html.twig';
|
return '@ChillPerson/CRUD/index.html.twig';
|
||||||
@ -49,41 +33,41 @@ class OneToOneEntityPersonCRUDController extends CRUDController
|
|||||||
. "action");
|
. "action");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEntity($action, $id, Request $request): ?object
|
protected function getEntity($action, $id, Request $request): ?object
|
||||||
{
|
{
|
||||||
$entity = parent::getEntity($action, $id, $request);
|
$entity = parent::getEntity($action, $id, $request);
|
||||||
|
|
||||||
if (NULL === $entity) {
|
if (NULL === $entity) {
|
||||||
$entity = $this->createEntity($action, $request);
|
$entity = $this->createEntity($action, $request);
|
||||||
$person = $this->getDoctrine()
|
$person = $this->getDoctrine()
|
||||||
->getManager()
|
->getManager()
|
||||||
->getRepository(Person::class)
|
->getRepository(Person::class)
|
||||||
->find($id);
|
->find($id);
|
||||||
|
|
||||||
$entity->setPerson($person);
|
$entity->setPerson($person);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||||
{
|
{
|
||||||
$this->getDoctrine()->getManager()->persist($entity);
|
$this->getDoctrine()->getManager()->persist($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
|
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
|
||||||
{
|
{
|
||||||
if (FALSE === $this->getDoctrine()->getManager()->contains($entity)) {
|
if (FALSE === $this->getDoctrine()->getManager()->contains($entity)) {
|
||||||
return new RedirectResponse($this->generateRedirectOnCreateRoute($action, $request, $entity));
|
return new RedirectResponse($this->generateRedirectOnCreateRoute($action, $request, $entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateRedirectOnCreateRoute($action, Request $request, $entity)
|
protected function generateRedirectOnCreateRoute($action, Request $request, $entity)
|
||||||
{
|
{
|
||||||
throw new BadMethodCallException("not implemtented yet");
|
throw new BadMethodCallException('Not implemented yet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -959,6 +959,8 @@ EOF
|
|||||||
$table->setHeaders(array('#', 'label', 'value'));
|
$table->setHeaders(array('#', 'label', 'value'));
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
|
$matchingTableRowAnswer = [];
|
||||||
|
|
||||||
foreach($answers as $key => $answer) {
|
foreach($answers as $key => $answer) {
|
||||||
$table->addRow(array(
|
$table->addRow(array(
|
||||||
$i, $answer, $key
|
$i, $answer, $key
|
||||||
|
@ -54,10 +54,14 @@ class AccompanyingCourseApiController extends ApiController
|
|||||||
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
$accompanyingPeriod = $this->getEntity('participation', $id, $request);
|
||||||
|
|
||||||
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
|
$this->checkACL('confirm', $request, $_format, $accompanyingPeriod);
|
||||||
$workflow = $this->registry->get($accompanyingPeriod);
|
$workflow = $this->registry->get($accompanyingPeriod);
|
||||||
|
|
||||||
if (FALSE === $workflow->can($accompanyingPeriod, 'confirm')) {
|
if (FALSE === $workflow->can($accompanyingPeriod, 'confirm')) {
|
||||||
throw new BadRequestException('It is not possible to confirm this period');
|
// throw new BadRequestException('It is not possible to confirm this period');
|
||||||
|
$errors = $this->validator->validate($accompanyingPeriod, null, [$accompanyingPeriod::STEP_CONFIRMED]);
|
||||||
|
if( count($errors) > 0 ){
|
||||||
|
return $this->json($errors, 422);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$workflow->apply($accompanyingPeriod, 'confirm');
|
$workflow->apply($accompanyingPeriod, 'confirm');
|
||||||
@ -109,6 +113,13 @@ $workflow = $this->registry->get($accompanyingPeriod);
|
|||||||
|
|
||||||
public function resourceApi($id, Request $request, string $_format): Response
|
public function resourceApi($id, Request $request, string $_format): Response
|
||||||
{
|
{
|
||||||
|
$accompanyingPeriod = $this->getEntity('resource', $id, $request);
|
||||||
|
$errors = $this->validator->validate($accompanyingPeriod);
|
||||||
|
|
||||||
|
if ($errors->count() > 0) {
|
||||||
|
return $this->json($errors, 422);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->addRemoveSomething('resource', $id, $request, $_format, 'resource', Resource::class);
|
return $this->addRemoveSomething('resource', $id, $request, $_format, 'resource', Resource::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
|
use Symfony\Component\Form\Form;
|
||||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
|
|
||||||
class AccompanyingCourseWorkController extends AbstractController
|
class AccompanyingCourseWorkController extends AbstractController
|
||||||
{
|
{
|
||||||
@ -19,17 +22,20 @@ class AccompanyingCourseWorkController extends AbstractController
|
|||||||
private SerializerInterface $serializer;
|
private SerializerInterface $serializer;
|
||||||
private AccompanyingPeriodWorkRepository $workRepository;
|
private AccompanyingPeriodWorkRepository $workRepository;
|
||||||
private PaginatorFactory $paginator;
|
private PaginatorFactory $paginator;
|
||||||
|
protected LoggerInterface $logger;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TranslatorInterface $trans,
|
TranslatorInterface $trans,
|
||||||
SerializerInterface $serializer,
|
SerializerInterface $serializer,
|
||||||
AccompanyingPeriodWorkRepository $workRepository,
|
AccompanyingPeriodWorkRepository $workRepository,
|
||||||
PaginatorFactory $paginator
|
PaginatorFactory $paginator,
|
||||||
|
LoggerInterface $chillLogger
|
||||||
) {
|
) {
|
||||||
$this->trans = $trans;
|
$this->trans = $trans;
|
||||||
$this->serializer = $serializer;
|
$this->serializer = $serializer;
|
||||||
$this->workRepository = $workRepository;
|
$this->workRepository = $workRepository;
|
||||||
$this->paginator = $paginator;
|
$this->paginator = $paginator;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,4 +112,65 @@ class AccompanyingCourseWorkController extends AbstractController
|
|||||||
'paginator' => $paginator
|
'paginator' => $paginator
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/person/accompanying-period/work/{id}/delete",
|
||||||
|
* name="chill_person_accompanying_period_work_delete",
|
||||||
|
* methods={"GET", "POST", "DELETE"}
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function deleteWork(AccompanyingPeriodWork $work, Request $request): Response
|
||||||
|
{
|
||||||
|
// TODO ACL
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$form = $this->createDeleteForm($work->getId());
|
||||||
|
|
||||||
|
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isValid()) {
|
||||||
|
|
||||||
|
$this->logger->notice("An accompanying period work has been removed", [
|
||||||
|
'by_user' => $this->getUser()->getUsername(),
|
||||||
|
'work_id' => $work->getId(),
|
||||||
|
'accompanying_period_id' => $work->getAccompanyingPeriod()->getId()
|
||||||
|
]);
|
||||||
|
|
||||||
|
$em->remove($work);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->addFlash(
|
||||||
|
'success',
|
||||||
|
$this->trans->trans("The accompanying period work has been successfully removed.")
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('chill_person_accompanying_period_work_list', [
|
||||||
|
'id' => $work->getAccompanyingPeriod()->getId()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('@ChillPerson/AccompanyingCourseWork/delete.html.twig', [
|
||||||
|
'accompanyingCourse' => $work->getAccompanyingPeriod(),
|
||||||
|
'work' => $work,
|
||||||
|
'delete_form' => $form->createView()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createDeleteForm(int $id): Form
|
||||||
|
{
|
||||||
|
$params['id'] = $id;
|
||||||
|
|
||||||
|
return $this->createFormBuilder()
|
||||||
|
->setAction($this->generateUrl('chill_person_accompanying_period_work_delete', $params))
|
||||||
|
->setMethod('DELETE')
|
||||||
|
->add('submit', SubmitType::class, ['label' => 'Delete'])
|
||||||
|
->getForm()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class LoadAccompanyingPeriodOrigin extends AbstractFixture implements OrderedFix
|
|||||||
|
|
||||||
public function getOrder()
|
public function getOrder()
|
||||||
{
|
{
|
||||||
return 10005;
|
return 9000;
|
||||||
}
|
}
|
||||||
|
|
||||||
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
||||||
|
@ -161,8 +161,10 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
\shuffle($this->personIds);
|
\shuffle($this->personIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomPersons(int $min, int $max)
|
private function getRandomPersons(int $min, int $max): array
|
||||||
{
|
{
|
||||||
|
$persons = [];
|
||||||
|
|
||||||
$nb = \random_int($min, $max);
|
$nb = \random_int($min, $max);
|
||||||
|
|
||||||
for ($i=0; $i < $nb; $i++) {
|
for ($i=0; $i < $nb; $i++) {
|
||||||
@ -172,7 +174,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $persons ?? [];
|
return $persons;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDependencies()
|
public function getDependencies()
|
||||||
|
@ -247,7 +247,9 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
if (\random_int(0, 10) > 3) {
|
if (\random_int(0, 10) > 3) {
|
||||||
// always add social scope:
|
// always add social scope:
|
||||||
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
||||||
|
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN);
|
||||||
|
$accompanyingPeriod->setOrigin($origin);
|
||||||
|
$accompanyingPeriod->setIntensity('regular');
|
||||||
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
||||||
$manager->persist($accompanyingPeriod->getAddressLocation());
|
$manager->persist($accompanyingPeriod->getAddressLocation());
|
||||||
$workflow = $this->workflowRegistry->get($accompanyingPeriod);
|
$workflow = $this->workflowRegistry->get($accompanyingPeriod);
|
||||||
|
@ -45,6 +45,9 @@ use Chill\MainBundle\Entity\User;
|
|||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\Validator\GroupSequenceProviderInterface;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccompanyingPeriod Class
|
* AccompanyingPeriod Class
|
||||||
@ -54,9 +57,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||||
* "accompanying_period"=AccompanyingPeriod::class
|
* "accompanying_period"=AccompanyingPeriod::class
|
||||||
* })
|
* })
|
||||||
|
* @Assert\GroupSequenceProvider
|
||||||
*/
|
*/
|
||||||
class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface,
|
class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface,
|
||||||
HasScopesInterface, HasCentersInterface
|
HasScopesInterface, HasCentersInterface, GroupSequenceProviderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Mark an accompanying period as "occasional"
|
* Mark an accompanying period as "occasional"
|
||||||
@ -132,6 +136,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* cascade={"persist", "remove"},
|
* cascade={"persist", "remove"},
|
||||||
* orphanRemoval=true
|
* orphanRemoval=true
|
||||||
* )
|
* )
|
||||||
|
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_DRAFT})
|
||||||
*/
|
*/
|
||||||
private $comments;
|
private $comments;
|
||||||
|
|
||||||
@ -147,9 +152,10 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var Collection
|
* @var Collection
|
||||||
*
|
*
|
||||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
||||||
* mappedBy="accompanyingPeriod",
|
* mappedBy="accompanyingPeriod", orphanRemoval=true,
|
||||||
* cascade={"persist", "refresh", "remove", "merge", "detach"})
|
* cascade={"persist", "refresh", "remove", "merge", "detach"})
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
* @ParticipationOverlap(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED})
|
||||||
*/
|
*/
|
||||||
private $participations;
|
private $participations;
|
||||||
|
|
||||||
@ -188,6 +194,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @ORM\ManyToOne(targetEntity=Origin::class)
|
* @ORM\ManyToOne(targetEntity=Origin::class)
|
||||||
* @ORM\JoinColumn(nullable=true)
|
* @ORM\JoinColumn(nullable=true)
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write"})
|
||||||
|
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
|
||||||
*/
|
*/
|
||||||
private $origin;
|
private $origin;
|
||||||
|
|
||||||
@ -195,8 +202,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var string
|
* @var string
|
||||||
* @ORM\Column(type="string", nullable=true)
|
* @ORM\Column(type="string", nullable=true)
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write"})
|
||||||
|
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CONFIRMED})
|
||||||
*/
|
*/
|
||||||
private $intensity;
|
private $intensity = self::INTENSITY_OCCASIONAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
@ -210,6 +218,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
|
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
|
||||||
* )
|
* )
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED})
|
||||||
*/
|
*/
|
||||||
private $scopes;
|
private $scopes;
|
||||||
|
|
||||||
@ -256,6 +265,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* orphanRemoval=true
|
* orphanRemoval=true
|
||||||
* )
|
* )
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
* @ResourceDuplicateCheck(groups={AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED, "Default", "default"})
|
||||||
*/
|
*/
|
||||||
private $resources;
|
private $resources;
|
||||||
|
|
||||||
@ -267,6 +277,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* name="chill_person_accompanying_period_social_issues"
|
* name="chill_person_accompanying_period_social_issues"
|
||||||
* )
|
* )
|
||||||
* @Groups({"read"})
|
* @Groups({"read"})
|
||||||
|
* @Assert\Count(min=1, groups={AccompanyingPeriod::STEP_CONFIRMED})
|
||||||
*/
|
*/
|
||||||
private Collection $socialIssues;
|
private Collection $socialIssues;
|
||||||
|
|
||||||
@ -606,6 +617,14 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
return $participation;
|
return $participation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove Participation
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function removeParticipation(AccompanyingPeriodParticipation $participation)
|
||||||
|
{
|
||||||
|
$participation->setAccompanyingPeriod(null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove Person
|
* Remove Person
|
||||||
@ -1115,4 +1134,17 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
return $centers ?? null;
|
return $centers ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGroupSequence()
|
||||||
|
{
|
||||||
|
if($this->getStep() == self::STEP_DRAFT)
|
||||||
|
{
|
||||||
|
return [[self::STEP_DRAFT]];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getStep() == self::STEP_CONFIRMED)
|
||||||
|
{
|
||||||
|
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
* @ORM\OneToMany(
|
* @ORM\OneToMany(
|
||||||
* targetEntity=AccompanyingPeriodWorkEvaluation::class,
|
* targetEntity=AccompanyingPeriodWorkEvaluation::class,
|
||||||
* mappedBy="accompanyingPeriodWork",
|
* mappedBy="accompanyingPeriodWork",
|
||||||
* cascade={"persist"},
|
* cascade={"remove", "persist"},
|
||||||
* orphanRemoval=true
|
* orphanRemoval=true
|
||||||
* )
|
* )
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
@ -70,7 +70,8 @@ class AccompanyingPeriodWorkEvaluationDocument implements \Chill\MainBundle\Doct
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(
|
* @ORM\ManyToOne(
|
||||||
* targetEntity=StoredObject::class
|
* targetEntity=StoredObject::class,
|
||||||
|
* cascade={"remove"},
|
||||||
* )
|
* )
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +33,13 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="chill_person_accompanying_period_resource")
|
* @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={
|
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||||
* "accompanying_period_resource"=Resource::class
|
* "accompanying_period_resource"=Resource::class
|
||||||
* })
|
* })
|
||||||
|
@ -134,4 +134,11 @@ class AccompanyingPeriodParticipation
|
|||||||
{
|
{
|
||||||
return $this->endDate === null;
|
return $this->endDate === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkSameStartEnd()
|
||||||
|
{
|
||||||
|
if($this->endDate == $this->startDate) {
|
||||||
|
$this->accompanyingPeriod->removeParticipation($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,8 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
|
|||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data)
|
||||||
{
|
{
|
||||||
|
$labels = [];
|
||||||
|
|
||||||
if ($data['group_by_level'] === 'country') {
|
if ($data['group_by_level'] === 'country') {
|
||||||
$qb = $this->countriesRepository->createQueryBuilder('c');
|
$qb = $this->countriesRepository->createQueryBuilder('c');
|
||||||
|
|
||||||
@ -153,15 +155,17 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
|
|||||||
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
||||||
|
|
||||||
// initialize array and add blank key for null values
|
// initialize array and add blank key for null values
|
||||||
$labels[''] = $this->translator->trans('without data');
|
$labels = [
|
||||||
$labels['_header'] = $this->translator->trans('Country of birth');
|
'' => $this->translator->trans('without data'),
|
||||||
|
'_header' => $this->translator->trans('Country of birth'),
|
||||||
|
];
|
||||||
|
|
||||||
foreach($countries as $row) {
|
foreach($countries as $row) {
|
||||||
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
|
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data['group_by_level'] === 'continent') {
|
||||||
} elseif ($data['group_by_level'] === 'continent') {
|
|
||||||
|
|
||||||
$labels = array(
|
$labels = array(
|
||||||
'EU' => $this->translator->trans('Europe'),
|
'EU' => $this->translator->trans('Europe'),
|
||||||
'AS' => $this->translator->trans('Asia'),
|
'AS' => $this->translator->trans('Asia'),
|
||||||
@ -170,13 +174,12 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
|
|||||||
'SA' => $this->translator->trans('South America'),
|
'SA' => $this->translator->trans('South America'),
|
||||||
'NA' => $this->translator->trans('North America'),
|
'NA' => $this->translator->trans('North America'),
|
||||||
'OC' => $this->translator->trans('Oceania'),
|
'OC' => $this->translator->trans('Oceania'),
|
||||||
'' => $this->translator->trans('without data'),
|
'' => $this->translator->trans('without data'),
|
||||||
'_header' => $this->translator->trans('Continent of birth')
|
'_header' => $this->translator->trans('Continent of birth')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return function(string $value) use ($labels): string {
|
||||||
return function($value) use ($labels) {
|
|
||||||
return $labels[$value];
|
return $labels[$value];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data)
|
||||||
{
|
{
|
||||||
|
$labels = [];
|
||||||
|
|
||||||
if ($data['group_by_level'] === 'country') {
|
if ($data['group_by_level'] === 'country') {
|
||||||
$qb = $this->countriesRepository->createQueryBuilder('c');
|
$qb = $this->countriesRepository->createQueryBuilder('c');
|
||||||
|
|
||||||
@ -154,15 +156,17 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
||||||
|
|
||||||
// initialize array and add blank key for null values
|
// initialize array and add blank key for null values
|
||||||
$labels[''] = $this->translator->trans('without data');
|
$labels = [
|
||||||
$labels['_header'] = $this->translator->trans('Nationality');
|
'' => $this->translator->trans('without data'),
|
||||||
|
'_header' => $this->translator->trans('Nationality'),
|
||||||
|
];
|
||||||
|
|
||||||
foreach($countries as $row) {
|
foreach($countries as $row) {
|
||||||
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
|
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data['group_by_level'] === 'continent') {
|
||||||
} elseif ($data['group_by_level'] === 'continent') {
|
|
||||||
|
|
||||||
$labels = array(
|
$labels = array(
|
||||||
'EU' => $this->translator->trans('Europe'),
|
'EU' => $this->translator->trans('Europe'),
|
||||||
'AS' => $this->translator->trans('Asia'),
|
'AS' => $this->translator->trans('Asia'),
|
||||||
@ -176,8 +180,7 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return function(string $value) use ($labels): string {
|
||||||
return function($value) use ($labels) {
|
|
||||||
return $labels[$value];
|
return $labels[$value];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Repository\Household;
|
namespace Chill\PersonBundle\Repository\Household;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMembers;
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
@ -12,6 +14,6 @@ final class HouseholdMembersRepository
|
|||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
public function __construct(EntityManagerInterface $entityManager)
|
||||||
{
|
{
|
||||||
$this->repository = $entityManager->getRepository(HouseholdMembers::class);
|
$this->repository = $entityManager->getRepository(HouseholdMember::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
<comment v-if="accompanyingCourse.step === 'DRAFT'"></comment>
|
<comment v-if="accompanyingCourse.step === 'DRAFT'"></comment>
|
||||||
<confirm v-if="accompanyingCourse.step === 'DRAFT'"></confirm>
|
<confirm v-if="accompanyingCourse.step === 'DRAFT'"></confirm>
|
||||||
|
|
||||||
<div v-for="error in errorMsg" class="vue-component errors alert alert-danger">
|
<!-- <div v-for="error in errorMsg" v-bind:key="error.id" class="vue-component errors alert alert-danger">
|
||||||
<p>
|
<p>
|
||||||
<span>{{ error.sta }} {{ error.txt }}</span><br>
|
<span>{{ error.sta }} {{ error.txt }}</span><br>
|
||||||
<span>{{ $t(error.msg) }}</span>
|
<span>{{ $t(error.msg) }}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState } from 'vuex'
|
import { mapGetters, mapState } from 'vuex'
|
||||||
import Banner from './components/Banner.vue';
|
import Banner from './components/Banner.vue';
|
||||||
import StickyNav from './components/StickyNav.vue';
|
import StickyNav from './components/StickyNav.vue';
|
||||||
import OriginDemand from './components/OriginDemand.vue';
|
import OriginDemand from './components/OriginDemand.vue';
|
||||||
@ -55,11 +55,12 @@ export default {
|
|||||||
Comment,
|
Comment,
|
||||||
Confirm,
|
Confirm,
|
||||||
},
|
},
|
||||||
computed: mapState([
|
computed: {
|
||||||
'accompanyingCourse',
|
...mapState([
|
||||||
'addressContext',
|
'accompanyingCourse',
|
||||||
'errorMsg'
|
'addressContext'
|
||||||
])
|
]),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -86,7 +86,8 @@ const postParticipation = (id, payload, method) => {
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
throw { msg: 'Error while sending AccompanyingPeriod Course participation.', sta: response.status, txt: response.statusText, err: new Error(), body: response.body };
|
// TODO: adjust message according to status code? Or how to access the message from the violation array?
|
||||||
|
throw { msg: 'Error while sending AccompanyingPeriod Course participation', sta: response.status, txt: response.statusText, err: new Error(), body: response.body };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
<VueMultiselect
|
<VueMultiselect
|
||||||
name="selectOrigin"
|
name="selectOrigin"
|
||||||
label="text"
|
label="text"
|
||||||
v-bind:custom-label="transText"
|
:custom-label="transText"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
v-bind:multiple="false"
|
:multiple="false"
|
||||||
v-bind:searchable="true"
|
:searchable="true"
|
||||||
v-bind:placeholder="$t('origin.placeholder')"
|
:placeholder="$t('origin.placeholder')"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
v-bind:options="options"
|
:options="options"
|
||||||
@select="updateOrigin">
|
@select="updateOrigin">
|
||||||
</VueMultiselect>
|
</VueMultiselect>
|
||||||
|
|
||||||
@ -47,18 +47,18 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getOptions() {
|
getOptions() {
|
||||||
//console.log('loading origins list');
|
|
||||||
getListOrigins().then(response => new Promise((resolve, reject) => {
|
getListOrigins().then(response => new Promise((resolve, reject) => {
|
||||||
this.options = response.results;
|
this.options = response.results;
|
||||||
resolve();
|
resolve();
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
updateOrigin(value) {
|
updateOrigin(value) {
|
||||||
//console.log('value', value);
|
console.log('value', value);
|
||||||
this.$store.dispatch('updateOrigin', value);
|
this.$store.dispatch('updateOrigin', value);
|
||||||
},
|
},
|
||||||
transText ({ text }) {
|
transText ({ text }) {
|
||||||
return text.fr //TODO multilang
|
const parsedText = JSON.parse(text);
|
||||||
|
return parsedText.fr;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import { createApp } from 'vue'
|
|||||||
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
||||||
import { appMessages } from './js/i18n'
|
import { appMessages } from './js/i18n'
|
||||||
import { initPromise } from './store'
|
import { initPromise } from './store'
|
||||||
|
import VueToast from 'vue-toast-notification';
|
||||||
|
import 'vue-toast-notification/dist/theme-sugar.css';
|
||||||
|
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import Banner from './components/Banner.vue';
|
import Banner from './components/Banner.vue';
|
||||||
@ -21,6 +23,7 @@ if (root === 'app') {
|
|||||||
})
|
})
|
||||||
.use(store)
|
.use(store)
|
||||||
.use(i18n)
|
.use(i18n)
|
||||||
|
.use(VueToast)
|
||||||
.component('app', App)
|
.component('app', App)
|
||||||
.mount('#accompanying-course');
|
.mount('#accompanying-course');
|
||||||
});
|
});
|
||||||
|
@ -77,7 +77,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
|
|||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
catchError(state, error) {
|
catchError(state, error) {
|
||||||
console.log('### mutation: a new error have been catched and pushed in store !', error);
|
// console.log('### mutation: a new error have been catched and pushed in store !', error);
|
||||||
state.errorMsg.push(error);
|
state.errorMsg.push(error);
|
||||||
},
|
},
|
||||||
removeParticipation(state, participation) {
|
removeParticipation(state, participation) {
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="isLoadingSocialActions">
|
<div v-if="isLoadingSocialActions">
|
||||||
<p>spinner</p>
|
<i class="fa fa-circle-o-notch fa-spin fa-fw"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="hasSocialActionPicked" id="persons">
|
<div v-if="hasSocialActionPicked" id="persons">
|
||||||
@ -72,7 +72,7 @@
|
|||||||
{{ $t('action.save') }}
|
{{ $t('action.save') }}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-save" v-show="isPostingWork" disabled>
|
<button class="btn btn-save" v-show="isPostingWork" disabled>
|
||||||
{{ $t('Save') }}
|
{{ $t('action.save') }}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -20,18 +20,25 @@
|
|||||||
v-bind:item="item">
|
v-bind:item="item">
|
||||||
</suggestion-third-party>
|
</suggestion-third-party>
|
||||||
|
|
||||||
|
<suggestion-user
|
||||||
|
v-if="item.result.type === 'user'"
|
||||||
|
v-bind:item="item">
|
||||||
|
</suggestion-user>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import SuggestionPerson from './TypePerson';
|
import SuggestionPerson from './TypePerson';
|
||||||
import SuggestionThirdParty from './TypeThirdParty';
|
import SuggestionThirdParty from './TypeThirdParty';
|
||||||
|
import SuggestionUser from './TypeUser';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PersonSuggestion',
|
name: 'PersonSuggestion',
|
||||||
components: {
|
components: {
|
||||||
SuggestionPerson,
|
SuggestionPerson,
|
||||||
SuggestionThirdParty,
|
SuggestionThirdParty,
|
||||||
|
SuggestionUser,
|
||||||
},
|
},
|
||||||
props: [
|
props: [
|
||||||
'item',
|
'item',
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
<template>
|
||||||
|
<div class="container usercontainer">
|
||||||
|
<div class="user-identification">
|
||||||
|
<span class="name">
|
||||||
|
{{ item.result.text }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="right_actions">
|
||||||
|
<span class="badge rounded-pill bg-secondary">
|
||||||
|
{{ $t('user')}}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
const i18n = {
|
||||||
|
messages: {
|
||||||
|
fr: {
|
||||||
|
user: 'Utilisateur' // TODO how to define other translations?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'SuggestionUser',
|
||||||
|
props: ['item'],
|
||||||
|
i18n,
|
||||||
|
computed: {
|
||||||
|
hasParent() {
|
||||||
|
return this.$props.item.result.parent !== null;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.usercontainer {
|
||||||
|
.userparent {
|
||||||
|
.name {
|
||||||
|
font-weight: bold;
|
||||||
|
font-variant: all-small-caps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,34 @@
|
|||||||
|
{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %}
|
||||||
|
|
||||||
|
{% set activeRouteKey = 'chill_person_accompanying_period_work_list' %}
|
||||||
|
|
||||||
|
{% block title 'accompanying_course_work.remove'|trans %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="accompanying_course_work-list">
|
||||||
|
<h2 class="badge-title">
|
||||||
|
<span class="title_label">{{ 'accompanying_course_work.action'|trans }}</span>
|
||||||
|
<span class="title_action">{{ work.socialAction|chill_entity_render_string }}</span>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>{{ "Associated peoples"|trans }}</h3>
|
||||||
|
<ul>
|
||||||
|
{% for p in work.persons %}
|
||||||
|
{{ p|chill_entity_render_box }}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{{ include('@ChillMain/Util/confirmation_template.html.twig',
|
||||||
|
{
|
||||||
|
'title' : 'accompanying_course_work.remove'|trans,
|
||||||
|
'confirm_question' : 'Are you sure you want to remove this work of the accompanying period %name% ?'|trans({ '%name%' : accompanyingCourse.id } ),
|
||||||
|
'cancel_route' : 'chill_person_accompanying_period_work_list',
|
||||||
|
'cancel_parameters' : {'id' : accompanyingCourse.id},
|
||||||
|
'form' : delete_form
|
||||||
|
} ) }}
|
||||||
|
{% endblock %}
|
@ -103,6 +103,11 @@
|
|||||||
href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', { 'id': w.id }) }}"
|
href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', { 'id': w.id }) }}"
|
||||||
>{% if buttonText is not defined or buttonText == true %}{{ 'Edit'|trans }}{% endif %}</a>
|
>{% if buttonText is not defined or buttonText == true %}{{ 'Edit'|trans }}{% endif %}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a class="btn btn-delete" title="{{ 'Delete'|trans }}"
|
||||||
|
href="{{ path('chill_person_accompanying_period_work_delete', { 'id': w.id } ) }}"
|
||||||
|
>{% if buttonText is not defined or buttonText == true %}{{ 'Delete'|trans }}{% endif %}</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- if options['addId'] -%}
|
{%- if options['addId'] -%}
|
||||||
<span class="id-number" title="{{ 'Person'|trans ~ ' n° ' ~ person.id }}">
|
<span class="id-number" title="{{ 'Person'|trans ~ ' n° ' ~ person.id }}">
|
||||||
{{ person.id|upper }}
|
{{ person.id|upper -}}
|
||||||
</span>
|
</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</div>
|
</div>
|
||||||
@ -95,7 +95,7 @@
|
|||||||
</time>
|
</time>
|
||||||
{%- if options['addAge'] -%}
|
{%- if options['addAge'] -%}
|
||||||
<span class="age">
|
<span class="age">
|
||||||
({{ 'years_old'|trans({ 'age': person.age }) }})
|
{{- 'years_old'|trans({ 'age': person.age }) -}}
|
||||||
</span>
|
</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
@ -263,8 +263,9 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
|||||||
|
|
||||||
public function convertTermsToFormData(array $terms)
|
public function convertTermsToFormData(array $terms)
|
||||||
{
|
{
|
||||||
foreach(['firstname', 'lastname', 'gender', '_default']
|
$data = [];
|
||||||
as $key) {
|
|
||||||
|
foreach(['firstname', 'lastname', 'gender', '_default'] as $key) {
|
||||||
$data[$key] = $terms[$key] ?? null;
|
$data[$key] = $terms[$key] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class SocialActionRender implements ChillEntityRenderInterface
|
|||||||
{
|
{
|
||||||
/** @var $socialAction SocialAction */
|
/** @var $socialAction SocialAction */
|
||||||
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
$options = \array_merge(self::DEFAULT_ARGS, $options);
|
||||||
$titles[] = $this->translatableStringHelper->localize($socialAction->getTitle());
|
$titles = [$this->translatableStringHelper->localize($socialAction->getTitle())];
|
||||||
|
|
||||||
while ($socialAction->hasParent()) {
|
while ($socialAction->hasParent()) {
|
||||||
$socialAction = $socialAction->getParent();
|
$socialAction = $socialAction->getParent();
|
||||||
|
@ -38,8 +38,7 @@ final class SocialIssueRender implements ChillEntityRenderInterface
|
|||||||
/** @var $socialIssue SocialIssue */
|
/** @var $socialIssue SocialIssue */
|
||||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||||
|
|
||||||
$titles[] = $this->translatableStringHelper
|
$titles = [$this->translatableStringHelper->localize($socialIssue->getTitle())];
|
||||||
->localize($socialIssue->getTitle());
|
|
||||||
|
|
||||||
// loop to parent, until root
|
// loop to parent, until root
|
||||||
while ($socialIssue->hasParent()) {
|
while ($socialIssue->hasParent()) {
|
||||||
|
@ -11,7 +11,7 @@ class LocationValidity extends Constraint
|
|||||||
{
|
{
|
||||||
public $messagePersonLocatedMustBeAssociated = "The person where the course is located must be associated to the course. Change course's location before removing the person.";
|
public $messagePersonLocatedMustBeAssociated = "The person where the course is located must be associated to the course. Change course's location before removing the person.";
|
||||||
|
|
||||||
public $messagePeriodMustRemainsLocated = "The period must remains located";
|
public $messagePeriodMustRemainsLocated = "The period must remain located";
|
||||||
|
|
||||||
public function getTargets()
|
public function getTargets()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
*/
|
||||||
|
class ParticipationOverlap extends Constraint
|
||||||
|
{
|
||||||
|
public $message = 'This participation already exists.';
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Util\DateRangeCovering;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ParticipationOverlap;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
|
class ParticipationOverlapValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
private const MAX_PARTICIPATION = 1;
|
||||||
|
|
||||||
|
public function validate($participations, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof ParticipationOverlap) {
|
||||||
|
throw new UnexpectedTypeException($constraint, ParticipationOverlap::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$participations instanceof Collection) {
|
||||||
|
throw new UnexpectedTypeException($participations, 'This should be a collection');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($participations) <= self::MAX_PARTICIPATION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$overlaps = new DateRangeCovering(self::MAX_PARTICIPATION, $participations[0]->getStartDate()->getTimezone());
|
||||||
|
|
||||||
|
foreach ($participations as $participation) {
|
||||||
|
|
||||||
|
if (!$participation instanceof AccompanyingPeriodParticipation) {
|
||||||
|
throw new UnexpectedTypeException($participation, AccompanyingPeriodParticipation::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$personId = $participation->getPerson()->getId();
|
||||||
|
|
||||||
|
$particpationList[$personId][] = $participation;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($particpationList as $group) {
|
||||||
|
if (count($group) > 1) {
|
||||||
|
foreach ($group as $p) {
|
||||||
|
$overlaps->add($p->getStartDate(), $p->getEndDate(), $p->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$overlaps->compute();
|
||||||
|
|
||||||
|
if ($overlaps->hasIntersections()) {
|
||||||
|
foreach ($overlaps->getIntersections() as list($start, $end, $ids)) {
|
||||||
|
$msg = $end === null ? $constraint->message :
|
||||||
|
$constraint->message;
|
||||||
|
|
||||||
|
$this->context->buildViolation($msg)
|
||||||
|
->setParameters([
|
||||||
|
'{{ start }}' => $start->format('d-m-Y'),
|
||||||
|
'{{ end }}' => $end === null ? null : $end->format('d-m-Y'),
|
||||||
|
'{{ ids }}' => $ids,
|
||||||
|
])
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
*/
|
||||||
|
class ResourceDuplicateCheck extends Constraint
|
||||||
|
{
|
||||||
|
public $message = '{{ name }} is already associated to this accompanying course.';
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicateCheck;
|
||||||
|
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
|
||||||
|
|
||||||
|
class ResourceDuplicateCheckValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
|
||||||
|
private PersonRender $personRender;
|
||||||
|
private ThirdPartyRender $thirdpartyRender;
|
||||||
|
|
||||||
|
public function __construct(PersonRender $personRender, ThirdPartyRender $thirdPartyRender)
|
||||||
|
{
|
||||||
|
$this->personRender = $personRender;
|
||||||
|
$this->thirdpartyRender = $thirdPartyRender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate($resources, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof ResourceDuplicateCheck) {
|
||||||
|
throw new UnexpectedTypeException($constraint, ParticipationOverlap::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$resources instanceof Collection) {
|
||||||
|
throw new UnexpectedTypeException($resources, Collection::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resourceList = [];
|
||||||
|
|
||||||
|
foreach ($resources as $resource) {
|
||||||
|
$id = ($resource->getResource() instanceof Person ? 'p' :
|
||||||
|
't').$resource->getResource()->getId();
|
||||||
|
|
||||||
|
if (\in_array($id, $resourceList, true)) {
|
||||||
|
$this->context->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ name }}', $resource->getResource() instanceof Person ? $this->personRender->renderString($resource->getResource(), []) :
|
||||||
|
$this->thirdpartyRender->renderString($resource->getResource(), []))
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
|
||||||
|
$resourceList[] = $id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
services:
|
||||||
|
Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
tags: ['validator.service_arguments']
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Person;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validation added to accompanying period resources and accompanying period.
|
||||||
|
*/
|
||||||
|
final class Version20211020131133 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Validation added to accompanying period resources and accompanying period.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX person_unique ON chill_person_accompanying_period_resource (person_id, accompanyingperiod_id) WHERE person_id IS NOT NULL');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX thirdparty_unique ON chill_person_accompanying_period_resource (thirdparty_id, accompanyingperiod_id) WHERE thirdparty_id IS NOT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP INDEX person_unique');
|
||||||
|
$this->addSql('DROP INDEX thirdparty_unique');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\Person;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom constraint added to database to prevent identical participations.
|
||||||
|
*/
|
||||||
|
final class Version20211021125359 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Custom constraint added to database to prevent identical participations.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// creates a constraint 'participations may not overlap'
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT '.
|
||||||
|
"participations_no_overlap EXCLUDE USING GIST(
|
||||||
|
-- extension btree_gist required to include comparaison with integer
|
||||||
|
person_id WITH =, accompanyingperiod_id WITH =,
|
||||||
|
daterange(startdate, enddate) WITH &&
|
||||||
|
)
|
||||||
|
INITIALLY DEFERRED");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX participation_unique ON chill_person_accompanying_period_participation (accompanyingperiod_id, person_id)');
|
||||||
|
}
|
||||||
|
}
|
@ -405,6 +405,8 @@ Back to household: Revenir au ménage
|
|||||||
# accompanying course work
|
# accompanying course work
|
||||||
Accompanying Course Actions: Actions d'accompagnements
|
Accompanying Course Actions: Actions d'accompagnements
|
||||||
Accompanying Course Action: Action d'accompagnement
|
Accompanying Course Action: Action d'accompagnement
|
||||||
|
Are you sure you want to remove this work of the accompanying period %name% ?: Êtes-vous sûr de vouloir supprimer cette action de la période d'accompagnement %name% ?
|
||||||
|
The accompanying period work has been successfully removed.: L'action d'accompagnement a été supprimée.
|
||||||
accompanying_course_work:
|
accompanying_course_work:
|
||||||
create: Créer une action
|
create: Créer une action
|
||||||
Create accompanying course work: Créer une action d'accompagnement
|
Create accompanying course work: Créer une action d'accompagnement
|
||||||
@ -419,6 +421,7 @@ accompanying_course_work:
|
|||||||
results: Résultats - orientations
|
results: Résultats - orientations
|
||||||
goal: Objectif - motif - dispositif
|
goal: Objectif - motif - dispositif
|
||||||
Any work: Aucune action d'accompagnement
|
Any work: Aucune action d'accompagnement
|
||||||
|
remove: Supprimer une action d'accompagnement
|
||||||
|
|
||||||
#
|
#
|
||||||
Person addresses: Adresses de résidence
|
Person addresses: Adresses de résidence
|
||||||
|
@ -41,3 +41,6 @@ household:
|
|||||||
household_membership:
|
household_membership:
|
||||||
The end date must be after start date: La date de la fin de l'appartenance doit être postérieure à la date de début.
|
The end date must be after start date: La date de la fin de l'appartenance doit être postérieure à la date de début.
|
||||||
Person with membership covering: Une personne ne peut pas appartenir à deux ménages simultanément. Or, avec cette modification, %person_name% appartiendrait à %nbHousehold% ménages à partir du %from%.
|
Person with membership covering: Une personne ne peut pas appartenir à deux ménages simultanément. Or, avec cette modification, %person_name% appartiendrait à %nbHousehold% ménages à partir du %from%.
|
||||||
|
|
||||||
|
# Accompanying period
|
||||||
|
'{{ name }} is already associated to this accompanying course.': '{{ name }} est déjà associé avec ce parcours.'
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
namespace Chill\ReportBundle\Export\Export;
|
namespace Chill\ReportBundle\Export\Export;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ use Chill\MainBundle\Entity\User;
|
|||||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
@ -38,27 +38,27 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
* @var CustomFieldsGroup
|
* @var CustomFieldsGroup
|
||||||
*/
|
*/
|
||||||
protected $customfieldsGroup;
|
protected $customfieldsGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TranslatableStringHelper
|
* @var TranslatableStringHelper
|
||||||
*/
|
*/
|
||||||
protected $translatableStringHelper;
|
protected $translatableStringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var TranslatorInterface
|
* @var TranslatorInterface
|
||||||
*/
|
*/
|
||||||
protected $translator;
|
protected $translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var CustomFieldProvider
|
* @var CustomFieldProvider
|
||||||
*/
|
*/
|
||||||
protected $customFieldProvider;
|
protected $customFieldProvider;
|
||||||
|
|
||||||
protected $em;
|
protected $em;
|
||||||
|
|
||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
'person_id', 'person_firstName', 'person_lastName', 'person_birthdate',
|
'person_id', 'person_firstName', 'person_lastName', 'person_birthdate',
|
||||||
'person_placeOfBirth', 'person_gender', 'person_memo', 'person_email', 'person_phonenumber',
|
'person_placeOfBirth', 'person_gender', 'person_memo', 'person_email', 'person_phonenumber',
|
||||||
@ -67,11 +67,11 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
'person_address_postcode_code', 'person_address_country_name', 'person_address_country_code',
|
'person_address_postcode_code', 'person_address_country_name', 'person_address_country_code',
|
||||||
'report_id', 'report_user', 'report_date', 'report_scope'
|
'report_id', 'report_user', 'report_date', 'report_scope'
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $slugs = [];
|
protected $slugs = [];
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
CustomFieldsGroup $customfieldsGroup,
|
CustomFieldsGroup $customfieldsGroup,
|
||||||
TranslatableStringHelper $translatableStringHelper,
|
TranslatableStringHelper $translatableStringHelper,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
CustomFieldProvider $customFieldProvider,
|
CustomFieldProvider $customFieldProvider,
|
||||||
@ -84,18 +84,18 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
|
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$choices = array_combine($this->fields, $this->fields);
|
$choices = array_combine($this->fields, $this->fields);
|
||||||
|
|
||||||
foreach ($this->getCustomFields() as $cf) {
|
foreach ($this->getCustomFields() as $cf) {
|
||||||
$choices
|
$choices
|
||||||
[$this->translatableStringHelper->localize($cf->getName())]
|
[$this->translatableStringHelper->localize($cf->getName())]
|
||||||
=
|
=
|
||||||
$cf->getSlug();
|
$cf->getSlug();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a checkbox to select fields
|
// Add a checkbox to select fields
|
||||||
$builder->add('fields', ChoiceType::class, array(
|
$builder->add('fields', ChoiceType::class, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
@ -133,7 +133,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
}
|
}
|
||||||
))]
|
))]
|
||||||
));
|
));
|
||||||
|
|
||||||
// add a date field for addresses
|
// add a date field for addresses
|
||||||
$builder->add('address_date', ChillDateType::class, array(
|
$builder->add('address_date', ChillDateType::class, array(
|
||||||
'label' => "Address valid at this date",
|
'label' => "Address valid at this date",
|
||||||
@ -142,14 +142,14 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
'block_name' => 'list_export_form_address_date'
|
'block_name' => 'list_export_form_address_date'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateForm($data, ExecutionContextInterface $context)
|
public function validateForm($data, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
// get the field starting with address_
|
// get the field starting with address_
|
||||||
$addressFields = array_filter(function($el) {
|
$addressFields = array_filter(function($el) {
|
||||||
return substr($el, 0, 8) === 'address_';
|
return substr($el, 0, 8) === 'address_';
|
||||||
}, $this->fields);
|
}, $this->fields);
|
||||||
|
|
||||||
// check if there is one field starting with address in data
|
// check if there is one field starting with address in data
|
||||||
if (count(array_intersect($data['fields'], $addressFields)) > 0) {
|
if (count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||||
// if a field address is checked, the date must not be empty
|
// if a field address is checked, the date must not be empty
|
||||||
@ -161,10 +161,10 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get custom fields associated with person
|
* Get custom fields associated with person
|
||||||
*
|
*
|
||||||
* @return CustomField[]
|
* @return CustomField[]
|
||||||
*/
|
*/
|
||||||
private function getCustomFields()
|
private function getCustomFields()
|
||||||
@ -184,7 +184,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
{
|
{
|
||||||
return $this->translator->trans(
|
return $this->translator->trans(
|
||||||
"Generate list of report '%type%'",
|
"Generate list of report '%type%'",
|
||||||
[
|
[
|
||||||
'%type%' => $this->translatableStringHelper->localize($this->customfieldsGroup->getName())
|
'%type%' => $this->translatableStringHelper->localize($this->customfieldsGroup->getName())
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -192,13 +192,12 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param type $key
|
* @param type $key
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* @param type $data
|
* @param type $data
|
||||||
* @return type
|
|
||||||
*/
|
*/
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data): \Closure
|
||||||
{
|
{
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'person_birthdate':
|
case 'person_birthdate':
|
||||||
@ -206,27 +205,27 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
// for birthdate or report date, we have to transform the string into a date
|
// for birthdate or report date, we have to transform the string into a date
|
||||||
// to format the date correctly.
|
// to format the date correctly.
|
||||||
return function($value) use ($key) {
|
return function($value) use ($key) {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return $key === 'person_birthdate' ? 'birthdate' : 'report_date';
|
return $key === 'person_birthdate' ? 'birthdate' : 'report_date';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($value))
|
if (empty($value))
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($key === 'person_birthdate') {
|
if ($key === 'person_birthdate') {
|
||||||
$date = \DateTime::createFromFormat('Y-m-d', $value);
|
$date = \DateTime::createFromFormat('Y-m-d', $value);
|
||||||
} else {
|
} else {
|
||||||
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
||||||
}
|
}
|
||||||
// check that the creation could occurs.
|
// check that the creation could occurs.
|
||||||
if ($date === false) {
|
if ($date === false) {
|
||||||
throw new \Exception(sprintf("The value %s could "
|
throw new \Exception(sprintf("The value %s could "
|
||||||
. "not be converted to %s", $value, \DateTime::class));
|
. "not be converted to %s", $value, \DateTime::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $date->format('d-m-Y');
|
return $date->format('d-m-Y');
|
||||||
};
|
};
|
||||||
case 'report_scope':
|
case 'report_scope':
|
||||||
$qb = $this->em->getRepository(Scope::class)
|
$qb = $this->em->getRepository(Scope::class)
|
||||||
@ -236,17 +235,18 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
->where($qb->expr()->in('s.id', $values))
|
->where($qb->expr()->in('s.id', $values))
|
||||||
;
|
;
|
||||||
$rows = $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
|
$rows = $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
|
||||||
|
|
||||||
|
$scopes = [];
|
||||||
|
|
||||||
foreach($rows as $row) {
|
foreach($rows as $row) {
|
||||||
$scopes[$row['id']] = $this->translatableStringHelper
|
$scopes[$row['id']] = $this->translatableStringHelper->localize($row['name']);
|
||||||
->localize($row['name']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return function($value) use ($scopes) {
|
return function($value) use ($scopes): string {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return 'circle';
|
return 'circle';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $scopes[$value];
|
return $scopes[$value];
|
||||||
};
|
};
|
||||||
case 'report_user':
|
case 'report_user':
|
||||||
@ -257,71 +257,73 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
->where($qb->expr()->in('u.id', $values))
|
->where($qb->expr()->in('u.id', $values))
|
||||||
;
|
;
|
||||||
$rows = $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
|
$rows = $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
|
||||||
|
|
||||||
|
$users = [];
|
||||||
|
|
||||||
foreach($rows as $row) {
|
foreach($rows as $row) {
|
||||||
$users[$row['id']] = $row['username'];
|
$users[$row['id']] = $row['username'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return function($value) use ($users) {
|
return function($value) use ($users): string {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return 'user';
|
return 'user';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $users[$value];
|
return $users[$value];
|
||||||
};
|
};
|
||||||
case 'person_gender' :
|
case 'person_gender' :
|
||||||
// for gender, we have to translate men/women statement
|
// for gender, we have to translate men/women statement
|
||||||
return function($value) {
|
return function($value) {
|
||||||
if ($value === '_header') { return 'gender'; }
|
if ($value === '_header') { return 'gender'; }
|
||||||
|
|
||||||
return $this->translator->trans($value);
|
return $this->translator->trans($value);
|
||||||
};
|
};
|
||||||
case 'person_countryOfBirth':
|
case 'person_countryOfBirth':
|
||||||
case 'person_nationality':
|
case 'person_nationality':
|
||||||
$countryRepository = $this->em
|
$countryRepository = $this->em
|
||||||
->getRepository('ChillMainBundle:Country');
|
->getRepository('ChillMainBundle:Country');
|
||||||
|
|
||||||
// load all countries in a single query
|
// load all countries in a single query
|
||||||
$countryRepository->findBy(array('countryCode' => $values));
|
$countryRepository->findBy(array('countryCode' => $values));
|
||||||
|
|
||||||
return function($value) use ($key, $countryRepository) {
|
return function($value) use ($key, $countryRepository) {
|
||||||
if ($value === '_header') { return \strtolower($key); }
|
if ($value === '_header') { return \strtolower($key); }
|
||||||
|
|
||||||
if ($value === NULL) {
|
if ($value === NULL) {
|
||||||
return $this->translator->trans('no data');
|
return $this->translator->trans('no data');
|
||||||
}
|
}
|
||||||
|
|
||||||
$country = $countryRepository->find($value);
|
$country = $countryRepository->find($value);
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize(
|
return $this->translatableStringHelper->localize(
|
||||||
$country->getName());
|
$country->getName());
|
||||||
};
|
};
|
||||||
case 'person_address_country_name':
|
case 'person_address_country_name':
|
||||||
return function($value) use ($key) {
|
return function($value) use ($key) {
|
||||||
if ($value === '_header') { return \strtolower($key); }
|
if ($value === '_header') { return \strtolower($key); }
|
||||||
|
|
||||||
if ($value === NULL) {
|
if ($value === NULL) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize(json_decode($value, true));
|
return $this->translatableStringHelper->localize(json_decode($value, true));
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
// for fields which are associated with person
|
// for fields which are associated with person
|
||||||
if (in_array($key, $this->fields)) {
|
if (in_array($key, $this->fields)) {
|
||||||
return function($value) use ($key) {
|
return function($value) use ($key) {
|
||||||
if ($value === '_header') { return \strtolower($key); }
|
if ($value === '_header') { return \strtolower($key); }
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return $this->getLabelForCustomField($key, $values, $data);
|
return $this->getLabelForCustomField($key, $values, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLabelForCustomField($key, array $values, $data)
|
private function getLabelForCustomField($key, array $values, $data)
|
||||||
{
|
{
|
||||||
// for fields which are custom fields
|
// for fields which are custom fields
|
||||||
@ -329,38 +331,38 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
$cf = $this->em
|
$cf = $this->em
|
||||||
->getRepository(CustomField::class)
|
->getRepository(CustomField::class)
|
||||||
->findOneBy(array('slug' => $this->DQLToSlug($key)));
|
->findOneBy(array('slug' => $this->DQLToSlug($key)));
|
||||||
|
|
||||||
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
|
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
|
||||||
$defaultFunction = function($value) use ($cf) {
|
$defaultFunction = function($value) use ($cf) {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return $this->translatableStringHelper->localize($cf->getName());
|
return $this->translatableStringHelper->localize($cf->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->customFieldProvider
|
return $this->customFieldProvider
|
||||||
->getCustomFieldByType($cf->getType())
|
->getCustomFieldByType($cf->getType())
|
||||||
->render(json_decode($value, true), $cf, 'csv');
|
->render(json_decode($value, true), $cf, 'csv');
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
|
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
|
||||||
return function($value) use ($cf, $cfType, $key) {
|
return function($value) use ($cf, $cfType, $key) {
|
||||||
$slugChoice = $this->extractInfosFromSlug($key)['additionnalInfos']['choiceSlug'];
|
$slugChoice = $this->extractInfosFromSlug($key)['additionnalInfos']['choiceSlug'];
|
||||||
$decoded = \json_decode($value, true);
|
$decoded = \json_decode($value, true);
|
||||||
|
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
|
|
||||||
$label = $cfType->getChoices($cf)[$slugChoice];
|
$label = $cfType->getChoices($cf)[$slugChoice];
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize($cf->getName())
|
return $this->translatableStringHelper->localize($cf->getName())
|
||||||
.' | '.$label;
|
.' | '.$label;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($slugChoice === '_other' and $cfType->isChecked($cf, $choiceSlug, $decoded)) {
|
if ($slugChoice === '_other' and $cfType->isChecked($cf, $choiceSlug, $decoded)) {
|
||||||
return $cfType->extractOtherValue($cf, $decoded);
|
return $cfType->extractOtherValue($cf, $decoded);
|
||||||
} else {
|
} else {
|
||||||
return $cfType->isChecked($cf, $slugChoice, $decoded);
|
return $cfType->isChecked($cf, $slugChoice, $decoded);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return $defaultFunction;
|
return $defaultFunction;
|
||||||
}
|
}
|
||||||
@ -369,44 +371,44 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
public function getQueryKeys($data)
|
public function getQueryKeys($data)
|
||||||
{
|
{
|
||||||
$fields = array();
|
$fields = array();
|
||||||
|
|
||||||
foreach ($data['fields'] as $key) {
|
foreach ($data['fields'] as $key) {
|
||||||
if (in_array($key, $this->fields)) {
|
if (in_array($key, $this->fields)) {
|
||||||
$fields[] = $key;
|
$fields[] = $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the key from slugs and return
|
// add the key from slugs and return
|
||||||
return \array_merge($fields, \array_keys($this->slugs));
|
return \array_merge($fields, \array_keys($this->slugs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean a slug to be usable by DQL
|
* clean a slug to be usable by DQL
|
||||||
*
|
*
|
||||||
* @param string $slugsanitize
|
* @param string $slugsanitize
|
||||||
* @param string $type the type of the customfield, if required (currently only for choices)
|
* @param string $type the type of the customfield, if required (currently only for choices)
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function slugToDQL($slug, $type = "default", array $additionalInfos = [])
|
private function slugToDQL($slug, $type = "default", array $additionalInfos = [])
|
||||||
{
|
{
|
||||||
$uid = 'slug_'.\uniqid();
|
$uid = 'slug_'.\uniqid();
|
||||||
|
|
||||||
$this->slugs[$uid] = [
|
$this->slugs[$uid] = [
|
||||||
'slug' => $slug,
|
'slug' => $slug,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'additionnalInfos' => $additionalInfos
|
'additionnalInfos' => $additionalInfos
|
||||||
];
|
];
|
||||||
|
|
||||||
return $uid;
|
return $uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function DQLToSlug($cleanedSlug)
|
private function DQLToSlug($cleanedSlug)
|
||||||
{
|
{
|
||||||
return $this->slugs[$cleanedSlug]['slug'];
|
return $this->slugs[$cleanedSlug]['slug'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $cleanedSlug
|
* @param type $cleanedSlug
|
||||||
* @return an array with keys = 'slug', 'type', 'additionnalInfo'
|
* @return an array with keys = 'slug', 'type', 'additionnalInfo'
|
||||||
*/
|
*/
|
||||||
@ -424,7 +426,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
{
|
{
|
||||||
return $this->translator->trans(
|
return $this->translator->trans(
|
||||||
"List for report '%type%'",
|
"List for report '%type%'",
|
||||||
[
|
[
|
||||||
'%type%' => $this->translatableStringHelper->localize($this->customfieldsGroup->getName())
|
'%type%' => $this->translatableStringHelper->localize($this->customfieldsGroup->getName())
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -438,22 +440,22 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = array())
|
||||||
{
|
{
|
||||||
$centers = array_map(function($el) { return $el['center']; }, $acl);
|
$centers = array_map(function($el) { return $el['center']; }, $acl);
|
||||||
|
|
||||||
// throw an error if any fields are present
|
// throw an error if any fields are present
|
||||||
if (!\array_key_exists('fields', $data)) {
|
if (!\array_key_exists('fields', $data)) {
|
||||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields "
|
throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields "
|
||||||
. "have been checked");
|
. "have been checked");
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb = $this->em->createQueryBuilder();
|
$qb = $this->em->createQueryBuilder();
|
||||||
|
|
||||||
// process fields which are not custom fields
|
// process fields which are not custom fields
|
||||||
foreach ($this->fields as $f) {
|
foreach ($this->fields as $f) {
|
||||||
// do not add fields which are not selected
|
// do not add fields which are not selected
|
||||||
if (!\in_array($f, $data['fields'])) {
|
if (!\in_array($f, $data['fields'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a column to the query for each field
|
// add a column to the query for each field
|
||||||
switch ($f) {
|
switch ($f) {
|
||||||
case 'person_countryOfBirth':
|
case 'person_countryOfBirth':
|
||||||
@ -470,11 +472,11 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
case 'person_address_country_code':
|
case 'person_address_country_code':
|
||||||
// remove 'person_'
|
// remove 'person_'
|
||||||
$suffix = \substr($f, 7);
|
$suffix = \substr($f, 7);
|
||||||
|
|
||||||
$qb->addSelect(sprintf(
|
$qb->addSelect(sprintf(
|
||||||
'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s',
|
'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s',
|
||||||
// get the part after address_
|
// get the part after address_
|
||||||
strtoupper(substr($suffix, 8)),
|
strtoupper(substr($suffix, 8)),
|
||||||
$f));
|
$f));
|
||||||
$qb->setParameter('address_date', $data['address_date']);
|
$qb->setParameter('address_date', $data['address_date']);
|
||||||
break;
|
break;
|
||||||
@ -487,7 +489,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
default:
|
default:
|
||||||
$prefix = \substr($f, 0, 7);
|
$prefix = \substr($f, 0, 7);
|
||||||
$suffix = \substr($f, 7);
|
$suffix = \substr($f, 7);
|
||||||
|
|
||||||
switch($prefix) {
|
switch($prefix) {
|
||||||
case 'person_':
|
case 'person_':
|
||||||
$qb->addSelect(sprintf('person.%s as %s', $suffix, $f));
|
$qb->addSelect(sprintf('person.%s as %s', $suffix, $f));
|
||||||
@ -502,22 +504,22 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process fields which are custom fields
|
// process fields which are custom fields
|
||||||
foreach ($this->getCustomFields() as $cf) {
|
foreach ($this->getCustomFields() as $cf) {
|
||||||
// do not add custom fields which are not selected
|
// do not add custom fields which are not selected
|
||||||
if (!\in_array($cf->getSlug(), $data['fields'])) {
|
if (!\in_array($cf->getSlug(), $data['fields'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
|
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
|
||||||
|
|
||||||
// if is multiple, split into multiple columns
|
// if is multiple, split into multiple columns
|
||||||
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
|
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
|
||||||
foreach($cfType->getChoices($cf) as $choiceSlug => $label) {
|
foreach($cfType->getChoices($cf) as $choiceSlug => $label) {
|
||||||
$slug = $this->slugToDQL($cf->getSlug(), 'choice', [ 'choiceSlug' => $choiceSlug ]);
|
$slug = $this->slugToDQL($cf->getSlug(), 'choice', [ 'choiceSlug' => $choiceSlug ]);
|
||||||
$qb->addSelect(
|
$qb->addSelect(
|
||||||
sprintf('GET_JSON_FIELD_BY_KEY(report.cFData, :slug%s) AS %s',
|
sprintf('GET_JSON_FIELD_BY_KEY(report.cFData, :slug%s) AS %s',
|
||||||
$slug, $slug));
|
$slug, $slug));
|
||||||
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
|
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
|
||||||
}
|
}
|
||||||
@ -525,12 +527,12 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
// not multiple, add a single column
|
// not multiple, add a single column
|
||||||
$slug = $this->slugToDQL($cf->getSlug());
|
$slug = $this->slugToDQL($cf->getSlug());
|
||||||
$qb->addSelect(
|
$qb->addSelect(
|
||||||
sprintf('GET_JSON_FIELD_BY_KEY(report.cFData, :slug%s) AS %s',
|
sprintf('GET_JSON_FIELD_BY_KEY(report.cFData, :slug%s) AS %s',
|
||||||
$slug, $slug));
|
$slug, $slug));
|
||||||
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
|
$qb->setParameter(sprintf('slug%s', $slug), $cf->getSlug());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
->from(Report::class, 'report')
|
->from(Report::class, 'report')
|
||||||
->leftJoin('report.person', 'person')
|
->leftJoin('report.person', 'person')
|
||||||
@ -540,7 +542,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
|
|||||||
->andWhere('center IN (:authorized_centers)')
|
->andWhere('center IN (:authorized_centers)')
|
||||||
->setParameter('authorized_centers', $centers);
|
->setParameter('authorized_centers', $centers);
|
||||||
;
|
;
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,18 +38,18 @@ use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
|||||||
class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||||
{
|
{
|
||||||
protected EntityManagerInterface $em;
|
protected EntityManagerInterface $em;
|
||||||
|
|
||||||
protected Registry $registry;
|
protected Registry $registry;
|
||||||
|
|
||||||
protected AuthorizationHelper $authorizationHelper;
|
protected AuthorizationHelper $authorizationHelper;
|
||||||
|
|
||||||
protected Security $security;
|
protected Security $security;
|
||||||
|
|
||||||
|
|
||||||
const TYPE = 'chill_task.transition';
|
const TYPE = 'chill_task.transition';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EntityManagerInterface $em,
|
EntityManagerInterface $em,
|
||||||
Registry $registry,
|
Registry $registry,
|
||||||
AuthorizationHelper $authorizationHelper,
|
AuthorizationHelper $authorizationHelper,
|
||||||
Security $security
|
Security $security
|
||||||
@ -64,7 +64,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
{
|
{
|
||||||
$metadata = $this->em
|
$metadata = $this->em
|
||||||
->getClassMetadata(SingleTaskPlaceEvent::class);
|
->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
|
|
||||||
switch ($context) {
|
switch ($context) {
|
||||||
case 'person':
|
case 'person':
|
||||||
[ $where, $parameters ] = $this->getWhereClauseForPerson($args['person']);
|
[ $where, $parameters ] = $this->getWhereClauseForPerson($args['person']);
|
||||||
@ -157,7 +157,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
|
|
||||||
|
|
||||||
// the parameters
|
// the parameters
|
||||||
$parameters = [];
|
$parameters = $circleIds = [];
|
||||||
|
|
||||||
// the clause that we will fill
|
// the clause that we will fill
|
||||||
$clause = "{person}.{person_id} = ? AND {task}.{circle} IN ({circle_ids})";
|
$clause = "{person}.{person_id} = ? AND {task}.{circle} IN ({circle_ids})";
|
||||||
@ -212,27 +212,27 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
'{single_task}' => sprintf('%s.%s', $singleTask->getSchemaName(), $singleTask->getTableName()),
|
'{single_task}' => sprintf('%s.%s', $singleTask->getSchemaName(), $singleTask->getTableName()),
|
||||||
'{single_task_event}' => sprintf('%s.%s', $taskEvent->getSchemaName(), $taskEvent->getTableName()),
|
'{single_task_event}' => sprintf('%s.%s', $taskEvent->getSchemaName(), $taskEvent->getTableName()),
|
||||||
'{task_pk}' => $singleTask->getColumnName('id'),
|
'{task_pk}' => $singleTask->getColumnName('id'),
|
||||||
'{event_fk_task}' => $eventFkTask,
|
'{event_fk_task}' => $eventFkTask,
|
||||||
'{person}' => $person->getTableName(),
|
'{person}' => $person->getTableName(),
|
||||||
'{task_person_fk}' => $taskFkPerson,
|
'{task_person_fk}' => $taskFkPerson,
|
||||||
'{person_pk}' => $personPk
|
'{person_pk}' => $personPk
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEntities(array $ids)
|
public function getEntities(array $ids)
|
||||||
{
|
{
|
||||||
$events = $this->em
|
$events = $this->em
|
||||||
->getRepository(SingleTaskPlaceEvent::class)
|
->getRepository(SingleTaskPlaceEvent::class)
|
||||||
->findBy([ 'id' => $ids ])
|
->findBy([ 'id' => $ids ])
|
||||||
;
|
;
|
||||||
|
|
||||||
return \array_combine(
|
return \array_combine(
|
||||||
\array_map(function($e) { return $e->getId(); }, $events ),
|
\array_map(function($e) { return $e->getId(); }, $events ),
|
||||||
$events
|
$events
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEntityTemplate($entity, $context, array $args)
|
public function getEntityTemplate($entity, $context, array $args)
|
||||||
{
|
{
|
||||||
$workflow = $this->registry->get($entity->getTask(),
|
$workflow = $this->registry->get($entity->getTask(),
|
||||||
@ -242,22 +242,22 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
// `Notice: Undefined property: Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent::$getData`
|
// `Notice: Undefined property: Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent::$getData`
|
||||||
// * fix syntax error on $entity->getData['workflow']
|
// * fix syntax error on $entity->getData['workflow']
|
||||||
// * return null if not set
|
// * return null if not set
|
||||||
|
|
||||||
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'template' => 'ChillTaskBundle:Timeline:single_task_transition.html.twig',
|
'template' => 'ChillTaskBundle:Timeline:single_task_transition.html.twig',
|
||||||
'template_data' => [
|
'template_data' => [
|
||||||
'context' => $context,
|
'context' => $context,
|
||||||
'event' => $entity,
|
'event' => $entity,
|
||||||
'task' => $entity->getTask(),
|
'task' => $entity->getTask(),
|
||||||
'transition' => $transition
|
'transition' => $transition
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param Workflow $workflow
|
* @param Workflow $workflow
|
||||||
* @return \Symfony\Component\Workflow\Transition
|
* @return \Symfony\Component\Workflow\Transition
|
||||||
@ -270,7 +270,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsType($type): bool
|
public function supportsType($type): bool
|
||||||
{
|
{
|
||||||
return $type === self::TYPE;
|
return $type === self::TYPE;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\ThirdPartyBundle\Serializer\Normalizer;
|
namespace Chill\ThirdPartyBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
@ -20,23 +22,24 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
|
|||||||
$this->thirdPartyRender = $thirdPartyRender;
|
$this->thirdPartyRender = $thirdPartyRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ThirdParty $thirdParty
|
||||||
|
*/
|
||||||
public function normalize($thirdParty, string $format = null, array $context = [])
|
public function normalize($thirdParty, string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
/** @var $thirdParty ThirdParty */
|
return [
|
||||||
$data['type'] = 'thirdparty';
|
'type' => 'thirdparty',
|
||||||
$data['text'] = $this->thirdPartyRender->renderString($thirdParty, []);
|
'text' => $this->thirdPartyRender->renderString($thirdParty, []),
|
||||||
$data['id'] = $thirdParty->getId();
|
'id' => $thirdParty->getId(),
|
||||||
$data['kind'] = $thirdParty->getKind();
|
'kind' => $thirdParty->getKind(),
|
||||||
$data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format,
|
'address' => $this->normalizer->normalize($thirdParty->getAddress(), $format, [ 'address_rendering' => 'short' ]),
|
||||||
[ 'address_rendering' => 'short' ]);
|
'phonenumber' => $thirdParty->getTelephone(),
|
||||||
$data['phonenumber'] = $thirdParty->getTelephone();
|
'email' => $thirdParty->getEmail(),
|
||||||
$data['email'] = $thirdParty->getEmail();
|
'isChild' => $thirdParty->isChild(),
|
||||||
$data['isChild'] = $thirdParty->isChild();
|
'parent' => $this->normalizer->normalize($thirdParty->getParent(), $format, $context),
|
||||||
$data['parent'] = $this->normalizer->normalize($thirdParty->getParent(), $format, $context);
|
'civility' => $this->normalizer->normalize($thirdParty->getCivility(), $format, $context),
|
||||||
$data['civility'] = $this->normalizer->normalize($thirdParty->getCivility(), $format, $context);
|
'contactDataAnonymous' => $thirdParty->isContactDataAnonymous(),
|
||||||
$data['contactDataAnonymous'] = $thirdParty->isContactDataAnonymous();
|
];
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, string $format = null)
|
public function supportsNormalization($data, string $format = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user