mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-30 18:39:43 +00:00
Compare commits
1 Commits
fix/person
...
issue186_A
Author | SHA1 | Date | |
---|---|---|---|
471a373117 |
26
CHANGELOG.md
26
CHANGELOG.md
@@ -12,26 +12,12 @@ and this project adheres to
|
|||||||
|
|
||||||
<!-- write down unreleased development here -->
|
<!-- write down unreleased development here -->
|
||||||
|
|
||||||
* [main] fix adding multiple AddresseDeRelais (combine PickAddressType with ChillCollection)
|
|
||||||
* [person]: do not suggest the current household of the person (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/51)
|
|
||||||
* [person]: display other phone numbers in view + add message in case no others phone numbers (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/184)
|
|
||||||
* 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.
|
|
||||||
* [household]: improve relationship graph
|
|
||||||
* add form to create/edit/delete relationship link,
|
|
||||||
* improve graph refresh mechanism
|
|
||||||
* add feature to export canvas as image (png)
|
|
||||||
* [person suggest] In widget "add person", improve the pertinence of persons when one of the names starts with the pattern;
|
|
||||||
* [person] do not ask for center any more on person creation
|
|
||||||
* [3party] do not ask for center any more on 3party creation
|
|
||||||
|
|
||||||
|
|
||||||
## 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
|
||||||
@@ -56,9 +42,10 @@ and this project adheres to
|
|||||||
* [tasks]: different layout for task list / my tasks, and fix link to tasks in alert or in warning
|
* [tasks]: different layout for task list / my tasks, and fix link to tasks in alert or in warning
|
||||||
* [admin]: links to activity admin section added again.
|
* [admin]: links to activity admin section added again.
|
||||||
* [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
|
||||||
|
|
||||||
|
|
||||||
### Test release 2021-10-27
|
### Test release 2021-10-27
|
||||||
|
|
||||||
* [person]: delete double actions buttons on search person page
|
* [person]: delete double actions buttons on search person page
|
||||||
@@ -76,10 +63,7 @@ and this project adheres to
|
|||||||
* [3party]: fix address creation
|
* [3party]: fix address creation
|
||||||
* [household members editor] finalisation of editor
|
* [household members editor] finalisation of editor
|
||||||
* [AccompanyingCourse banner]: replace translation referrer (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/70)
|
* [AccompanyingCourse banner]: replace translation referrer (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/70)
|
||||||
* [Location]: add location system in activity and RV (calendar). User can choose in location list or create a new location.
|
* [Location]: add location system in activity and RV (calendar). User can choose in location list or create a new location.
|
||||||
* [household]: add relationship page with dynamic data visualisation graph
|
|
||||||
|
|
||||||
## Test releases
|
|
||||||
|
|
||||||
### Test release 2021-10-11
|
### Test release 2021-10-11
|
||||||
|
|
||||||
@@ -146,7 +130,7 @@ and this project adheres to
|
|||||||
|
|
||||||
## Test released
|
## Test released
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Coming soon...
|
Coming soon...
|
||||||
|
|
||||||
@@ -159,4 +143,4 @@ DO NOT ADD unreleased items here. Add them under "Unreleased" title
|
|||||||
## Stable releases
|
## Stable releases
|
||||||
|
|
||||||
No stable releases for v2+
|
No stable releases for v2+
|
||||||
|
|
||||||
|
@@ -54,9 +54,6 @@
|
|||||||
"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",
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,21 +0,0 @@
|
|||||||
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
|
|
||||||
|
|
@@ -22,10 +22,8 @@
|
|||||||
|
|
||||||
namespace Chill\ActivityBundle\DataFixtures\ORM;
|
namespace Chill\ActivityBundle\DataFixtures\ORM;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Faker\Factory as FakerFactory;
|
use Faker\Factory as FakerFactory;
|
||||||
use Chill\ActivityBundle\Entity\Activity;
|
use Chill\ActivityBundle\Entity\Activity;
|
||||||
@@ -33,19 +31,25 @@ use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
|||||||
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityReason;
|
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityReason;
|
||||||
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityType;
|
use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityType;
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
|
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
|
||||||
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
/**
|
||||||
|
* Load reports into DB
|
||||||
|
*
|
||||||
|
* @author Champs-Libres Coop
|
||||||
|
*/
|
||||||
|
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
||||||
{
|
{
|
||||||
|
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Faker\Generator
|
* @var \Faker\Generator
|
||||||
*/
|
*/
|
||||||
private $faker;
|
private $faker;
|
||||||
private EntityManagerInterface $em;
|
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
$this->faker = FakerFactory::create('fr_FR');
|
||||||
$this->em = $em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder()
|
public function getOrder()
|
||||||
@@ -84,7 +88,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
{
|
{
|
||||||
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
||||||
|
|
||||||
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds, true)) {
|
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) {
|
||||||
// we have a reason which should be excluded. Find another...
|
// we have a reason which should be excluded. Find another...
|
||||||
return $this->getRandomActivityReason($excludingIds);
|
return $this->getRandomActivityReason($excludingIds);
|
||||||
}
|
}
|
||||||
@@ -128,17 +132,20 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$persons = $this->em
|
$persons = $this->container->get('doctrine.orm.entity_manager')
|
||||||
->getRepository(Person::class)
|
->getRepository('ChillPersonBundle:Person')
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
foreach ($persons as $person) {
|
foreach($persons as $person) {
|
||||||
$activityNbr = rand(0,3);
|
$activityNbr = rand(0,3);
|
||||||
|
$ref = 'activity_'.$person->getFullnameCanonical();
|
||||||
|
|
||||||
for ($i = 0; $i < $activityNbr; $i ++) {
|
for($i = 0; $i < $activityNbr; $i ++) {
|
||||||
$activity = $this->newRandomActivity($person);
|
$activity = $this->newRandomActivity($person);
|
||||||
$manager->persist($activity);
|
$manager->persist($activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setReference($ref, $activity);
|
||||||
}
|
}
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
@@ -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): \Closure
|
public function getLabels($key, array $values, $data)
|
||||||
{
|
{
|
||||||
// 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): string {
|
return function($value) use ($data) {
|
||||||
if ($value === '_header') {
|
if ($value === '_header') {
|
||||||
return 'Activity type';
|
return 'Activity type';
|
||||||
}
|
}
|
||||||
@@ -120,11 +120,12 @@ class ActivityTypeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
return $this->stringHelper->localize($t->getName());
|
return $this->stringHelper->localize($t->getName());
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryKeys($data): array
|
public function getQueryKeys($data)
|
||||||
{
|
{
|
||||||
return [self::KEY];
|
return array(self::KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
},
|
},
|
||||||
{ 'title': 'Users concerned'|trans,
|
{ 'title': 'Users concerned'|trans,
|
||||||
'items': entity.users,
|
'items': entity.users,
|
||||||
|
'path' : 'admin_user_show',
|
||||||
'key' : 'id'
|
'key' : 'id'
|
||||||
},
|
},
|
||||||
] %}
|
] %}
|
||||||
@@ -57,7 +58,6 @@
|
|||||||
<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,14 +66,6 @@
|
|||||||
}) }}
|
}) }}
|
||||||
</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>
|
||||||
@@ -93,7 +85,6 @@
|
|||||||
<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({
|
||||||
@@ -102,12 +93,6 @@
|
|||||||
}) }}
|
}) }}
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
|
||||||
{{ item|chill_entity_render_box({
|
|
||||||
'render': 'raw',
|
|
||||||
'addAltNames': false
|
|
||||||
}) }}
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -129,19 +114,12 @@
|
|||||||
{% 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_period_id' : accompanyingCourse.id, 'id' : activity.id },
|
'cancel_parameters' : { 'accompanying_course_id' : accompanyingCourse.id, 'id' : activity.id },
|
||||||
'form' : delete_form
|
'form' : delete_form
|
||||||
} ) }}
|
} ) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
Chill\ActivityBundle\DataFixtures\ORM\:
|
Chill\ActivityBundle\DataFixtures\ORM\:
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
resource: ../../DataFixtures/ORM
|
resource: ../../DataFixtures/ORM
|
||||||
tags: [ 'doctrine.fixture.orm' ]
|
tags: [ 'doctrine.fixture.orm' ]
|
||||||
|
@@ -19,6 +19,8 @@ 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
|
||||||
{
|
{
|
||||||
@@ -109,4 +111,4 @@ final class ChillAsideActivityExtension extends Extension implements PrependExte
|
|||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -30,9 +30,7 @@ final class CategoryRender implements ChillEntityRenderInterface
|
|||||||
{
|
{
|
||||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||||
|
|
||||||
$titles = [
|
$titles[] = $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
|
||||||
$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
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
if ($accompanyingPeriod instanceof AccompanyingPeriod) {
|
} elseif ($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,8 +117,6 @@ class CalendarController extends AbstractController
|
|||||||
'paginator' => $paginator
|
'paginator' => $paginator
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('Unable to list actions.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -5,20 +5,21 @@ namespace Chill\CalendarBundle\DataFixtures\ORM;
|
|||||||
use Chill\CalendarBundle\Entity\CalendarRange;
|
use Chill\CalendarBundle\Entity\CalendarRange;
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
|
||||||
class LoadCalendarRange extends Fixture implements FixtureGroupInterface, OrderedFixtureInterface
|
class LoadCalendarRange extends Fixture implements FixtureGroupInterface, OrderedFixtureInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
UserRepository $userRepository
|
EntityManagerInterface $em
|
||||||
) {
|
) {
|
||||||
$this->userRepository = $userRepository;
|
$this->userRepository = $em->getRepository(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder(): int
|
public function getOrder(): int
|
||||||
@@ -36,7 +37,7 @@ class LoadCalendarRange extends Fixture implements FixtureGroupInterface, Ordere
|
|||||||
public function load(ObjectManager $manager): void
|
public function load(ObjectManager $manager): void
|
||||||
{
|
{
|
||||||
$arr = range(-50, 50);
|
$arr = range(-50, 50);
|
||||||
|
|
||||||
print "Creating calendar range ('plage de disponibilités')\n";
|
print "Creating calendar range ('plage de disponibilités')\n";
|
||||||
|
|
||||||
$users = $this->userRepository->findAll();
|
$users = $this->userRepository->findAll();
|
||||||
@@ -69,7 +70,7 @@ class LoadCalendarRange extends Fixture implements FixtureGroupInterface, Ordere
|
|||||||
->setUser($u)
|
->setUser($u)
|
||||||
->setStartDate($startEvent)
|
->setStartDate($startEvent)
|
||||||
->setEndDate($endEvent);
|
->setEndDate($endEvent);
|
||||||
|
|
||||||
$manager->persist($calendarRange);
|
$manager->persist($calendarRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +79,4 @@ class LoadCalendarRange extends Fixture implements FixtureGroupInterface, Ordere
|
|||||||
}
|
}
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -28,31 +28,27 @@ 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 = [
|
$twigConfig['form_themes'][] = 'ChillCustomFieldsBundle:Form:fields.html.twig';
|
||||||
'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,7 +145,5 @@ class DocGeneratorTemplateController extends AbstractController
|
|||||||
} catch (TransferException $e) {
|
} catch (TransferException $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('Unable to generate document.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
return 35000;
|
return 35000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
|
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
|
||||||
@@ -57,15 +57,15 @@ class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
break;
|
break;
|
||||||
case 'administrative':
|
case 'administrative':
|
||||||
case 'direction':
|
case 'direction':
|
||||||
if (in_array($scope->getName()['en'], array('administrative', 'social'), true)) {
|
if (in_array($scope->getName()['en'], array('administrative', 'social'))) {
|
||||||
printf("denying power on %s\n", $scope->getName()['en']);
|
printf("denying power on %s\n", $scope->getName()['en']);
|
||||||
break 2; // we do not want any power on social or administrative
|
break 2; // we do not want any power on social or administrative
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Adding Person report acl to %s "
|
printf("Adding Person report acl to %s "
|
||||||
. "permission group, scope '%s' \n",
|
. "permission group, scope '%s' \n",
|
||||||
$permissionsGroup->getName(), $scope->getName()['en']);
|
$permissionsGroup->getName(), $scope->getName()['en']);
|
||||||
$roleScopeUpdate = (new RoleScope())
|
$roleScopeUpdate = (new RoleScope())
|
||||||
->setRole(PersonDocumentVoter::CREATE)
|
->setRole(PersonDocumentVoter::CREATE)
|
||||||
@@ -83,9 +83,9 @@ class LoadDocumentACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
$manager->persist($roleScopeCreate);
|
$manager->persist($roleScopeCreate);
|
||||||
$manager->persist($roleScopeDelete);
|
$manager->persist($roleScopeDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
namespace Chill\DocStoreBundle\Repository;
|
||||||
|
|
||||||
namespace Chill\DocStoreBundle\EntityRepository;
|
use App\Entity\AccompanyingCourseDocument;
|
||||||
|
|
||||||
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 ([] === $newParticipations) {
|
if (!isset($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,29 +222,24 @@ 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(
|
return $this->render('ChillEventBundle:Participation:new-multiple.html.twig', array(
|
||||||
'ChillEventBundle:Participation:new-multiple.html.twig',
|
|
||||||
[
|
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participations' => $newParticipations,
|
'participations' => $newParticipations,
|
||||||
'ignored_participations' => $ignoredParticipations
|
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
||||||
]
|
));
|
||||||
);
|
} 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
|
|
||||||
$form = $this->createCreateForm($participation);
|
return $this->render('ChillEventBundle:Participation:new.html.twig', array(
|
||||||
|
|
||||||
return $this->render(
|
|
||||||
'ChillEventBundle:Participation:new.html.twig',
|
|
||||||
[
|
|
||||||
'form' => $form->createView(),
|
'form' => $form->createView(),
|
||||||
'participation' => $participation,
|
'participation' => $participation,
|
||||||
'ignored_participations' => $ignoredParticipations,
|
'ignored_participations' => isset($ignoredParticipations) ? $ignoredParticipations : array()
|
||||||
]
|
));
|
||||||
);
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||||
@@ -256,32 +251,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
|
||||||
@@ -289,41 +284,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
|
||||||
@@ -331,56 +326,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)
|
||||||
{
|
{
|
||||||
@@ -389,37 +384,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);
|
||||||
@@ -433,13 +428,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
|
||||||
@@ -447,7 +442,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(
|
||||||
@@ -456,14 +451,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
|
||||||
@@ -475,7 +470,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))
|
||||||
)
|
)
|
||||||
)));
|
)));
|
||||||
@@ -486,90 +481,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
|
||||||
*/
|
*/
|
||||||
@@ -581,14 +576,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.
|
||||||
*
|
*
|
||||||
@@ -599,84 +594,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
|
||||||
@@ -684,14 +679,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(
|
||||||
@@ -699,14 +694,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
|
||||||
@@ -718,28 +713,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()
|
||||||
]);
|
]);
|
||||||
@@ -749,9 +744,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
|
||||||
@@ -767,5 +762,5 @@ class ParticipationController extends AbstractController
|
|||||||
->getForm()
|
->getForm()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -50,19 +50,19 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
break;
|
break;
|
||||||
case 'administrative':
|
case 'administrative':
|
||||||
case 'direction':
|
case 'direction':
|
||||||
if (in_array($scope->getName()['en'], array('administrative', 'social'), true)) {
|
if (in_array($scope->getName()['en'], array('administrative', 'social'))) {
|
||||||
break 2; // we do not want any power on social or administrative
|
break 2; // we do not want any power on social or administrative
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Adding CHILL_EVENT_UPDATE & CHILL_EVENT_CREATE "
|
printf("Adding CHILL_EVENT_UPDATE & CHILL_EVENT_CREATE "
|
||||||
. "& CHILL_EVENT_PARTICIPATION_UPDATE & CHILL_EVENT_PARTICIPATION_CREATE "
|
. "& CHILL_EVENT_PARTICIPATION_UPDATE & CHILL_EVENT_PARTICIPATION_CREATE "
|
||||||
. "& CHILL_EVENT_SEE & CHILL_EVENT_SEE_DETAILS "
|
. "& CHILL_EVENT_SEE & CHILL_EVENT_SEE_DETAILS "
|
||||||
. "to %s "
|
. "to %s "
|
||||||
. "permission group, scope '%s' \n",
|
. "permission group, scope '%s' \n",
|
||||||
$permissionsGroup->getName(), $scope->getName()['en']);
|
$permissionsGroup->getName(), $scope->getName()['en']);
|
||||||
|
|
||||||
$roleScopeUpdate = (new RoleScope())
|
$roleScopeUpdate = (new RoleScope())
|
||||||
->setRole('CHILL_EVENT_UPDATE')
|
->setRole('CHILL_EVENT_UPDATE')
|
||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
@@ -71,7 +71,7 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
$permissionsGroup->addRoleScope($roleScopeUpdate);
|
$permissionsGroup->addRoleScope($roleScopeUpdate);
|
||||||
$permissionsGroup->addRoleScope($roleScopeUpdate2);
|
$permissionsGroup->addRoleScope($roleScopeUpdate2);
|
||||||
|
|
||||||
$roleScopeCreate = (new RoleScope())
|
$roleScopeCreate = (new RoleScope())
|
||||||
->setRole('CHILL_EVENT_CREATE')
|
->setRole('CHILL_EVENT_CREATE')
|
||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
@@ -80,7 +80,7 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
$permissionsGroup->addRoleScope($roleScopeCreate);
|
$permissionsGroup->addRoleScope($roleScopeCreate);
|
||||||
$permissionsGroup->addRoleScope($roleScopeCreate2);
|
$permissionsGroup->addRoleScope($roleScopeCreate2);
|
||||||
|
|
||||||
$roleScopeSee = (new RoleScope())
|
$roleScopeSee = (new RoleScope())
|
||||||
->setRole('CHILL_EVENT_SEE')
|
->setRole('CHILL_EVENT_SEE')
|
||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
@@ -89,7 +89,7 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
->setScope($scope);
|
->setScope($scope);
|
||||||
$permissionsGroup->addRoleScope($roleScopeSee);
|
$permissionsGroup->addRoleScope($roleScopeSee);
|
||||||
$permissionsGroup->addRoleScope($roleScopeSee2);
|
$permissionsGroup->addRoleScope($roleScopeSee2);
|
||||||
|
|
||||||
$manager->persist($roleScopeUpdate);
|
$manager->persist($roleScopeUpdate);
|
||||||
$manager->persist($roleScopeUpdate2);
|
$manager->persist($roleScopeUpdate2);
|
||||||
$manager->persist($roleScopeCreate);
|
$manager->persist($roleScopeCreate);
|
||||||
@@ -97,9 +97,9 @@ class LoadRolesACL extends AbstractFixture implements OrderedFixtureInterface
|
|||||||
$manager->persist($roleScopeSee);
|
$manager->persist($roleScopeSee);
|
||||||
$manager->persist($roleScopeSee2);
|
$manager->persist($roleScopeSee2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -504,8 +504,6 @@ 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,44 +54,43 @@ 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,24 +58,23 @@ 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(string $languageCode): array {
|
private function prepareName($languageCode) {
|
||||||
$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,32 +1,35 @@
|
|||||||
<?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 LogicException(sprintf(
|
throw new \LogicalException(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,11 +19,14 @@ class Configuration implements ConfigurationInterface
|
|||||||
|
|
||||||
use AddWidgetConfigurationTrait;
|
use AddWidgetConfigurationTrait;
|
||||||
|
|
||||||
private ContainerBuilder $containerBuilder;
|
/**
|
||||||
|
*
|
||||||
|
* @var ContainerBuilder
|
||||||
|
*/
|
||||||
|
private $containerBuilder;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(array $widgetFactories = array(),
|
||||||
array $widgetFactories,
|
|
||||||
ContainerBuilder $containerBuilder)
|
ContainerBuilder $containerBuilder)
|
||||||
{
|
{
|
||||||
$this->setWidgetFactories($widgetFactories);
|
$this->setWidgetFactories($widgetFactories);
|
||||||
@@ -104,9 +107,6 @@ class Configuration implements ConfigurationInterface
|
|||||||
->booleanNode('form_show_scopes')
|
->booleanNode('form_show_scopes')
|
||||||
->defaultTrue()
|
->defaultTrue()
|
||||||
->end()
|
->end()
|
||||||
->booleanNode('form_show_centers')
|
|
||||||
->defaultTrue()
|
|
||||||
->end()
|
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->arrayNode('redis')
|
->arrayNode('redis')
|
||||||
|
@@ -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,25 +118,24 @@ 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(
|
public function doProcess(ContainerBuilder $container, $extension,
|
||||||
ContainerBuilder $container,
|
$containerWidgetConfigParameterName)
|
||||||
$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);
|
||||||
@@ -149,19 +148,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
|
||||||
@@ -169,43 +168,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
|
||||||
));
|
));
|
||||||
@@ -213,10 +212,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
|
||||||
@@ -232,28 +231,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
|
||||||
@@ -263,7 +262,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
|
||||||
@@ -271,14 +270,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
|
||||||
*/
|
*/
|
||||||
@@ -289,7 +288,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]);
|
||||||
|
|
||||||
@@ -301,17 +300,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
|
||||||
@@ -321,13 +320,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(
|
||||||
@@ -336,54 +335,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,9 +4,13 @@ namespace Chill\MainBundle\Doctrine\Model;
|
|||||||
|
|
||||||
use \JsonSerializable;
|
use \JsonSerializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of Point
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Point implements JsonSerializable {
|
class Point implements JsonSerializable {
|
||||||
private ?float $lat;
|
private ?float $lat = null;
|
||||||
private ?float $lon;
|
private ?float $lon = null;
|
||||||
public static string $SRID = '4326';
|
public static string $SRID = '4326';
|
||||||
|
|
||||||
private function __construct(?float $lon, ?float $lat)
|
private function __construct(?float $lon, ?float $lat)
|
||||||
@@ -18,7 +22,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,53 +33,60 @@ 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 sprintf("SRID=%s;POINT(%s %s)", self::$SRID, $this->lon, $this->lat);
|
return 'SRID='.self::$SRID.';POINT('.$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) {
|
if (NULL === $a or !isset($a->type) or !isset($a->coordinates)){
|
||||||
throw PointException::badJsonString($geojson);
|
throw PointException::badJsonString($geojson);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $a->type || null === $a->coordinates) {
|
if ($a->type != 'Point'){
|
||||||
throw PointException::badJsonString($geojson);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($a->type !== 'Point'){
|
|
||||||
throw PointException::badGeoType();
|
throw PointException::badGeoType();
|
||||||
}
|
}
|
||||||
|
|
||||||
[$lon, $lat] = $a->coordinates;
|
$lat = $a->coordinates[1];
|
||||||
|
$lon = $a->coordinates[0];
|
||||||
|
|
||||||
return Point::fromLonLat($lon, $lat);
|
return Point::fromLonLat($lon, $lat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromLonLat(float $lon, float $lat): self
|
public static function fromLonLat(float $lon, float $lat): Point
|
||||||
{
|
{
|
||||||
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): self
|
public static function fromArrayGeoJson(array $array): Point
|
||||||
{
|
{
|
||||||
if ($array['type'] === 'Point' && isset($array['coordinates'])) {
|
if ($array['type'] == 'Point' &&
|
||||||
|
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,10 +51,8 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -70,9 +68,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,7 +4,6 @@ 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;
|
||||||
|
@@ -6,12 +6,12 @@ import App from './App.vue';
|
|||||||
const i18n = _createI18n(addressMessages);
|
const i18n = _createI18n(addressMessages);
|
||||||
|
|
||||||
const addAddressInput = (inputs) => {
|
const addAddressInput = (inputs) => {
|
||||||
console.log(inputs)
|
|
||||||
inputs.forEach(el => {
|
inputs.forEach(el => {
|
||||||
let
|
let
|
||||||
addressId = el.value,
|
addressId = el.value,
|
||||||
uniqid = el.dataset.inputAddress,
|
uniqid = el.dataset.inputAddress,
|
||||||
container = el.parentNode.querySelector('div[data-input-address-container="' + uniqid + '"]'),
|
container = document.querySelector('div[data-input-address-container="' + uniqid + '"]'),
|
||||||
isEdit = addressId !== '',
|
isEdit = addressId !== '',
|
||||||
addressIdInt = addressId !== '' ? parseInt(addressId) : null
|
addressIdInt = addressId !== '' ? parseInt(addressId) : null
|
||||||
;
|
;
|
||||||
|
@@ -45,8 +45,7 @@ const messages = {
|
|||||||
redirect: {
|
redirect: {
|
||||||
person: "Quitter la page et ouvrir la fiche de l'usager",
|
person: "Quitter la page et ouvrir la fiche de l'usager",
|
||||||
thirdparty: "Quitter la page et voir le tiers",
|
thirdparty: "Quitter la page et voir le tiers",
|
||||||
},
|
}
|
||||||
refresh: 'Rafraîchir'
|
|
||||||
},
|
},
|
||||||
nav: {
|
nav: {
|
||||||
next: "Suivant",
|
next: "Suivant",
|
||||||
|
@@ -47,15 +47,8 @@
|
|||||||
{% endblock content_form_actions_view %}
|
{% endblock content_form_actions_view %}
|
||||||
{% block content_form_actions_save_and_close %}
|
{% block content_form_actions_save_and_close %}
|
||||||
<li class="">
|
<li class="">
|
||||||
<button type="submit" name="submit" value="save-and-close" class="btn btn-update" form="{{ formId }}">
|
<button type="submit" name="submit" value="save" class="btn btn-update" form="{{ formId }}">
|
||||||
{{ 'crud.edit.save_and_close'|trans }}
|
{{ 'crud.edit.save'|trans }}
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{% endblock %}
|
|
||||||
{% block content_form_actions_save_and_show %}
|
|
||||||
<li class="">
|
|
||||||
<button type="submit" name="submit" value="save-and-show" class="btn btn-update" form="{{ formId }}">
|
|
||||||
{{ 'crud.edit.save_and_show'|trans }}
|
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -28,15 +28,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content_form_actions_save_and_close %}
|
{% block content_form_actions_save_and_close %}
|
||||||
<li class="">
|
<li class="">
|
||||||
<button type="submit" name="submit" value="save-and-close" class="btn btn-create" form="{{ formId }}">
|
<button type="submit" name="submit" value="save" class="btn btn-create" form="{{ formId }}">
|
||||||
{{ 'crud.new.save_and_close'|trans }}
|
{{ 'crud.new.save'|trans }}
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{% endblock %}
|
|
||||||
{% block content_form_actions_save_and_show %}
|
|
||||||
<li class="">
|
|
||||||
<button type="submit" name="submit" value="save-and-show" class="btn btn-create" form="{{ formId }}">
|
|
||||||
{{ 'crud.new.save_and_show'|trans }}
|
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@@ -58,13 +58,6 @@
|
|||||||
|
|
||||||
{% macro inline(address, options) %}
|
{% macro inline(address, options) %}
|
||||||
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
||||||
{% if address.postCode is not empty %}
|
|
||||||
<p class="postcode">
|
|
||||||
<span class="code">{{ address.postCode.code }}</span>
|
|
||||||
<span class="name">{{ address.postCode.name }}</span>
|
|
||||||
</p>
|
|
||||||
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
|
|
||||||
{% endif %}
|
|
||||||
<span class="noaddress">
|
<span class="noaddress">
|
||||||
{{ 'address.consider homeless'|trans }}
|
{{ 'address.consider homeless'|trans }}
|
||||||
</span>
|
</span>
|
||||||
@@ -115,19 +108,9 @@
|
|||||||
{%- if render == 'bloc' -%}
|
{%- if render == 'bloc' -%}
|
||||||
<div class="chill-entity entity-address">
|
<div class="chill-entity entity-address">
|
||||||
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
||||||
{% if address.postCode is not empty %}
|
|
||||||
<div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
|
|
||||||
<p class="postcode">
|
|
||||||
<span class="code">{{ address.postCode.code }}</span>
|
|
||||||
<span class="name">{{ address.postCode.name }}</span>
|
|
||||||
</p>
|
|
||||||
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div class="noaddress">
|
<div class="noaddress">
|
||||||
{{ 'address.consider homeless'|trans }}
|
{{ 'address.consider homeless'|trans }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
|
<div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
|
||||||
{% if options['with_picto'] %}
|
{% if options['with_picto'] %}
|
||||||
|
@@ -10,32 +10,30 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if form.checkboxes is defined %}
|
{% if form.checkboxes|length > 0 %}
|
||||||
{% if form.checkboxes|length > 0 %}
|
{% for checkbox_name, options in form.checkboxes %}
|
||||||
{% for checkbox_name, options in form.checkboxes %}
|
<div class="row gx-0">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% for c in form['checkboxes'][checkbox_name].children %}
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
{{ form_widget(c) }}
|
||||||
|
{{ form_label(c) }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% if loop.last %}
|
||||||
<div class="row gx-0">
|
<div class="row gx-0">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
{% for c in form['checkboxes'][checkbox_name].children %}
|
<ul class="record_actions">
|
||||||
<div class="form-check form-check-inline">
|
<li>
|
||||||
{{ form_widget(c) }}
|
<button type="submit" class="btn btn-misc"><i class="fa fa-filter"></i></button>
|
||||||
{{ form_label(c) }}
|
</li>
|
||||||
</div>
|
</ul>
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if loop.last %}
|
{% endif %}
|
||||||
<div class="row gx-0">
|
{% endfor %}
|
||||||
<div class="col-md-12">
|
|
||||||
<ul class="record_actions">
|
|
||||||
<li>
|
|
||||||
<button type="submit" class="btn btn-misc"><i class="fa fa-filter"></i></button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
@@ -88,13 +88,13 @@ class SearchApi
|
|||||||
|
|
||||||
private function buildCountQuery(array $queries, $types, $parameters)
|
private function buildCountQuery(array $queries, $types, $parameters)
|
||||||
{
|
{
|
||||||
$query = "SELECT COUNT(*) AS count FROM ({union_unordered}) AS sq";
|
$query = "SELECT COUNT(sq.key) AS count FROM ({union_unordered}) AS sq";
|
||||||
$unions = [];
|
$unions = [];
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
|
|
||||||
foreach ($queries as $q) {
|
foreach ($queries as $q) {
|
||||||
$unions[] = $q->buildQuery(true);
|
$unions[] = $q->buildQuery();
|
||||||
$parameters = \array_merge($parameters, $q->buildParameters(true));
|
$parameters = \array_merge($parameters, $q->buildParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
$unionUnordered = \implode(" UNION ", $unions);
|
$unionUnordered = \implode(" UNION ", $unions);
|
||||||
@@ -139,7 +139,7 @@ class SearchApi
|
|||||||
return $nq->getResult();
|
return $nq->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareProviders(array $rawResults)
|
private function prepareProviders($rawResults)
|
||||||
{
|
{
|
||||||
$metadatas = [];
|
$metadatas = [];
|
||||||
foreach ($rawResults as $r) {
|
foreach ($rawResults as $r) {
|
||||||
@@ -156,10 +156,8 @@ class SearchApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildResults(array $rawResults): array
|
private function buildResults($rawResults)
|
||||||
{
|
{
|
||||||
$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'])) {
|
||||||
@@ -172,6 +170,6 @@ class SearchApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $items;
|
return $items ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,58 +76,33 @@ class SearchApiQuery
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildQuery(bool $countOnly = false): string
|
public function buildQuery(): string
|
||||||
{
|
{
|
||||||
$isMultiple = count($this->whereClauses);
|
$where = \implode(' AND ', $this->whereClauses);
|
||||||
$where =
|
|
||||||
($isMultiple ? '(' : '').
|
|
||||||
\implode(
|
|
||||||
($isMultiple ? ')' : '').' AND '.($isMultiple ? '(' : '')
|
|
||||||
, $this->whereClauses).
|
|
||||||
($isMultiple ? ')' : '')
|
|
||||||
;
|
|
||||||
|
|
||||||
if (!$countOnly) {
|
return \strtr("SELECT
|
||||||
$select = \strtr("
|
|
||||||
'{key}' AS key,
|
'{key}' AS key,
|
||||||
{metadata} AS metadata,
|
{metadata} AS metadata,
|
||||||
{pertinence} AS pertinence
|
{pertinence} AS pertinence
|
||||||
", [
|
FROM {from}
|
||||||
'{key}' => $this->selectKey,
|
WHERE {where}
|
||||||
'{metadata}' => $this->jsonbMetadata,
|
|
||||||
'{pertinence}' => $this->pertinence,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$select = "1 AS c";
|
|
||||||
}
|
|
||||||
|
|
||||||
return \strtr("SELECT
|
|
||||||
{select}
|
|
||||||
FROM {from}
|
|
||||||
WHERE {where}
|
|
||||||
", [
|
", [
|
||||||
'{select}' => $select,
|
'{key}' => $this->selectKey,
|
||||||
|
'{metadata}' => $this->jsonbMetadata,
|
||||||
|
'{pertinence}' => $this->pertinence,
|
||||||
'{from}' => $this->fromClause,
|
'{from}' => $this->fromClause,
|
||||||
'{where}' => $where,
|
'{where}' => $where,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function buildParameters(): array
|
||||||
public function buildParameters(bool $countOnly = false): array
|
|
||||||
{
|
{
|
||||||
if (!$countOnly) {
|
return \array_merge(
|
||||||
return \array_merge(
|
$this->selectKeyParams,
|
||||||
$this->selectKeyParams,
|
$this->jsonbMetadataParams,
|
||||||
$this->jsonbMetadataParams,
|
$this->pertinenceParams,
|
||||||
$this->pertinenceParams,
|
$this->fromClauseParams,
|
||||||
$this->fromClauseParams,
|
\array_merge([], ...$this->whereClausesParams),
|
||||||
\array_merge([], ...$this->whereClausesParams),
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return \array_merge(
|
|
||||||
$this->fromClauseParams,
|
|
||||||
\array_merge([], ...$this->whereClausesParams),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,5 @@ class PasswordRecoverVoter extends Voter
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
<?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;
|
||||||
@@ -14,41 +12,31 @@ 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 = [])
|
||||||
{
|
{
|
||||||
$data = [
|
/** @var Address $address */
|
||||||
'address_id' => $address->getId(),
|
$data['address_id'] = $address->getId();
|
||||||
'text' => $address->isNoAddress() ? '' : $address->getStreetNumber().', '.$address->getStreet(),
|
$data['text'] = $address->isNoAddress() ? '' : $address->getStreetNumber().', '.$address->getStreet();
|
||||||
'street' => $address->getStreet(),
|
$data['street'] = $address->getStreet();
|
||||||
'streetNumber' => $address->getStreetNumber(),
|
$data['streetNumber'] = $address->getStreetNumber();
|
||||||
'postcode' => [
|
$data['postcode']['id'] = $address->getPostCode()->getId();
|
||||||
'id' => $address->getPostCode()->getId(),
|
$data['postcode']['name'] = $address->getPostCode()->getName();
|
||||||
'name' => $address->getPostCode()->getName(),
|
$data['postcode']['code'] = $address->getPostCode()->getCode();
|
||||||
'code' => $address->getPostCode()->getCode(),
|
$data['country']['id'] = $address->getPostCode()->getCountry()->getId();
|
||||||
],
|
$data['country']['name'] = $address->getPostCode()->getCountry()->getName();
|
||||||
'country' => [
|
$data['country']['code'] = $address->getPostCode()->getCountry()->getCountryCode();
|
||||||
'id' => $address->getPostCode()->getCountry()->getId(),
|
$data['floor'] = $address->getFloor();
|
||||||
'name' => $address->getPostCode()->getCountry()->getName(),
|
$data['corridor'] = $address->getCorridor();
|
||||||
'code' => $address->getPostCode()->getCountry()->getCountryCode(),
|
$data['steps'] = $address->getSteps();
|
||||||
],
|
$data['flat'] = $address->getFlat();
|
||||||
'floor' => $address->getFloor(),
|
$data['buildingName'] = $address->getBuildingName();
|
||||||
'corridor' => $address->getCorridor(),
|
$data['distribution'] = $address->getDistribution();
|
||||||
'steps' => $address->getSteps(),
|
$data['extra'] = $address->getExtra();
|
||||||
'flat' => $address->getFlat(),
|
$data['validFrom'] = $address->getValidFrom();
|
||||||
'buildingName' => $address->getBuildingName(),
|
$data['validTo'] = $address->getValidTo();
|
||||||
'distribution' => $address->getDistribution(),
|
$data['addressReference'] = $this->normalizer->normalize($address->getAddressReference(), $format, [
|
||||||
'extra' => $address->getExtra(),
|
AbstractNormalizer::GROUPS => ['read']
|
||||||
'validFrom' => $address->getValidFrom(),
|
]);
|
||||||
'validTo' => $address->getValidTo(),
|
|
||||||
'addressReference' => $this->normalizer->normalize(
|
|
||||||
$address->getAddressReference(),
|
|
||||||
$format,
|
|
||||||
[AbstractNormalizer::GROUPS => ['read']]
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@@ -9,30 +9,32 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ trait PrepareClientTrait
|
|||||||
*
|
*
|
||||||
* @param string $username the username (default 'center a_social')
|
* @param string $username the username (default 'center a_social')
|
||||||
* @param string $password the password (default 'password')
|
* @param string $password the password (default 'password')
|
||||||
|
* @return \Symfony\Component\BrowserKit\Client
|
||||||
* @throws \LogicException
|
* @throws \LogicException
|
||||||
*/
|
*/
|
||||||
public function getClientAuthenticated(
|
public function getClientAuthenticated(
|
||||||
|
@@ -20,12 +20,7 @@ class SearchApiQueryTest extends TestCase
|
|||||||
|
|
||||||
$query = $q->buildQuery();
|
$query = $q->buildQuery();
|
||||||
|
|
||||||
$this->assertStringContainsString('(foo) AND (bar)', $query);
|
$this->assertStringContainsString('foo AND bar', $query);
|
||||||
$this->assertEquals(['alpha', 'beta'], $q->buildParameters());
|
|
||||||
|
|
||||||
$query = $q->buildQuery(true);
|
|
||||||
|
|
||||||
$this->assertStringContainsString('(foo) AND (bar)', $query);
|
|
||||||
$this->assertEquals(['alpha', 'beta'], $q->buildParameters());
|
$this->assertEquals(['alpha', 'beta'], $q->buildParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,18 +37,6 @@ 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,12 +291,11 @@ 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[] = [
|
$timelineEntries[] = $timelineEntry;
|
||||||
'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,11 +140,72 @@ 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;
|
||||||
@@ -154,7 +215,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;
|
||||||
|
@@ -74,7 +74,7 @@ Choose a postal code: Choisir un code postal
|
|||||||
address:
|
address:
|
||||||
address_homeless: L'adresse est-elle celle d'un domicile fixe ?
|
address_homeless: L'adresse est-elle celle d'un domicile fixe ?
|
||||||
real address: Adresse d'un domicile
|
real address: Adresse d'un domicile
|
||||||
consider homeless: Cette adresse est incomplète
|
consider homeless: N'est pas l'adresse d'un domicile (SDF)
|
||||||
address more:
|
address more:
|
||||||
floor: ét
|
floor: ét
|
||||||
corridor: coul
|
corridor: coul
|
||||||
@@ -297,8 +297,9 @@ crud:
|
|||||||
edit:
|
edit:
|
||||||
button_action_form: Enregistrer
|
button_action_form: Enregistrer
|
||||||
back_to_view: Voir
|
back_to_view: Voir
|
||||||
save_and_close: Enregistrer & fermer
|
save: Enregistrer
|
||||||
save_and_show: Enregistrer & voir
|
# save_and_close: Enregistrer & fermer
|
||||||
|
# save_and_show: Enregistrer & voir
|
||||||
success: Les données ont été modifiées
|
success: Les données ont été modifiées
|
||||||
delete:
|
delete:
|
||||||
success: Les données ont été supprimées
|
success: Les données ont été supprimées
|
||||||
|
@@ -1,7 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
/*
|
||||||
declare(strict_types=1);
|
* Copyright (C) 2016-2019 Champs-Libres <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
namespace Chill\PersonBundle\CRUD\Controller;
|
namespace Chill\PersonBundle\CRUD\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||||
@@ -10,8 +23,11 @@ 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)
|
||||||
@@ -19,11 +35,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';
|
||||||
@@ -33,41 +49,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 implemented yet.');
|
throw new BadMethodCallException("not implemtented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -959,8 +959,6 @@ 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
|
||||||
|
@@ -24,29 +24,27 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
|||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
|
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
||||||
|
|
||||||
final class AccompanyingCourseApiController extends ApiController
|
class AccompanyingCourseApiController extends ApiController
|
||||||
{
|
{
|
||||||
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
|
protected EventDispatcherInterface $eventDispatcher;
|
||||||
private EventDispatcherInterface $eventDispatcher;
|
|
||||||
private ValidatorInterface $validator;
|
protected ValidatorInterface $validator;
|
||||||
|
|
||||||
private Registry $registry;
|
private Registry $registry;
|
||||||
|
|
||||||
private ReferralsSuggestionInterface $referralAvailable;
|
private ReferralsSuggestionInterface $referralAvailable;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
ValidatorInterface $validator,
|
ValidatorInterface $validator,
|
||||||
Registry $registry,
|
Registry $registry,
|
||||||
AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository,
|
|
||||||
ReferralsSuggestionInterface $referralAvailable
|
ReferralsSuggestionInterface $referralAvailable
|
||||||
) {
|
) {
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
|
||||||
$this->referralAvailable = $referralAvailable;
|
$this->referralAvailable = $referralAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,14 +54,10 @@ final 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');
|
||||||
@@ -115,13 +109,6 @@ final class AccompanyingCourseApiController extends ApiController
|
|||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,18 +198,6 @@ final class AccompanyingCourseApiController extends ApiController
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @ParamConverter("person", options={"id" = "person_id"})
|
|
||||||
*/
|
|
||||||
public function getAccompanyingPeriodsByPerson(Person $person){
|
|
||||||
$accompanyingPeriods = $person->getCurrentAccompanyingPeriods();
|
|
||||||
$accompanyingPeriodsChecked = array_filter($accompanyingPeriods,
|
|
||||||
function(AccompanyingPeriod $period){
|
|
||||||
return $this->isGranted(AccompanyingPeriodVoter::SEE, $period);
|
|
||||||
});
|
|
||||||
return $this->json(\array_values($accompanyingPeriodsChecked), Response::HTTP_OK, [], ['groups' => [ 'read']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/api/1.0/person/accompanying-course/{id}/referrers-suggested.{_format}",
|
* @Route("/api/1.0/person/accompanying-course/{id}/referrers-suggested.{_format}",
|
||||||
* requirements={ "_format"="json"},
|
* requirements={ "_format"="json"},
|
||||||
|
@@ -11,10 +11,7 @@ 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
|
||||||
{
|
{
|
||||||
@@ -22,20 +19,17 @@ class AccompanyingCourseWorkController extends AbstractController
|
|||||||
private SerializerInterface $serializer;
|
private SerializerInterface $serializer;
|
||||||
private AccompanyingPeriodWorkRepository $workRepository;
|
private AccompanyingPeriodWorkRepository $workRepository;
|
||||||
private PaginatorFactory $paginator;
|
private PaginatorFactory $paginator;
|
||||||
private LoggerInterface $chillLogger;
|
|
||||||
|
|
||||||
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->chillLogger = $chillLogger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,66 +106,4 @@ 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->chillLogger->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 = [];
|
|
||||||
$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()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -47,22 +47,13 @@ class HouseholdApiController extends ApiController
|
|||||||
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
|
$count = $this->householdRepository->countByAccompanyingPeriodParticipation($person);
|
||||||
$paginator = $this->getPaginatorFactory()->create($count);
|
$paginator = $this->getPaginatorFactory()->create($count);
|
||||||
|
|
||||||
$households = [];
|
if ($count === 0) {
|
||||||
if ($count !== 0) {
|
$households = [];
|
||||||
$allHouseholds = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
|
} else {
|
||||||
|
$households = $this->householdRepository->findByAccompanyingPeriodParticipation($person,
|
||||||
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
$paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber());
|
||||||
$currentHouseholdPerson = $person->getCurrentHousehold();
|
|
||||||
|
|
||||||
foreach ($allHouseholds as $h) {
|
|
||||||
if ($h !== $currentHouseholdPerson) {
|
|
||||||
array_push($households, $h);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (null !== $currentHouseholdPerson) {
|
|
||||||
$count = $count - 1;
|
|
||||||
$paginator = $this->getPaginatorFactory()->create($count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection = new Collection($households, $paginator);
|
$collection = new Collection($households, $paginator);
|
||||||
|
|
||||||
return $this->json($collection, Response::HTTP_OK, [],
|
return $this->json($collection, Response::HTTP_OK, [],
|
||||||
|
@@ -9,8 +9,6 @@ use Symfony\Component\Form\FormInterface;
|
|||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
@@ -28,19 +26,13 @@ class HouseholdController extends AbstractController
|
|||||||
|
|
||||||
private PositionRepository $positionRepository;
|
private PositionRepository $positionRepository;
|
||||||
|
|
||||||
private SerializerInterface $serializer;
|
|
||||||
|
|
||||||
private Security $security;
|
private Security $security;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(TranslatorInterface $translator, PositionRepository $positionRepository, Security $security)
|
||||||
TranslatorInterface $translator,
|
|
||||||
PositionRepository $positionRepository,
|
{
|
||||||
SerializerInterface $serializer,
|
|
||||||
Security $security
|
|
||||||
) {
|
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->positionRepository = $positionRepository;
|
$this->positionRepository = $positionRepository;
|
||||||
$this->serializer = $serializer;
|
|
||||||
$this->security = $security;
|
$this->security = $security;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,13 +211,9 @@ class HouseholdController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function showRelationship(Request $request, Household $household)
|
public function showRelationship(Request $request, Household $household)
|
||||||
{
|
{
|
||||||
$jsonString = $this->serializer->serialize($household->getCurrentPersons(),
|
|
||||||
'json', [ AbstractNormalizer::GROUPS => ['read']]);
|
|
||||||
|
|
||||||
return $this->render('@ChillPerson/Household/relationship.html.twig',
|
return $this->render('@ChillPerson/Household/relationship.html.twig',
|
||||||
[
|
[
|
||||||
'household' => $household,
|
'household' => $household
|
||||||
'persons' => $jsonString
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
|
||||||
|
|
||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
||||||
|
|
||||||
class RelationshipApiController extends ApiController
|
|
||||||
{
|
|
||||||
private ValidatorInterface $validator;
|
|
||||||
private RelationshipRepository $repository;
|
|
||||||
|
|
||||||
public function __construct(ValidatorInterface $validator, RelationshipRepository $repository)
|
|
||||||
{
|
|
||||||
$this->validator = $validator;
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ParamConverter("person", options={"id" = "person_id"})
|
|
||||||
*/
|
|
||||||
public function getRelationshipsByPerson(Person $person)
|
|
||||||
{
|
|
||||||
//TODO: add permissions? (voter?)
|
|
||||||
$relationships = $this->repository->findByPerson($person);
|
|
||||||
|
|
||||||
return $this->json(\array_values($relationships), Response::HTTP_OK, [], ['groups' => [ 'read']]);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\DataFixtures\Helper;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
|
|
||||||
trait PersonRandomHelper
|
|
||||||
{
|
|
||||||
private array $randPersons = [];
|
|
||||||
private ?int $countPersons = null;
|
|
||||||
|
|
||||||
protected function getRandomPerson(EntityManagerInterface $em): Person
|
|
||||||
{
|
|
||||||
$fetchBy = 5;
|
|
||||||
if (null === $this->countPersons) {
|
|
||||||
$qb = $em->createQueryBuilder();
|
|
||||||
$this->countPersons = $qb->select('count(p)')
|
|
||||||
->from(Person::class, 'p')
|
|
||||||
->getQuery()
|
|
||||||
->getSingleScalarResult()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([] === $this->randPersons) {
|
|
||||||
$qb = $em->createQueryBuilder();
|
|
||||||
$this->randPersons = $qb
|
|
||||||
->select('p')
|
|
||||||
->from(Person::class, 'p')
|
|
||||||
->getQuery()
|
|
||||||
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
|
|
||||||
->setMaxResults($fetchBy)
|
|
||||||
->getResult()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
return \array_pop($this->randPersons);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -40,7 +40,7 @@ class LoadAccompanyingPeriodOrigin extends AbstractFixture implements OrderedFix
|
|||||||
|
|
||||||
public function getOrder()
|
public function getOrder()
|
||||||
{
|
{
|
||||||
return 9000;
|
return 10005;
|
||||||
}
|
}
|
||||||
|
|
||||||
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
||||||
|
@@ -161,10 +161,8 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
\shuffle($this->personIds);
|
\shuffle($this->personIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomPersons(int $min, int $max): array
|
private function getRandomPersons(int $min, int $max)
|
||||||
{
|
{
|
||||||
$persons = [];
|
|
||||||
|
|
||||||
$nb = \random_int($min, $max);
|
$nb = \random_int($min, $max);
|
||||||
|
|
||||||
for ($i=0; $i < $nb; $i++) {
|
for ($i=0; $i < $nb; $i++) {
|
||||||
@@ -174,7 +172,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $persons;
|
return $persons ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDependencies()
|
public function getDependencies()
|
||||||
|
@@ -10,8 +10,8 @@ class LoadHouseholdPosition extends Fixture
|
|||||||
{
|
{
|
||||||
const POSITIONS_DATA = [
|
const POSITIONS_DATA = [
|
||||||
["Adulte", true, true, 1.0, self::ADULT ],
|
["Adulte", true, true, 1.0, self::ADULT ],
|
||||||
["Enfant", true, false, 2.0, self::CHILD ],
|
["Enfants", true, false, 2.0, self::CHILD ],
|
||||||
["Enfant hors ménage", false, false, 3.0, self::CHILD_OUT ]
|
["Enfants hors ménage", false, false, 3.0, self::CHILD_OUT ]
|
||||||
];
|
];
|
||||||
|
|
||||||
const ADULT = "position_adulte";
|
const ADULT = "position_adulte";
|
||||||
|
@@ -106,8 +106,6 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
|
|
||||||
protected UserRepository $userRepository;
|
protected UserRepository $userRepository;
|
||||||
|
|
||||||
public const PERSON = 'person';
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Registry $workflowRegistry,
|
Registry $workflowRegistry,
|
||||||
SocialIssueRepository $socialIssueRepository,
|
SocialIssueRepository $socialIssueRepository,
|
||||||
@@ -249,9 +247,7 @@ 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);
|
||||||
@@ -261,8 +257,6 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
$manager->persist($person);
|
$manager->persist($person);
|
||||||
$manager->persist($accompanyingPeriod);
|
$manager->persist($accompanyingPeriod);
|
||||||
echo "add person'".$person->__toString()."'\n";
|
echo "add person'".$person->__toString()."'\n";
|
||||||
|
|
||||||
$this->addReference(self::PERSON.$person->getId(), $person);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomUser(): User
|
private function getRandomUser(): User
|
||||||
|
@@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
|
|
||||||
class LoadRelations extends Fixture implements FixtureGroupInterface
|
|
||||||
{
|
|
||||||
public const RELATION_KEY = 'relations';
|
|
||||||
public const RELATIONS = [
|
|
||||||
['title' => ['fr' => 'Mère'], 'reverseTitle' => ['fr' => 'Fille']],
|
|
||||||
['title' => ['fr' => 'Mère'], 'reverseTitle' => ['fr' => 'Fils']],
|
|
||||||
['title' => ['fr' => 'Père'], 'reverseTitle' => ['fr' => 'Fille']],
|
|
||||||
['title' => ['fr' => 'Père'], 'reverseTitle' => ['fr' => 'Fils']],
|
|
||||||
|
|
||||||
['title' => ['fr' => 'Frère'], 'reverseTitle' => ['fr' => 'Frère']],
|
|
||||||
['title' => ['fr' => 'Soeur'], 'reverseTitle' => ['fr' => 'Soeur']],
|
|
||||||
['title' => ['fr' => 'Frère'], 'reverseTitle' => ['fr' => 'Soeur']],
|
|
||||||
|
|
||||||
['title' => ['fr' => 'Demi-frère'], 'reverseTitle' => ['fr' => 'Demi-frère']],
|
|
||||||
['title' => ['fr' => 'Demi-soeur'], 'reverseTitle' => ['fr' => 'Demi-soeur']],
|
|
||||||
['title' => ['fr' => 'Demi-frère'], 'reverseTitle' => ['fr' => 'Demi-soeur']],
|
|
||||||
|
|
||||||
['title' => ['fr' => 'Oncle'], 'reverseTitle' => ['fr' => 'Neveu']],
|
|
||||||
['title' => ['fr' => 'Oncle'], 'reverseTitle' => ['fr' => 'Nièce']],
|
|
||||||
['title' => ['fr' => 'Tante'], 'reverseTitle' => ['fr' => 'Neveu']],
|
|
||||||
['title' => ['fr' => 'Tante'], 'reverseTitle' => ['fr' => 'Nièce']],
|
|
||||||
];
|
|
||||||
|
|
||||||
public static function getGroups(): array
|
|
||||||
{
|
|
||||||
return ['person_relations'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
|
||||||
{
|
|
||||||
foreach (self::RELATIONS as $key => $value){
|
|
||||||
print "Creating a new relation type: relation" . $value['title']['fr'] . "reverse relation: " . $value['reverseTitle']['fr'] . "\n";
|
|
||||||
$relation = new Relation();
|
|
||||||
$relation->setTitle($value['title'])
|
|
||||||
->setReverseTitle($value['reverseTitle']);
|
|
||||||
$manager->persist($relation);
|
|
||||||
|
|
||||||
$this->addReference(self::RELATION_KEY.$key, $relation);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
|
||||||
|
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
|
||||||
|
|
||||||
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
|
||||||
{
|
|
||||||
use PersonRandomHelper;
|
|
||||||
private EntityManagerInterface $em;
|
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
|
||||||
{
|
|
||||||
$this->em = $em;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDependencies()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
LoadPeople::class,
|
|
||||||
LoadRelations::class
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
|
||||||
{
|
|
||||||
for ($i = 0; $i < 15; $i++) {
|
|
||||||
$user = $this->getRandomUser();
|
|
||||||
$date = new \DateTimeImmutable();
|
|
||||||
$relationship = (new Relationship())
|
|
||||||
->setFromPerson($this->getRandomPerson($this->em))
|
|
||||||
->setToPerson($this->getRandomPerson($this->em))
|
|
||||||
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
|
|
||||||
\random_int(0, count(LoadRelations::RELATIONS) - 1)))
|
|
||||||
->setReverse((bool) random_int(0, 1))
|
|
||||||
->setCreatedBy($user)
|
|
||||||
->setUpdatedBy($user)
|
|
||||||
->setCreatedAt($date)
|
|
||||||
->setUpdatedAt($date)
|
|
||||||
;
|
|
||||||
$manager->persist($relationship);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getRandomUser(): User
|
|
||||||
{
|
|
||||||
$userRef = array_rand(LoadUsers::$refs);
|
|
||||||
return $this->getReference($userRef);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -585,14 +585,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE,
|
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'findAccompanyingPeriodsByPerson' => [
|
|
||||||
'path' => '/by-person/{person_id}.{_format}',
|
|
||||||
'controller_action' => 'getAccompanyingPeriodsByPerson',
|
|
||||||
'methods' => [
|
|
||||||
Request::METHOD_GET => true,
|
|
||||||
Request::METHOD_HEAD => true,
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
@@ -870,59 +862,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'class' => \Chill\PersonBundle\Entity\Relationships\Relationship::class,
|
|
||||||
'controller' => \Chill\PersonBundle\Controller\RelationshipApiController::class,
|
|
||||||
'name' => 'relationship_by_person',
|
|
||||||
'base_path' => '/api/1.0/relations/relationship',
|
|
||||||
'base_role' => 'ROLE_USER',
|
|
||||||
'actions' => [
|
|
||||||
'_entity' => [
|
|
||||||
'methods' => [
|
|
||||||
Request::METHOD_POST => true,
|
|
||||||
Request::METHOD_PATCH => true,
|
|
||||||
Request::METHOD_DELETE => true,
|
|
||||||
],
|
|
||||||
'roles' => [
|
|
||||||
Request::METHOD_POST => 'ROLE_USER',
|
|
||||||
Request::METHOD_PATCH => 'ROLE_USER',
|
|
||||||
Request::METHOD_DELETE => 'ROLE_USER',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'relationship-by-person' => [
|
|
||||||
'path' => '/by-person/{person_id}.json',
|
|
||||||
'controller_action' => 'getRelationshipsByPerson',
|
|
||||||
'methods' => [
|
|
||||||
Request::METHOD_GET => true,
|
|
||||||
Request::METHOD_HEAD => true,
|
|
||||||
],
|
|
||||||
'roles' => [
|
|
||||||
Request::METHOD_GET => 'ROLE_USER',
|
|
||||||
Request::METHOD_HEAD => 'ROLE_USER',
|
|
||||||
]
|
|
||||||
],
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'class' => \Chill\PersonBundle\Entity\Relationships\Relation::class,
|
|
||||||
'name' => 'relations',
|
|
||||||
'base_path' => '/api/1.0/relations/relation',
|
|
||||||
'base_role' => 'ROLE_USER',
|
|
||||||
'actions' => [
|
|
||||||
'_index' => [
|
|
||||||
'methods' => [
|
|
||||||
Request::METHOD_GET => true,
|
|
||||||
Request::METHOD_HEAD => true
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'_entity' => [
|
|
||||||
'methods' => [
|
|
||||||
Request::METHOD_GET => true,
|
|
||||||
Request::METHOD_HEAD => true
|
|
||||||
]
|
|
||||||
],
|
|
||||||
]
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@@ -45,9 +45,6 @@ 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
|
||||||
@@ -57,10 +54,9 @@ use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\ResourceDuplicat
|
|||||||
* @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, GroupSequenceProviderInterface
|
HasScopesInterface, HasCentersInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Mark an accompanying period as "occasional"
|
* Mark an accompanying period as "occasional"
|
||||||
@@ -136,7 +132,6 @@ 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;
|
||||||
|
|
||||||
@@ -152,10 +147,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var Collection
|
* @var Collection
|
||||||
*
|
*
|
||||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
||||||
* mappedBy="accompanyingPeriod", orphanRemoval=true,
|
* mappedBy="accompanyingPeriod",
|
||||||
* 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;
|
||||||
|
|
||||||
@@ -194,7 +188,6 @@ 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;
|
||||||
|
|
||||||
@@ -202,9 +195,8 @@ 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 = self::INTENSITY_OCCASIONAL;
|
private $intensity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
@@ -218,7 +210,6 @@ 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;
|
||||||
|
|
||||||
@@ -265,7 +256,6 @@ 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;
|
||||||
|
|
||||||
@@ -277,7 +267,6 @@ 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;
|
||||||
|
|
||||||
@@ -617,14 +606,6 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
return $participation;
|
return $participation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove Participation
|
|
||||||
*/
|
|
||||||
|
|
||||||
public function removeParticipation(AccompanyingPeriodParticipation $participation)
|
|
||||||
{
|
|
||||||
$participation->setAccompanyingPeriod(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove Person
|
* Remove Person
|
||||||
@@ -1134,18 +1115,4 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
return $centers ?? null;
|
return $centers ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroupSequence()
|
|
||||||
{
|
|
||||||
if ($this->getStep() == self::STEP_DRAFT)
|
|
||||||
{
|
|
||||||
return [[self::STEP_DRAFT]];
|
|
||||||
} elseif ($this->getStep() == self::STEP_CONFIRMED)
|
|
||||||
{
|
|
||||||
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \LogicException("no validation group permitted with this step");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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={"remove", "persist"},
|
* cascade={"persist"},
|
||||||
* orphanRemoval=true
|
* orphanRemoval=true
|
||||||
* )
|
* )
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
@@ -70,8 +70,7 @@ 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,13 +33,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(
|
* @ORM\Table(name="chill_person_accompanying_period_resource")
|
||||||
* 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,11 +134,4 @@ class AccompanyingPeriodParticipation
|
|||||||
{
|
{
|
||||||
return $this->endDate === null;
|
return $this->endDate === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkSameStartEnd()
|
|
||||||
{
|
|
||||||
if($this->endDate == $this->startDate) {
|
|
||||||
$this->accompanyingPeriod->removeParticipation($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -931,19 +931,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* return gender as a Numeric form.
|
* return gender as a Numeric form.
|
||||||
* This is used for translations
|
* This is used for translations
|
||||||
* @return int
|
* @return int
|
||||||
* @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations
|
|
||||||
*/
|
*/
|
||||||
public function getGenderNumeric()
|
public function getGenderNumeric()
|
||||||
{
|
{
|
||||||
switch ($this->getGender()) {
|
if ($this->getGender() == self::FEMALE_GENDER) {
|
||||||
case self::FEMALE_GENDER:
|
return 1;
|
||||||
return 1;
|
} else {
|
||||||
case self::MALE_GENDER:
|
return 0;
|
||||||
return 0;
|
|
||||||
case self::BOTH_GENDER:
|
|
||||||
return 2;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1182,9 +1176,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* @param string $phonenumber
|
* @param string $phonenumber
|
||||||
* @return Person
|
* @return Person
|
||||||
*/
|
*/
|
||||||
public function setPhonenumber(?string $phonenumber = '')
|
public function setPhonenumber($phonenumber = '')
|
||||||
{
|
{
|
||||||
$this->phonenumber = (string) $phonenumber;
|
$this->phonenumber = $phonenumber;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -1205,9 +1199,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* @param string $mobilenumber
|
* @param string $mobilenumber
|
||||||
* @return Person
|
* @return Person
|
||||||
*/
|
*/
|
||||||
public function setMobilenumber(?string $mobilenumber = '')
|
public function setMobilenumber($mobilenumber = '')
|
||||||
{
|
{
|
||||||
$this->mobilenumber = (string) $mobilenumber;
|
$this->mobilenumber = $mobilenumber;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -1,85 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Entity\Relationships;
|
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Entity()
|
|
||||||
* @ORM\Table(name="chill_person_relations")
|
|
||||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
|
||||||
* "relation"=Relation::class
|
|
||||||
* })
|
|
||||||
*/
|
|
||||||
class Relation
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @ORM\Id
|
|
||||||
* @ORM\GeneratedValue
|
|
||||||
* @ORM\Column(type="integer")
|
|
||||||
* @Serializer\Groups({"read"})
|
|
||||||
*/
|
|
||||||
private ?int $id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="json", nullable=true)
|
|
||||||
* @Serializer\Groups({"read"})
|
|
||||||
*/
|
|
||||||
private array $title = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="json", nullable=true)
|
|
||||||
* @Serializer\Groups({"read"})
|
|
||||||
*/
|
|
||||||
private array $reverseTitle = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="boolean", nullable=true)
|
|
||||||
* @Serializer\Groups({"read"})
|
|
||||||
*/
|
|
||||||
private bool $isActive = true;
|
|
||||||
|
|
||||||
public function getId(): ?int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitle(): ?array
|
|
||||||
{
|
|
||||||
return $this->title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTitle(?array $title): self
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getReverseTitle(): ?array
|
|
||||||
{
|
|
||||||
return $this->reverseTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setReverseTitle(?array $reverseTitle): self
|
|
||||||
{
|
|
||||||
$this->reverseTitle = $reverseTitle;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIsActive(): bool
|
|
||||||
{
|
|
||||||
return $this->isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIsActive(?bool $isActive): self
|
|
||||||
{
|
|
||||||
$this->isActive = $isActive;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,192 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Entity\Relationships;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Entity()
|
|
||||||
* @ORM\Table(name="chill_person_relationships")
|
|
||||||
* @DiscriminatorColumn(name="relation_id", type="integer")
|
|
||||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
|
||||||
* "relationship"=Relationship::class
|
|
||||||
* })
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Relationship implements TrackCreationInterface, TrackUpdateInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @ORM\Id
|
|
||||||
* @ORM\GeneratedValue
|
|
||||||
* @ORM\Column(type="integer")
|
|
||||||
* @Serializer\Groups({"read"})
|
|
||||||
*/
|
|
||||||
private ?int $id = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
|
||||||
* @ORM\JoinColumn(nullable=false)
|
|
||||||
* @Assert\NotNull()
|
|
||||||
* @Serializer\Groups({"read", "write"})
|
|
||||||
*/
|
|
||||||
private ?Person $fromPerson = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity=Person::class)
|
|
||||||
* @ORM\JoinColumn(nullable=false)
|
|
||||||
* @Assert\NotNull()
|
|
||||||
* @Serializer\Groups({"read", "write"})
|
|
||||||
*/
|
|
||||||
private ?Person $toPerson = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity=Relation::class)
|
|
||||||
* @ORM\JoinColumn(nullable=false, name="relation_id", referencedColumnName="id")
|
|
||||||
* @Assert\NotNull()
|
|
||||||
* @Serializer\Groups({"read", "write"})
|
|
||||||
*/
|
|
||||||
private ?Relation $relation = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="boolean")
|
|
||||||
* @Assert\Type(
|
|
||||||
* type="bool",
|
|
||||||
* message="This must be of type boolean"
|
|
||||||
* )
|
|
||||||
* @Serializer\Groups({"read", "write"})
|
|
||||||
*/
|
|
||||||
private bool $reverse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity=User::class)
|
|
||||||
* @ORM\JoinColumn(nullable=false)
|
|
||||||
*/
|
|
||||||
private ?User $createdBy = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime_immutable")
|
|
||||||
*/
|
|
||||||
private ?DateTimeImmutable $createdAt = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity=User::class)
|
|
||||||
*/
|
|
||||||
private ?User $updatedBy = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ORM\Column(type="datetime_immutable", nullable=true)
|
|
||||||
*/
|
|
||||||
private ?DateTimeImmutable $updatedAt = null;
|
|
||||||
|
|
||||||
|
|
||||||
public function getId(): ?int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFromPerson(): ?Person
|
|
||||||
{
|
|
||||||
return $this->fromPerson;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFromPerson(?Person $fromPerson): self
|
|
||||||
{
|
|
||||||
$this->fromPerson = $fromPerson;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getToPerson(): ?Person
|
|
||||||
{
|
|
||||||
return $this->toPerson;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setToPerson(?Person $toPerson): self
|
|
||||||
{
|
|
||||||
$this->toPerson = $toPerson;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getReverse(): ?bool
|
|
||||||
{
|
|
||||||
return $this->reverse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setReverse(bool $reverse): self
|
|
||||||
{
|
|
||||||
$this->reverse = $reverse;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCreatedBy(): ?User
|
|
||||||
{
|
|
||||||
return $this->createdBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreatedBy(?User $user): self
|
|
||||||
{
|
|
||||||
$this->createdBy = $user;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCreatedAt(): ?\DateTimeImmutable
|
|
||||||
{
|
|
||||||
return $this->createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreatedAt(\DateTimeInterface $createdAt): self
|
|
||||||
{
|
|
||||||
$this->createdAt = $createdAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUpdatedBy(): ?User
|
|
||||||
{
|
|
||||||
return $this->updatedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUpdatedBy(?User $updatedBy): self
|
|
||||||
{
|
|
||||||
$this->updatedBy = $updatedBy;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUpdatedAt(): ?\DateTimeImmutable
|
|
||||||
{
|
|
||||||
return $this->updatedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
|
|
||||||
{
|
|
||||||
$this->updatedAt = $updatedAt;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRelation(): ?Relation
|
|
||||||
{
|
|
||||||
return $this->relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setRelation(?Relation $relation): self
|
|
||||||
{
|
|
||||||
$this->relation = $relation;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -143,8 +143,6 @@ 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');
|
||||||
|
|
||||||
@@ -155,17 +153,15 @@ 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 = [
|
$labels[''] = $this->translator->trans('without data');
|
||||||
'' => $this->translator->trans('without data'),
|
$labels['_header'] = $this->translator->trans('Country of birth');
|
||||||
'_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'),
|
||||||
@@ -174,12 +170,13 @@ 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,8 +144,6 @@ 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');
|
||||||
|
|
||||||
@@ -156,17 +154,15 @@ 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 = [
|
$labels[''] = $this->translator->trans('without data');
|
||||||
'' => $this->translator->trans('without data'),
|
$labels['_header'] = $this->translator->trans('Nationality');
|
||||||
'_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'),
|
||||||
@@ -180,7 +176,8 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(string $value) use ($labels): string {
|
|
||||||
|
return function($value) use ($labels) {
|
||||||
return $labels[$value];
|
return $labels[$value];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@ use Chill\MainBundle\Form\Event\CustomizeFormEvent;
|
|||||||
use Chill\MainBundle\Repository\CenterRepository;
|
use Chill\MainBundle\Repository\CenterRepository;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
@@ -55,18 +54,14 @@ final class CreationPersonType extends AbstractType
|
|||||||
|
|
||||||
private EventDispatcherInterface $dispatcher;
|
private EventDispatcherInterface $dispatcher;
|
||||||
|
|
||||||
private bool $askCenters;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
CenterRepository $centerRepository,
|
CenterRepository $centerRepository,
|
||||||
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
|
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
|
||||||
EventDispatcherInterface $dispatcher,
|
EventDispatcherInterface $dispatcher
|
||||||
ParameterBagInterface $parameterBag
|
|
||||||
) {
|
) {
|
||||||
$this->centerTransformer = $centerRepository;
|
$this->centerTransformer = $centerRepository;
|
||||||
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
|
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->askCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,15 +78,12 @@ final class CreationPersonType extends AbstractType
|
|||||||
])
|
])
|
||||||
->add('gender', GenderType::class, array(
|
->add('gender', GenderType::class, array(
|
||||||
'required' => true, 'placeholder' => null
|
'required' => true, 'placeholder' => null
|
||||||
));
|
))
|
||||||
|
->add('center', PickCenterType::class, [
|
||||||
if ($this->askCenters) {
|
'required' => false,
|
||||||
$builder
|
'role' => PersonVoter::CREATE,
|
||||||
->add('center', PickCenterType::class, [
|
])
|
||||||
'required' => false,
|
;
|
||||||
'role' => PersonVoter::CREATE,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->configPersonAltNamesHelper->hasAltNames()) {
|
if ($this->configPersonAltNamesHelper->hasAltNames()) {
|
||||||
$builder->add('altNames', PersonAltNameType::class, [
|
$builder->add('altNames', PersonAltNameType::class, [
|
||||||
|
@@ -144,10 +144,7 @@ class PersonType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['phonenumber'] === 'visible') {
|
if ($this->config['phonenumber'] === 'visible') {
|
||||||
$builder->add('phonenumber', TelType::class, array(
|
$builder->add('phonenumber', TelType::class, array('required' => false));
|
||||||
'required' => false,
|
|
||||||
// 'placeholder' => '+33623124554' //TODO placeholder for phone numbers
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['mobilenumber'] === 'visible') {
|
if ($this->config['mobilenumber'] === 'visible') {
|
||||||
@@ -170,8 +167,7 @@ class PersonType extends AbstractType
|
|||||||
'delete_empty' => function(PersonPhone $pp = null) {
|
'delete_empty' => function(PersonPhone $pp = null) {
|
||||||
return NULL === $pp || $pp->isEmpty();
|
return NULL === $pp || $pp->isEmpty();
|
||||||
},
|
},
|
||||||
'error_bubbling' => false,
|
'error_bubbling' => false
|
||||||
'empty_collection_explain' => 'No additional phone numbers'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($this->config['email'] === 'visible') {
|
if ($this->config['email'] === 'visible') {
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Repository\Household;
|
namespace Chill\PersonBundle\Repository\Household;
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
use Chill\PersonBundle\Entity\Household\HouseholdMembers;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
@@ -14,6 +12,6 @@ final class HouseholdMembersRepository
|
|||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
public function __construct(EntityManagerInterface $entityManager)
|
||||||
{
|
{
|
||||||
$this->repository = $entityManager->getRepository(HouseholdMember::class);
|
$this->repository = $entityManager->getRepository(HouseholdMembers::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Repository\Relationships;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
|
||||||
|
|
||||||
class RelationRepository implements ObjectRepository
|
|
||||||
{
|
|
||||||
private EntityRepository $repository;
|
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
|
||||||
{
|
|
||||||
$this->repository = $entityManager->getRepository(Relation::class);
|
|
||||||
}
|
|
||||||
public function find($id): ?Relation
|
|
||||||
{
|
|
||||||
return $this->repository->find($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findAll(): array
|
|
||||||
{
|
|
||||||
return $this->repository->findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
|
||||||
{
|
|
||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findOneBy(array $criteria): ?Relation
|
|
||||||
{
|
|
||||||
return $this->findOneBy($criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClassName(): string
|
|
||||||
{
|
|
||||||
return Relation::class;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Repository\Relationships;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
|
||||||
|
|
||||||
class RelationshipRepository implements ObjectRepository
|
|
||||||
{
|
|
||||||
private EntityRepository $repository;
|
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
|
||||||
{
|
|
||||||
$this->repository = $em->getRepository(Relationship::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find($id): ?Relationship
|
|
||||||
{
|
|
||||||
return $this->repository->find($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findAll(): array
|
|
||||||
{
|
|
||||||
return $this->repository->findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
|
|
||||||
{
|
|
||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findOneBy(array $criteria): ?Relationship
|
|
||||||
{
|
|
||||||
return $this->findOneBy($criteria);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClassName(): string
|
|
||||||
{
|
|
||||||
return Relationship::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function findByPerson($personId): array
|
|
||||||
{
|
|
||||||
// return all relationships of which person is part? or only where person is the fromPerson?
|
|
||||||
return $this->repository->createQueryBuilder('r')
|
|
||||||
->select('r, t') // entity Relationship
|
|
||||||
->join('r.relation', 't')
|
|
||||||
->where('r.fromPerson = :val')
|
|
||||||
->orWhere('r.toPerson = :val')
|
|
||||||
->setParameter('val', $personId)
|
|
||||||
->getQuery()
|
|
||||||
->getResult()
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,32 @@
|
|||||||
|
import vis from 'vis-network/dist/vis-network.min';
|
||||||
|
|
||||||
|
require('./scss/vis.scss');
|
||||||
|
|
||||||
|
// create an array with nodes
|
||||||
|
let nodes = new vis.DataSet([
|
||||||
|
{ id: 1, label: "Node 1" },
|
||||||
|
{ id: 2, label: "Node 2" },
|
||||||
|
{ id: 3, label: "Node 3" },
|
||||||
|
{ id: 4, label: "Node 4" },
|
||||||
|
{ id: 5, label: "Node 5", cid: 1 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
// create an array with edges
|
||||||
|
let edges = new vis.DataSet([
|
||||||
|
{ from: 1, to: 3 },
|
||||||
|
{ from: 1, to: 2 },
|
||||||
|
{ from: 2, to: 4 },
|
||||||
|
{ from: 2, to: 5 },
|
||||||
|
{ from: 3, to: 3 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
// create a network
|
||||||
|
let container = document.getElementById("graph-relationship");
|
||||||
|
let data = {
|
||||||
|
nodes: nodes,
|
||||||
|
edges: edges,
|
||||||
|
};
|
||||||
|
let options = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
let network = new vis.Network(container, data, options);
|
@@ -0,0 +1,5 @@
|
|||||||
|
div#graph-relationship {
|
||||||
|
margin: 2em auto;
|
||||||
|
height: 500px;
|
||||||
|
border: 1px solid lightgray;
|
||||||
|
}
|
@@ -16,15 +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" v-bind:key="error.id" class="vue-component errors alert alert-danger">
|
<div v-for="error in errorMsg" 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 { mapGetters, mapState } from 'vuex'
|
import { 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';
|
||||||
@@ -54,12 +55,11 @@ export default {
|
|||||||
Comment,
|
Comment,
|
||||||
Confirm,
|
Confirm,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: mapState([
|
||||||
...mapState([
|
'accompanyingCourse',
|
||||||
'accompanyingCourse',
|
'addressContext',
|
||||||
'addressContext'
|
'errorMsg'
|
||||||
]),
|
])
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@@ -86,8 +86,7 @@ const postParticipation = (id, payload, method) => {
|
|||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
// 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 };
|
||||||
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"
|
||||||
:custom-label="transText"
|
v-bind:custom-label="transText"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
:multiple="false"
|
v-bind:multiple="false"
|
||||||
:searchable="true"
|
v-bind:searchable="true"
|
||||||
:placeholder="$t('origin.placeholder')"
|
v-bind:placeholder="$t('origin.placeholder')"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="options"
|
v-bind: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 }) {
|
||||||
const parsedText = JSON.parse(text);
|
return text.fr //TODO multilang
|
||||||
return parsedText.fr;
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,6 @@ 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';
|
||||||
@@ -23,7 +21,6 @@ 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">
|
||||||
<i class="fa fa-circle-o-notch fa-spin fa-fw"></i>
|
<p>spinner</p>
|
||||||
</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('action.save') }}
|
{{ $t('Save') }}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -1,508 +0,0 @@
|
|||||||
<template>
|
|
||||||
|
|
||||||
<div id="visgraph"></div>
|
|
||||||
|
|
||||||
<teleport to="#visgraph-legend">
|
|
||||||
<div class="post-menu">
|
|
||||||
<div class="list-group mt-4">
|
|
||||||
<button type="button" class="list-group-item list-group-item-action btn btn-create" @click="createRelationship">
|
|
||||||
{{ $t('visgraph.add_link') }}
|
|
||||||
</button>
|
|
||||||
<a type="button" class="list-group-item list-group-item-action btn btn-misc" id="exportCanvasBtn" @click="exportCanvasAsImage">
|
|
||||||
<i class="fa fa-camera fa-fw"></i> {{ $t('visgraph.screenshot') }}
|
|
||||||
</a>
|
|
||||||
<button type="button" class="list-group-item list-group-item-action btn btn-light" @click="refreshNetwork">
|
|
||||||
<i class="fa fa-refresh fa-fw"></i> {{ $t('visgraph.refresh') }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="displayHelpMessage" class="alert alert-info mt-3">
|
|
||||||
{{ $t('visgraph.create_link_help') }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="my-4 legend">
|
|
||||||
<h3>{{ $t('visgraph.Legend') }}</h3>
|
|
||||||
<div class="list-group">
|
|
||||||
<label class="list-group-item" v-for="layer in legendLayers">
|
|
||||||
<input
|
|
||||||
class="form-check-input me-1"
|
|
||||||
type="checkbox"
|
|
||||||
:value="layer.id"
|
|
||||||
v-model="checkedLayers"
|
|
||||||
@change="toggleLayer"
|
|
||||||
/>
|
|
||||||
{{ layer.label }}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</teleport>
|
|
||||||
|
|
||||||
<teleport to="body">
|
|
||||||
<modal v-if="modal.showModal" :modalDialogClass="modal.modalDialogClass" @close="modal.showModal = false">
|
|
||||||
<template v-slot:header>
|
|
||||||
<h2 class="modal-title">{{ $t(modal.title) }}</h2>
|
|
||||||
<!-- {{ modal.data.id }} -->
|
|
||||||
</template>
|
|
||||||
<template v-slot:body>
|
|
||||||
<div v-if="modal.action === 'delete'">
|
|
||||||
<p>{{ $t('visgraph.delete_confirmation_text') }}</p>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<form>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12 text-center">{{ $t('visgraph.between') }}<br>{{ $t('visgraph.and') }}</div>
|
|
||||||
<div class="col">
|
|
||||||
<h4>{{ getPerson(modal.data.from).text }}</h4>
|
|
||||||
<p class="text-start" v-if="relation && relation.title">
|
|
||||||
<span v-if="reverse">
|
|
||||||
{{ $t('visgraph.relation_from_to_like', [ getPerson(modal.data.from).text, getPerson(modal.data.to).text, relation.reverseTitle.fr.toLowerCase() ])}}
|
|
||||||
</span>
|
|
||||||
<span v-else>
|
|
||||||
{{ $t('visgraph.relation_from_to_like', [ getPerson(modal.data.from).text, getPerson(modal.data.to).text, relation.title.fr.toLowerCase() ])}}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="col text-end">
|
|
||||||
<h4>{{ getPerson(modal.data.to).text }}</h4>
|
|
||||||
<p class="text-end" v-if="relation && relation.title">
|
|
||||||
<span v-if="reverse">
|
|
||||||
{{ $t('visgraph.relation_from_to_like', [ getPerson(modal.data.to).text, getPerson(modal.data.from).text, relation.title.fr.toLowerCase() ])}}
|
|
||||||
</span>
|
|
||||||
<span v-else>
|
|
||||||
{{ $t('visgraph.relation_from_to_like', [ getPerson(modal.data.to).text, getPerson(modal.data.from).text, relation.reverseTitle.fr.toLowerCase() ])}}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="my-3">
|
|
||||||
<VueMultiselect
|
|
||||||
id="relation"
|
|
||||||
label="title"
|
|
||||||
track-by="id"
|
|
||||||
:custom-label="customLabel"
|
|
||||||
:placeholder="$t('visgraph.choose_relation')"
|
|
||||||
:close-on-select="true"
|
|
||||||
:multiple="false"
|
|
||||||
:searchable="true"
|
|
||||||
:options="relations"
|
|
||||||
v-model="relation"
|
|
||||||
:value="relation"
|
|
||||||
>
|
|
||||||
</VueMultiselect>
|
|
||||||
</div>
|
|
||||||
<div class="form-check form-switch">
|
|
||||||
<input
|
|
||||||
class="form-check-input"
|
|
||||||
type="checkbox"
|
|
||||||
id="reverse"
|
|
||||||
v-model="reverse"
|
|
||||||
>
|
|
||||||
<label class="form-check-label" for="reverse">{{ $t('visgraph.reverse_relation') }}</label>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<template v-slot:footer>
|
|
||||||
<button class="btn" :class="modal.button.class" @click="submitRelationship">
|
|
||||||
{{ $t(modal.button.text)}}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-delete" v-if="modal.action === 'edit'" @click="dropRelationship"></button>
|
|
||||||
</template>
|
|
||||||
</modal>
|
|
||||||
</teleport>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import vis from 'vis-network/dist/vis-network'
|
|
||||||
import { mapState, mapGetters } from "vuex"
|
|
||||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal'
|
|
||||||
import VueMultiselect from 'vue-multiselect'
|
|
||||||
import { getRelationsList, postRelationship, patchRelationship, deleteRelationship } from "./api";
|
|
||||||
import { splitId } from "./vis-network";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: "App",
|
|
||||||
components: {
|
|
||||||
Modal,
|
|
||||||
VueMultiselect
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
container: '',
|
|
||||||
checkedLayers: [],
|
|
||||||
relations: [],
|
|
||||||
displayHelpMessage: false,
|
|
||||||
listenPersonFlag: 'normal',
|
|
||||||
newEdgeData: {},
|
|
||||||
modal: {
|
|
||||||
showModal: false,
|
|
||||||
modalDialogClass: "modal-md",
|
|
||||||
title: null,
|
|
||||||
action: null,
|
|
||||||
data: {
|
|
||||||
type: 'relationship',
|
|
||||||
from: null,
|
|
||||||
to: null,
|
|
||||||
relation: null,
|
|
||||||
reverse: false
|
|
||||||
},
|
|
||||||
button: {
|
|
||||||
class: null,
|
|
||||||
text: null
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapGetters(['nodes', 'edges',
|
|
||||||
// not used 'isInWhitelist', 'isHouseholdLoading', 'isCourseLoaded', 'isRelationshipLoaded', 'isPersonLoaded', 'isExcludedNode', 'countLinksByNode', 'getParticipationsByCourse', 'getMembersByHousehold', 'getPersonsGroup',
|
|
||||||
]),
|
|
||||||
...mapState(['persons', 'households', 'courses', 'excludedNodesIds', 'updateHack',
|
|
||||||
// not used 'links', 'relationships', 'whitelistIds', 'personLoadedIds', 'householdLoadingIds', 'courseLoadedIds', 'relationshipLoadedIds',
|
|
||||||
]),
|
|
||||||
|
|
||||||
visgraph_data() {
|
|
||||||
console.log('::: visgraph_data :::', this.nodes.length, 'nodes,', this.edges.length, 'edges')
|
|
||||||
return {
|
|
||||||
nodes: this.nodes,
|
|
||||||
edges: this.edges
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
refreshNetwork() {
|
|
||||||
console.log('--- refresh network')
|
|
||||||
window.network.setData(this.visgraph_data)
|
|
||||||
},
|
|
||||||
|
|
||||||
legendLayers() {
|
|
||||||
console.log('--- refresh legend and rebuild checked Layers')
|
|
||||||
this.checkedLayers = []
|
|
||||||
let layersDisplayed = [
|
|
||||||
...this.nodes.filter(n => n.id.startsWith('household')),
|
|
||||||
...this.nodes.filter(n => n.id.startsWith('accompanying'))
|
|
||||||
]
|
|
||||||
layersDisplayed.forEach(layer => {
|
|
||||||
this.checkedLayers.push(layer.id)
|
|
||||||
})
|
|
||||||
return [
|
|
||||||
...this.households,
|
|
||||||
...this.courses
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
checkedLayers() { // required to refresh data checkedLayers
|
|
||||||
console.log('--- checkedLayers')
|
|
||||||
return this.checkedLayers
|
|
||||||
},
|
|
||||||
|
|
||||||
relation: {
|
|
||||||
get() {
|
|
||||||
return this.modal.data.relation
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
this.modal.data.relation = value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
reverse: {
|
|
||||||
get() {
|
|
||||||
return this.modal.data.reverse
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
this.modal.data.reverse = value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
updateHack(newValue, oldValue) {
|
|
||||||
console.log(`--- updateHack ${oldValue} <> ${newValue}`)
|
|
||||||
if (oldValue !== newValue) {
|
|
||||||
this.forceUpdateComponent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
//console.log('=== mounted: init graph')
|
|
||||||
this.initGraph()
|
|
||||||
this.listenOnGraph()
|
|
||||||
this.getRelationsList()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
|
|
||||||
initGraph() {
|
|
||||||
this.container = document.getElementById('visgraph')
|
|
||||||
// Instanciate vis objects in separate window variables, see vis-network.js
|
|
||||||
window.network = new vis.Network(this.container, this.visgraph_data, window.options)
|
|
||||||
},
|
|
||||||
forceUpdateComponent() {
|
|
||||||
//console.log('!! forceUpdateComponent !!')
|
|
||||||
this.refreshNetwork
|
|
||||||
this.$forceUpdate()
|
|
||||||
},
|
|
||||||
|
|
||||||
// events
|
|
||||||
listenOnGraph() {
|
|
||||||
window.network.on('selectNode', (data) => {
|
|
||||||
if (data.nodes.length > 1) {
|
|
||||||
throw 'Multi selection is not allowed. Disable it in options.interaction !'
|
|
||||||
}
|
|
||||||
let node = data.nodes[0]
|
|
||||||
let nodeType = splitId(node, 'type')
|
|
||||||
switch (nodeType) {
|
|
||||||
|
|
||||||
case 'person':
|
|
||||||
let person = this.nodes.filter(n => n.id === node)[0]
|
|
||||||
console.log('@@@@@@ event on selected Node', person.id)
|
|
||||||
if (this.listenPersonFlag === 'normal') {
|
|
||||||
if (person.folded === true) {
|
|
||||||
console.log(' @@> expand mode event')
|
|
||||||
this.$store.commit('unfoldPerson', person)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(' @@> create link mode event')
|
|
||||||
this.listenStepsToAddRelationship(person)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'household':
|
|
||||||
let household = this.nodes.filter(n => n.id === node)[0]
|
|
||||||
console.log('@@@@@@ event on selected Node', household.id)
|
|
||||||
this.$store.dispatch('unfoldPersonsByHousehold', household)
|
|
||||||
break
|
|
||||||
|
|
||||||
case 'accompanying_period':
|
|
||||||
let course = this.nodes.filter(n => n.id === node)[0]
|
|
||||||
console.log('@@@@@@ event on selected Node', course.id)
|
|
||||||
this.$store.dispatch('unfoldPersonsByCourse', course)
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw 'event is undefined for this type of node'
|
|
||||||
}
|
|
||||||
this.forceUpdateComponent()
|
|
||||||
})
|
|
||||||
window.network.on('selectEdge', (data) => {
|
|
||||||
if (data.nodes.length !== 0 || data.edges.length !== 1) {
|
|
||||||
return false //we don't want to trigger nodeEdge or multiselect !
|
|
||||||
}
|
|
||||||
let link = data.edges[0]
|
|
||||||
let linkType = splitId(link, 'link')
|
|
||||||
console.log('@@@@@ event on selected Edge', data.edges.length, linkType, data)
|
|
||||||
|
|
||||||
if (linkType.startsWith('relationship')) {
|
|
||||||
//console.log('linkType relationship')
|
|
||||||
|
|
||||||
let relationships = this.edges.filter(l => l.id === link)
|
|
||||||
if (relationships.length > 1) {
|
|
||||||
throw 'error: only one link is allowed between two person!'
|
|
||||||
}
|
|
||||||
|
|
||||||
let relationship = relationships[0]
|
|
||||||
//console.log(relationship)
|
|
||||||
|
|
||||||
this.editRelationshipModal({
|
|
||||||
from: relationship.from,
|
|
||||||
to: relationship.to,
|
|
||||||
id: relationship.id,
|
|
||||||
relation: relationship.relation,
|
|
||||||
reverse: relationship.reverse
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
listenStepsToAddRelationship(person) {
|
|
||||||
console.log(' @@> listenStep', this.listenPersonFlag)
|
|
||||||
if (this.listenPersonFlag === 'step2') {
|
|
||||||
//console.log(' @@> person 2', person)
|
|
||||||
this.newEdgeData.to = person.id
|
|
||||||
this.addRelationshipModal(this.newEdgeData)
|
|
||||||
this.displayHelpMessage = false
|
|
||||||
this.listenPersonFlag = 'normal'
|
|
||||||
this.newEdgeData = {}
|
|
||||||
}
|
|
||||||
if (this.listenPersonFlag === 'step1') {
|
|
||||||
//console.log(' @@> person 1', person)
|
|
||||||
this.newEdgeData.from = person.id
|
|
||||||
this.listenPersonFlag = 'step2'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/// control Layers
|
|
||||||
toggleLayer(value) {
|
|
||||||
let id = value.target.value
|
|
||||||
console.log('@@@@@@ toggle Layer', id)
|
|
||||||
this.forceUpdateComponent()
|
|
||||||
if (this.checkedLayers.includes(id)) {
|
|
||||||
this.removeLayer(id)
|
|
||||||
} else {
|
|
||||||
this.addLayer(id)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addLayer(id) {
|
|
||||||
//console.log('+ addLayer', id)
|
|
||||||
this.checkedLayers.push(id)
|
|
||||||
this.$store.dispatch('excludedNode', ['remove', id])
|
|
||||||
},
|
|
||||||
removeLayer(id) {
|
|
||||||
//console.log('- removeLayer', id)
|
|
||||||
this.checkedLayers = this.checkedLayers.filter(i => i !== id)
|
|
||||||
this.$store.dispatch('excludedNode', ['add', id])
|
|
||||||
},
|
|
||||||
|
|
||||||
/// control Modal
|
|
||||||
addRelationshipModal(edgeData) {
|
|
||||||
//console.log('==- addRelationshipModal', edgeData)
|
|
||||||
this.modal = {
|
|
||||||
data: { from: edgeData.from, to: edgeData.to },
|
|
||||||
action: 'create',
|
|
||||||
showModal: true,
|
|
||||||
title: 'visgraph.add_relationship_link',
|
|
||||||
button: { class: 'btn-create', text: 'action.create' }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
editRelationshipModal(edgeData) {
|
|
||||||
//console.log('==- editRelationshipModal', edgeData)
|
|
||||||
this.modal = {
|
|
||||||
data: edgeData,
|
|
||||||
action: 'edit',
|
|
||||||
showModal: true,
|
|
||||||
title: 'visgraph.edit_relationship_link',
|
|
||||||
button: { class: 'btn-edit', text: 'action.edit' }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// form
|
|
||||||
resetForm() {
|
|
||||||
this.modal = {
|
|
||||||
data: { type: 'relationship', from: null, to: null, relation: null, reverse: false },
|
|
||||||
action: null,
|
|
||||||
title: null,
|
|
||||||
button: { class: null, text: null, }
|
|
||||||
}
|
|
||||||
console.log('==- reset Form', this.modal.data)
|
|
||||||
},
|
|
||||||
getRelationsList() {
|
|
||||||
//console.log('fetch relationsList')
|
|
||||||
return getRelationsList().then(relations => new Promise(resolve => {
|
|
||||||
//console.log('+ relations list', relations.results.length)
|
|
||||||
this.relations = relations.results.filter(r => r.isActive === true)
|
|
||||||
resolve()
|
|
||||||
})).catch()
|
|
||||||
},
|
|
||||||
customLabel(value) {
|
|
||||||
//console.log('customLabel', value)
|
|
||||||
return (value.title && value.reverseTitle) ? `${value.title.fr} ↔ ${value.reverseTitle.fr}` : ''
|
|
||||||
},
|
|
||||||
getPerson(id) {
|
|
||||||
let person = this.persons.filter(p => p.id === id)
|
|
||||||
return person[0]
|
|
||||||
},
|
|
||||||
|
|
||||||
// actions
|
|
||||||
createRelationship() {
|
|
||||||
this.displayHelpMessage = true
|
|
||||||
this.listenPersonFlag = 'step1' // toggle listener in create link mode
|
|
||||||
console.log(' @@> switch listener to create link mode:', this.listenPersonFlag)
|
|
||||||
},
|
|
||||||
dropRelationship() {
|
|
||||||
//console.log('delete', this.modal.data)
|
|
||||||
deleteRelationship(this.modal.data)
|
|
||||||
.catch()
|
|
||||||
this.$store.commit('removeLink', this.modal.data.id)
|
|
||||||
this.modal.showModal = false
|
|
||||||
this.resetForm()
|
|
||||||
},
|
|
||||||
submitRelationship() {
|
|
||||||
console.log('submitRelationship', this.modal.action)
|
|
||||||
switch (this.modal.action) {
|
|
||||||
|
|
||||||
case 'create':
|
|
||||||
return postRelationship(this.modal.data)
|
|
||||||
.then(relationship => new Promise(resolve => {
|
|
||||||
console.log('post relationship response', relationship)
|
|
||||||
this.$store.dispatch('addLinkFromRelationship', relationship)
|
|
||||||
this.modal.showModal = false
|
|
||||||
this.resetForm()
|
|
||||||
resolve()
|
|
||||||
}))
|
|
||||||
.catch()
|
|
||||||
|
|
||||||
case 'edit':
|
|
||||||
return patchRelationship(this.modal.data)
|
|
||||||
.then(relationship => new Promise(resolve => {
|
|
||||||
console.log('patch relationship response', relationship)
|
|
||||||
this.$store.commit('updateLink', relationship)
|
|
||||||
this.modal.showModal = false
|
|
||||||
this.resetForm()
|
|
||||||
resolve()
|
|
||||||
}))
|
|
||||||
.catch()
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw "uncaught action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// export image
|
|
||||||
exportCanvasAsImage() {
|
|
||||||
const canvas = document.getElementById('visgraph')
|
|
||||||
.querySelector('canvas')
|
|
||||||
console.log(canvas)
|
|
||||||
|
|
||||||
let link = document.getElementById('exportCanvasBtn')
|
|
||||||
link.download = "filiation.png"
|
|
||||||
|
|
||||||
canvas.toBlob(blob => {
|
|
||||||
console.log(blob)
|
|
||||||
link.href = URL.createObjectURL(blob)
|
|
||||||
}, 'image/png')
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO improve feature
|
|
||||||
|
|
||||||
// 1. fonctionne, mais pas de contrôle sur le nom
|
|
||||||
if (canvas && canvas.getContext('2d')) {
|
|
||||||
let img = canvas.toDataURL('image/png;base64;')
|
|
||||||
img = img.replace('image/png','image/octet-stream')
|
|
||||||
window.open(img, '', 'width=1000, height=1000')
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. fonctionne, mais 2 click et pas compatible avec tous les browsers
|
|
||||||
let link = document.getElementById('exportCanvasBtn')
|
|
||||||
link.download = "image.png"
|
|
||||||
canvas.toBlob(blob => {
|
|
||||||
link.href = URL.createObjectURL(blob)
|
|
||||||
}, 'image/png')
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style src="vis-network/dist/dist/vis-network.min.css"></style>
|
|
||||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
div#visgraph {
|
|
||||||
height: 700px;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
div#visgraph-legend {
|
|
||||||
div.post-menu.legend {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.modal-mask {
|
|
||||||
background-color: rgba(0, 0, 0, 0.25);
|
|
||||||
}
|
|
||||||
.debug {
|
|
||||||
margin: 1em; padding: 1em;
|
|
||||||
color: dimgray;
|
|
||||||
font-style: italic;
|
|
||||||
font-size: 80%;
|
|
||||||
}
|
|
||||||
</style>
|
|
@@ -1,195 +0,0 @@
|
|||||||
import { splitId } from './vis-network'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function makeFetch
|
|
||||||
* @param method
|
|
||||||
* @param url
|
|
||||||
* @param body
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const makeFetch = (method, url, body) => {
|
|
||||||
return fetch(url, {
|
|
||||||
method: method,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json;charset=utf-8'
|
|
||||||
},
|
|
||||||
body: (body !== null) ? JSON.stringify(body) : null
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.status === 422) {
|
|
||||||
return response.json().then(violations => {
|
|
||||||
throw ValidationException(violations)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
throw {
|
|
||||||
msg: 'Error while updating AccompanyingPeriod Course.',
|
|
||||||
sta: response.status,
|
|
||||||
txt: response.statusText,
|
|
||||||
err: new Error(),
|
|
||||||
body: response.body
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param violations
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
const ValidationException = (violations) => {
|
|
||||||
this.violations = violations
|
|
||||||
this.name = 'ValidationException'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function getFetch
|
|
||||||
* @param url
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const getFetch = (url) => {
|
|
||||||
return makeFetch('GET', url, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function postFetch
|
|
||||||
* @param url
|
|
||||||
* @param body
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const postFetch = (url, body) => {
|
|
||||||
return makeFetch('POST', url, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function patchFetch
|
|
||||||
* @param url
|
|
||||||
* @param body
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const patchFetch = (url, body) => {
|
|
||||||
return makeFetch('PATCH', url, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function deleteFetch
|
|
||||||
* @param url
|
|
||||||
* @param body
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const deleteFetch = (url, body) => {
|
|
||||||
return makeFetch('DELETE', url, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function getHouseholdByPerson
|
|
||||||
* @param person
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const getHouseholdByPerson = (person) => {
|
|
||||||
//console.log('getHouseholdByPerson', person.id)
|
|
||||||
if (person.current_household_id === null) {
|
|
||||||
throw 'Currently the person has not household!'
|
|
||||||
}
|
|
||||||
return getFetch(
|
|
||||||
`/api/1.0/person/household/${person.current_household_id}.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function getCoursesByPerson
|
|
||||||
* @param person
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const getCoursesByPerson = (person) => {
|
|
||||||
//console.log('getCoursesByPerson', person._id)
|
|
||||||
return getFetch(
|
|
||||||
`/api/1.0/person/accompanying-course/by-person/${person._id}.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function getRelationshipsByPerson
|
|
||||||
* @param person
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const getRelationshipsByPerson = (person) => {
|
|
||||||
//console.log('getRelationshipsByPerson', person.id)
|
|
||||||
return getFetch(
|
|
||||||
`/api/1.0/relations/relationship/by-person/${person._id}.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return list of relations
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const getRelationsList = () => {
|
|
||||||
return getFetch(`/api/1.0/relations/relation.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function postRelationship
|
|
||||||
* @param relationship
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const postRelationship = (relationship) => {
|
|
||||||
//console.log(relationship)
|
|
||||||
return postFetch(
|
|
||||||
`/api/1.0/relations/relationship.json`,
|
|
||||||
{
|
|
||||||
type: 'relationship',
|
|
||||||
fromPerson: { type: 'person', id: splitId(relationship.from, 'id') },
|
|
||||||
toPerson: { type: 'person', id: splitId(relationship.to, 'id') },
|
|
||||||
relation: { type: 'relation', id: relationship.relation.id },
|
|
||||||
reverse: relationship.reverse
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function patchRelationship
|
|
||||||
* @param relationship
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const patchRelationship = (relationship) => {
|
|
||||||
//console.log(relationship)
|
|
||||||
let linkType = splitId(relationship.id, 'link')
|
|
||||||
let id = splitId(linkType, 'id')
|
|
||||||
return patchFetch(
|
|
||||||
`/api/1.0/relations/relationship/${id}.json`,
|
|
||||||
{
|
|
||||||
type: 'relationship',
|
|
||||||
fromPerson: { type: 'person', id: splitId(relationship.from, 'id') },
|
|
||||||
toPerson: { type: 'person', id: splitId(relationship.to, 'id') },
|
|
||||||
relation: { type: 'relation', id: relationship.relation.id },
|
|
||||||
reverse: relationship.reverse
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @function deleteRelationship
|
|
||||||
* @param relationship
|
|
||||||
* @returns {Promise<Response>}
|
|
||||||
*/
|
|
||||||
const deleteRelationship = (relationship) => {
|
|
||||||
//console.log(relationship)
|
|
||||||
let linkType = splitId(relationship.id, 'link')
|
|
||||||
let id = splitId(linkType, 'id')
|
|
||||||
return deleteFetch(
|
|
||||||
`/api/1.0/relations/relationship/${id}.json`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
getHouseholdByPerson,
|
|
||||||
getCoursesByPerson,
|
|
||||||
getRelationshipsByPerson,
|
|
||||||
getRelationsList,
|
|
||||||
postRelationship,
|
|
||||||
patchRelationship,
|
|
||||||
deleteRelationship
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
const visMessages = {
|
|
||||||
fr: {
|
|
||||||
visgraph: {
|
|
||||||
Course: 'Parcours',
|
|
||||||
Household: 'Ménage',
|
|
||||||
Holder: 'Titulaire',
|
|
||||||
Legend: 'Calques',
|
|
||||||
concerned: 'concerné',
|
|
||||||
both: 'neutre, non binaire',
|
|
||||||
woman: 'féminin',
|
|
||||||
man: 'masculin',
|
|
||||||
years: 'ans',
|
|
||||||
click_to_expand: 'cliquez pour étendre',
|
|
||||||
add_relationship_link: "Créer un lien de filiation",
|
|
||||||
edit_relationship_link: "Modifier le lien de filiation",
|
|
||||||
delete_relationship_link: "Êtes-vous sûr ?",
|
|
||||||
delete_confirmation_text: "Vous allez supprimer le lien entre ces 2 usagers.",
|
|
||||||
reverse_relation: "Inverser la relation",
|
|
||||||
relation_from_to_like: "{2} de {1}", // disable {0}
|
|
||||||
between: "entre",
|
|
||||||
and: "et",
|
|
||||||
add_link: "Créer un lien de filiation",
|
|
||||||
create_link_help: "Pour créer un lien de filiation, cliquez d'abord sur un usager, puis sur un second ; précisez ensuite la nature du lien dans le formulaire d'édition.",
|
|
||||||
refresh: "Rafraîchir",
|
|
||||||
screenshot: "Prendre une photo",
|
|
||||||
choose_relation: "Choisissez le lien de parenté",
|
|
||||||
},
|
|
||||||
edit: 'Éditer',
|
|
||||||
del: 'Supprimer',
|
|
||||||
back: 'Revenir en arrière',
|
|
||||||
addNode: 'Ajouter un noeuds',
|
|
||||||
addEdge: 'Ajouter un lien de filiation',
|
|
||||||
editNode: 'Éditer le noeuds',
|
|
||||||
editEdge: 'Éditer le lien',
|
|
||||||
addDescription: 'Cliquez dans un espace vide pour créer un nouveau nœud.',
|
|
||||||
edgeDescription: 'Cliquez sur un usager et faites glisser le lien vers un autre usager pour les connecter.',
|
|
||||||
editEdgeDescription: 'Cliquez sur les points de contrôle et faites-les glisser vers un nœud pour les relier.',
|
|
||||||
createEdgeError: 'Il est impossible de relier des arêtes à un cluster.',
|
|
||||||
deleteClusterError: 'Les clusters ne peuvent pas être supprimés.',
|
|
||||||
editClusterError: 'Les clusters ne peuvent pas être modifiés.'
|
|
||||||
},
|
|
||||||
en: {
|
|
||||||
edit: 'Edit',
|
|
||||||
del: 'Delete selected',
|
|
||||||
back: 'Back',
|
|
||||||
addNode: 'Add Node',
|
|
||||||
addEdge: 'Add Link',
|
|
||||||
editNode: 'Edit Switch',
|
|
||||||
editEdge: 'Edit Link',
|
|
||||||
addDescription: 'Click in an empty space to place a new node.',
|
|
||||||
edgeDescription: 'Click on a node and drag the link to another node to connect them.',
|
|
||||||
editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.',
|
|
||||||
createEdgeError: 'Cannot link edges to a cluster.',
|
|
||||||
deleteClusterError: 'Clusters cannot be deleted.',
|
|
||||||
editClusterError: 'Clusters cannot be edited.'
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
visMessages
|
|
||||||
}
|
|
@@ -1,24 +0,0 @@
|
|||||||
import { createApp } from "vue"
|
|
||||||
import { store } from "./store.js"
|
|
||||||
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
|
||||||
import { visMessages } from './i18n'
|
|
||||||
import App from './App.vue'
|
|
||||||
|
|
||||||
import './vis-network'
|
|
||||||
|
|
||||||
const i18n = _createI18n(visMessages)
|
|
||||||
const container = document.getElementById('relationship-graph')
|
|
||||||
const persons = JSON.parse(container.dataset.persons)
|
|
||||||
|
|
||||||
persons.forEach(person => {
|
|
||||||
store.dispatch('addPerson', person)
|
|
||||||
store.commit('markInWhitelist', person)
|
|
||||||
})
|
|
||||||
|
|
||||||
const app = createApp({
|
|
||||||
template: `<app></app>`
|
|
||||||
})
|
|
||||||
.use(store)
|
|
||||||
.use(i18n)
|
|
||||||
.component('app', App)
|
|
||||||
.mount('#relationship-graph')
|
|
@@ -1,534 +0,0 @@
|
|||||||
import { createStore } from 'vuex'
|
|
||||||
import { getHouseholdByPerson, getCoursesByPerson, getRelationshipsByPerson } from './api'
|
|
||||||
import { getHouseholdLabel, getHouseholdWidth, getRelationshipLabel, getRelationshipTitle, getRelationshipDirection, splitId, getGender, getAge } from './vis-network'
|
|
||||||
import {visMessages} from "./i18n";
|
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production'
|
|
||||||
|
|
||||||
const store = createStore({
|
|
||||||
strict: debug,
|
|
||||||
state: {
|
|
||||||
persons: [],
|
|
||||||
households: [],
|
|
||||||
courses: [],
|
|
||||||
relationships: [],
|
|
||||||
links: [],
|
|
||||||
whitelistIds: [],
|
|
||||||
personLoadedIds: [],
|
|
||||||
householdLoadingIds: [],
|
|
||||||
courseLoadedIds: [],
|
|
||||||
relationshipLoadedIds: [],
|
|
||||||
excludedNodesIds: [],
|
|
||||||
updateHack: 0
|
|
||||||
},
|
|
||||||
getters: {
|
|
||||||
nodes(state) {
|
|
||||||
let nodes = []
|
|
||||||
state.persons.forEach(p => {
|
|
||||||
nodes.push(p)
|
|
||||||
})
|
|
||||||
state.households.forEach(h => {
|
|
||||||
nodes.push(h)
|
|
||||||
})
|
|
||||||
state.courses.forEach(c => {
|
|
||||||
nodes.push(c)
|
|
||||||
})
|
|
||||||
// except excluded nodes (unchecked layers)
|
|
||||||
state.excludedNodesIds.forEach(excluded => {
|
|
||||||
nodes = nodes.filter(n => n.id !== excluded)
|
|
||||||
})
|
|
||||||
return nodes
|
|
||||||
},
|
|
||||||
edges(state) {
|
|
||||||
return state.links
|
|
||||||
},
|
|
||||||
isInWhitelist: (state) => (person_id) => {
|
|
||||||
return state.whitelistIds.includes(person_id)
|
|
||||||
},
|
|
||||||
isHouseholdLoading: (state) => (household_id) => {
|
|
||||||
return state.householdLoadingIds.includes(household_id)
|
|
||||||
},
|
|
||||||
isCourseLoaded: (state) => (course_id) => {
|
|
||||||
return state.courseLoadedIds.includes(course_id)
|
|
||||||
},
|
|
||||||
isRelationshipLoaded: (state) => (relationship_id) => {
|
|
||||||
return state.relationshipLoadedIds.includes(relationship_id)
|
|
||||||
},
|
|
||||||
isPersonLoaded: (state) => (person_id) => {
|
|
||||||
return state.personLoadedIds.includes(person_id)
|
|
||||||
},
|
|
||||||
isExcludedNode: (state) => (id) => {
|
|
||||||
return state.excludedNodesIds.includes(id)
|
|
||||||
},
|
|
||||||
|
|
||||||
countLinksByNode: (state) => (node_id) => {
|
|
||||||
let array = []
|
|
||||||
state.links.filter(link => ! link.id.startsWith('relationship'))
|
|
||||||
.forEach(link => {
|
|
||||||
if (link.from === node_id || link.to === node_id) {
|
|
||||||
if (state.excludedNodesIds.indexOf(splitId(link.id, 'link')) === -1) {
|
|
||||||
array.push(link)
|
|
||||||
}
|
|
||||||
//console.log(link.id, state.excludedNodesIds.indexOf(splitId(link.id, 'link')))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//console.log('count links', array.length, array.map(i => i.id))
|
|
||||||
return array.length
|
|
||||||
},
|
|
||||||
|
|
||||||
getParticipationsByCourse: (state) => (course_id) => {
|
|
||||||
const course = state.courses.filter(c => c.id === course_id)[0]
|
|
||||||
const currentParticipations = course.participations.filter(p => p.endDate === null)
|
|
||||||
//console.log('get persons in', course_id, currentParticipations.map(p => p.person.id),
|
|
||||||
// 'with folded', currentParticipations.filter(p => p.person.folded === true).map(p => p.person.id))
|
|
||||||
return currentParticipations
|
|
||||||
},
|
|
||||||
|
|
||||||
getMembersByHousehold: (state) => (household_id) => {
|
|
||||||
const household = state.households.filter(h => h.id === household_id)[0]
|
|
||||||
const currentMembers = household.members.filter(m => household.current_members_id.includes(m.id))
|
|
||||||
//console.log('get persons in', household_id, currentMembers.map(m => m.person.id),
|
|
||||||
// 'with folded', currentMembers.filter(m => m.person.folded === true).map(m => m.person.id))
|
|
||||||
return currentMembers
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This getter is a little bit mysterious :
|
|
||||||
* The 2 previous getters return complete array, but folded (missing) persons are not taken into consideration and are not displayed (!?!)
|
|
||||||
* This getter compare input array (participations|members) to personLoadedIds array
|
|
||||||
* and return complete array with folded persons taken into consideration
|
|
||||||
*
|
|
||||||
* @param state
|
|
||||||
* @param array - An array of persons from course or household.
|
|
||||||
* This array is dirty, melting persons adapted (or not) to vis, with _id and _label.
|
|
||||||
* @return array - An array of persons mapped and taken in state.persons
|
|
||||||
*/
|
|
||||||
getPersonsGroup: (state) => (array) => {
|
|
||||||
let group = []
|
|
||||||
array.forEach(item => {
|
|
||||||
let id = splitId(item.person.id, 'id')
|
|
||||||
if (state.personLoadedIds.includes(id)) {
|
|
||||||
group.push(state.persons.filter(person => person._id === id)[0])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//console.log('array', array.map(item => item.person.id))
|
|
||||||
console.log('get persons group', group.map(f => f.id))
|
|
||||||
return group
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
addPerson(state, [person, options]) {
|
|
||||||
let debug = ''
|
|
||||||
/// Debug mode: uncomment to display person_id on visgraph
|
|
||||||
//debug = `\nid ${person.id}`
|
|
||||||
person.group = person.type
|
|
||||||
person._id = person.id
|
|
||||||
person.id = `person_${person.id}`
|
|
||||||
person.label = `*${person.text}*\n_${getGender(person.gender)} - ${getAge(person.birthdate)}_${debug}` //
|
|
||||||
person.folded = false
|
|
||||||
// folded is used for missing persons
|
|
||||||
if (options.folded) {
|
|
||||||
person.title = visMessages.fr.visgraph.click_to_expand
|
|
||||||
person._label = person.label // keep label
|
|
||||||
person.label = null
|
|
||||||
person.folded = true
|
|
||||||
}
|
|
||||||
state.persons.push(person)
|
|
||||||
},
|
|
||||||
addHousehold(state, household) {
|
|
||||||
household.group = household.type
|
|
||||||
household._id = household.id
|
|
||||||
household.label = `${visMessages.fr.visgraph.Household} n° ${household.id}`
|
|
||||||
household.id = `household_${household.id}`
|
|
||||||
state.households.push(household)
|
|
||||||
},
|
|
||||||
addCourse(state, course) {
|
|
||||||
course.group = course.type
|
|
||||||
course._id = course.id
|
|
||||||
course.label = `${visMessages.fr.visgraph.Course} n° ${course.id}`
|
|
||||||
course.id = `accompanying_period_${course.id}`
|
|
||||||
state.courses.push(course)
|
|
||||||
},
|
|
||||||
addRelationship(state, relationship) {
|
|
||||||
relationship.group = relationship.type
|
|
||||||
relationship._id = relationship.id
|
|
||||||
relationship.id = `relationship_${relationship.id}`
|
|
||||||
state.relationships.push(relationship)
|
|
||||||
},
|
|
||||||
addLink(state, link) {
|
|
||||||
state.links.push(link)
|
|
||||||
},
|
|
||||||
updateLink(state, link) {
|
|
||||||
console.log('updateLink', link)
|
|
||||||
let link_ = {
|
|
||||||
from: `person_${link.fromPerson.id}`,
|
|
||||||
to: `person_${link.toPerson.id}`,
|
|
||||||
id: 'relationship_' + splitId(link.id,'id')
|
|
||||||
+ '-person_' + link.fromPerson.id + '-person_' + link.toPerson.id,
|
|
||||||
arrows: getRelationshipDirection(link),
|
|
||||||
color: 'lightblue',
|
|
||||||
font: { color: '#33839d' },
|
|
||||||
dashes: true,
|
|
||||||
label: getRelationshipLabel(link),
|
|
||||||
title: getRelationshipTitle(link),
|
|
||||||
relation: link.relation,
|
|
||||||
reverse: link.reverse
|
|
||||||
}
|
|
||||||
// find row position and replace by updatedLink
|
|
||||||
state.links.splice(
|
|
||||||
state.links.findIndex(item => item.id === link_.id), 1, link_
|
|
||||||
)
|
|
||||||
},
|
|
||||||
removeLink(state, link_id) {
|
|
||||||
state.links = state.links.filter(l => l.id !== link_id)
|
|
||||||
},
|
|
||||||
|
|
||||||
//// id markers
|
|
||||||
markInWhitelist(state, person) {
|
|
||||||
state.whitelistIds.push(person.id)
|
|
||||||
},
|
|
||||||
markPersonLoaded(state, id) {
|
|
||||||
state.personLoadedIds.push(id)
|
|
||||||
},
|
|
||||||
unmarkPersonLoaded(state, id) {
|
|
||||||
state.personLoadedIds = state.personLoadedIds.filter(i => i !== id)
|
|
||||||
},
|
|
||||||
markHouseholdLoading(state, id) {
|
|
||||||
//console.log('..loading household', id)
|
|
||||||
state.householdLoadingIds.push(id)
|
|
||||||
},
|
|
||||||
unmarkHouseholdLoading(state, id) {
|
|
||||||
state.householdLoadingIds = state.householdLoadingIds.filter(i => i !== id)
|
|
||||||
},
|
|
||||||
markCourseLoaded(state, id) {
|
|
||||||
state.courseLoadedIds.push(id)
|
|
||||||
},
|
|
||||||
unmarkCourseLoaded(state, id) {
|
|
||||||
state.courseLoadedIds = state.courseLoadedIds.filter(i => i !== id)
|
|
||||||
},
|
|
||||||
markRelationshipLoaded(state, id) {
|
|
||||||
state.relationshipLoadedIds.push(id)
|
|
||||||
},
|
|
||||||
unmarkRelationshipLoaded(state, id) {
|
|
||||||
state.relationshipLoadedIds = state.relationshipLoadedIds.filter(i => i !== id)
|
|
||||||
},
|
|
||||||
|
|
||||||
//// excluded
|
|
||||||
addExcludedNode(state, id) {
|
|
||||||
//console.log('==> exclude list: +', id)
|
|
||||||
state.excludedNodesIds.push(id)
|
|
||||||
},
|
|
||||||
removeExcludedNode(state, id) {
|
|
||||||
//console.log('<== exclude list: -', id)
|
|
||||||
state.excludedNodesIds = state.excludedNodesIds.filter(e => e !== id)
|
|
||||||
},
|
|
||||||
|
|
||||||
//// unfold
|
|
||||||
unfoldPerson(state, person) {
|
|
||||||
//console.log('unfoldPerson', person)
|
|
||||||
person.label = person._label
|
|
||||||
delete person._label
|
|
||||||
delete person.title
|
|
||||||
person.folded = false
|
|
||||||
},
|
|
||||||
|
|
||||||
//// force update hack
|
|
||||||
updateHack(state) {
|
|
||||||
state.updateHack = state.updateHack + 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
/**
|
|
||||||
* Expand loop (steps 1->10), always start from a person.
|
|
||||||
* Fetch household, courses, relationships, and others persons.
|
|
||||||
* These persons are "missing" and will be first display in fold mode.
|
|
||||||
*
|
|
||||||
* 1) Add a new person
|
|
||||||
* @param object
|
|
||||||
* @param person
|
|
||||||
*/
|
|
||||||
addPerson({ commit, dispatch }, person) {
|
|
||||||
commit('markPersonLoaded', person.id)
|
|
||||||
commit('addPerson', [person, { folded: false }])
|
|
||||||
commit('updateHack')
|
|
||||||
dispatch('fetchInfoForPerson', person)
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2) Fetch infos for this person (hub)
|
|
||||||
* @param object
|
|
||||||
* @param person
|
|
||||||
*/
|
|
||||||
fetchInfoForPerson({ dispatch }, person) {
|
|
||||||
// TODO enfants hors ménages
|
|
||||||
// example: household 61
|
|
||||||
// console.log(person.text, 'household', person.current_household_id)
|
|
||||||
if (null !== person.current_household_id) {
|
|
||||||
dispatch('fetchHouseholdForPerson', person)
|
|
||||||
}
|
|
||||||
dispatch('fetchCoursesByPerson', person)
|
|
||||||
dispatch('fetchRelationshipByPerson', person)
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 3) Fetch person current household (if it is not already loading)
|
|
||||||
* check first isHouseholdLoading to fetch household once
|
|
||||||
* @param object
|
|
||||||
* @param person
|
|
||||||
*/
|
|
||||||
fetchHouseholdForPerson({ commit, getters, dispatch }, person) {
|
|
||||||
//console.log(' isHouseholdLoading ?', getters.isHouseholdLoading(person.current_household_id))
|
|
||||||
if (! getters.isHouseholdLoading(person.current_household_id)) {
|
|
||||||
commit('markHouseholdLoading', person.current_household_id)
|
|
||||||
getHouseholdByPerson(person)
|
|
||||||
.then(household => new Promise(resolve => {
|
|
||||||
commit('addHousehold', household)
|
|
||||||
// DISABLED: in init or expand loop, layer is uncheck when added
|
|
||||||
//commit('addExcludedNode', household.id)
|
|
||||||
//commit('updateHack')
|
|
||||||
dispatch('addLinkFromPersonsToHousehold', household)
|
|
||||||
commit('updateHack')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
).catch( () => {
|
|
||||||
commit('unmarkHouseholdLoading', person.current_household_id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 4) Add an edge for each household member (household -> person)
|
|
||||||
* @param object
|
|
||||||
* @param household
|
|
||||||
*/
|
|
||||||
addLinkFromPersonsToHousehold({ commit, getters, dispatch }, household) {
|
|
||||||
let members = getters.getMembersByHousehold(household.id)
|
|
||||||
console.log('add link for', members.length, 'members')
|
|
||||||
members.forEach(m => {
|
|
||||||
commit('addLink', {
|
|
||||||
from: `${m.person.type}_${m.person.id}`,
|
|
||||||
to: `household_${m.person.current_household_id}`,
|
|
||||||
id: `household_${m.person.current_household_id}-person_${m.person.id}`,
|
|
||||||
arrows: 'from',
|
|
||||||
color: 'pink',
|
|
||||||
font: { color: '#D04A60' },
|
|
||||||
label: getHouseholdLabel(m),
|
|
||||||
width: getHouseholdWidth(m),
|
|
||||||
})
|
|
||||||
if (!getters.isPersonLoaded(m.person.id)) {
|
|
||||||
dispatch('addMissingPerson', [m.person, household])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 5) Fetch AccompanyingCourses for the person
|
|
||||||
* @param object
|
|
||||||
* @param person
|
|
||||||
*/
|
|
||||||
fetchCoursesByPerson({ commit, dispatch }, person) {
|
|
||||||
getCoursesByPerson(person)
|
|
||||||
.then(courses => new Promise(resolve => {
|
|
||||||
dispatch('addCourses', courses)
|
|
||||||
resolve()
|
|
||||||
}))
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 6) Add each distinct course (a person can have multiple courses)
|
|
||||||
* @param object
|
|
||||||
* @param courses
|
|
||||||
*/
|
|
||||||
addCourses({ commit, getters, dispatch }, courses) {
|
|
||||||
let currentCourses = courses.filter(c => c.closingDate === null)
|
|
||||||
currentCourses.forEach(course => {
|
|
||||||
//console.log(' isCourseLoaded ?', getters.isCourseLoaded(course.id))
|
|
||||||
if (! getters.isCourseLoaded(course.id)) {
|
|
||||||
commit('markCourseLoaded', course.id)
|
|
||||||
commit('addCourse', course)
|
|
||||||
commit('addExcludedNode', course.id) // in init or expand loop, layer is uncheck when added
|
|
||||||
dispatch('addLinkFromPersonsToCourse', course)
|
|
||||||
commit('updateHack')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 7) Add an edge for each course participation (course <- person)
|
|
||||||
* @param object
|
|
||||||
* @param course
|
|
||||||
*/
|
|
||||||
addLinkFromPersonsToCourse({ commit, getters, dispatch }, course) {
|
|
||||||
const participations = getters.getParticipationsByCourse(course.id)
|
|
||||||
console.log('add link for', participations.length, 'participations')
|
|
||||||
participations.forEach(p => {
|
|
||||||
//console.log(p.person.id)
|
|
||||||
commit('addLink', {
|
|
||||||
from: `${p.person.type}_${p.person.id}`,
|
|
||||||
to: `${course.id}`,
|
|
||||||
id: `accompanying_period_${splitId(course.id,'id')}-person_${p.person.id}`,
|
|
||||||
arrows: 'from',
|
|
||||||
color: 'orange',
|
|
||||||
font: { color: 'darkorange' },
|
|
||||||
})
|
|
||||||
if (!getters.isPersonLoaded(p.person.id)) {
|
|
||||||
dispatch('addMissingPerson', [p.person, course])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 8) Fetch Relationship
|
|
||||||
* @param object
|
|
||||||
* @param person
|
|
||||||
*/
|
|
||||||
fetchRelationshipByPerson({ dispatch }, person) {
|
|
||||||
//console.log('fetchRelationshipByPerson', person)
|
|
||||||
getRelationshipsByPerson(person)
|
|
||||||
.then(relationships => new Promise(resolve => {
|
|
||||||
dispatch('addRelationships', relationships)
|
|
||||||
resolve()
|
|
||||||
}))
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 9) Add each distinct relationship
|
|
||||||
* @param object
|
|
||||||
* @param relationships
|
|
||||||
*/
|
|
||||||
addRelationships({ commit, getters, dispatch }, relationships) {
|
|
||||||
relationships.forEach(relationship => {
|
|
||||||
//console.log(' isRelationshipLoaded ?', getters.isRelationshipLoaded(relationship.id))
|
|
||||||
if (! getters.isRelationshipLoaded(relationship.id)) {
|
|
||||||
commit('markRelationshipLoaded', relationship.id)
|
|
||||||
commit('addRelationship', relationship)
|
|
||||||
dispatch('addLinkFromRelationship', relationship)
|
|
||||||
commit('updateHack')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 10) Add an edge for each relationship (person -> person)
|
|
||||||
* @param object
|
|
||||||
* @param relationship
|
|
||||||
*/
|
|
||||||
addLinkFromRelationship({ commit, getters, dispatch }, relationship) {
|
|
||||||
//console.log('-> addLink from person', relationship.fromPerson.id, 'to person', relationship.toPerson.id)
|
|
||||||
commit('addLink', {
|
|
||||||
from: `person_${relationship.fromPerson.id}`,
|
|
||||||
to: `person_${relationship.toPerson.id}`,
|
|
||||||
id: 'relationship_' + splitId(relationship.id,'id')
|
|
||||||
+ '-person_' + relationship.fromPerson.id + '-person_' + relationship.toPerson.id,
|
|
||||||
arrows: getRelationshipDirection(relationship),
|
|
||||||
color: 'lightblue',
|
|
||||||
font: { color: '#33839d' },
|
|
||||||
dashes: true,
|
|
||||||
label: getRelationshipLabel(relationship),
|
|
||||||
title: getRelationshipTitle(relationship),
|
|
||||||
relation: relationship.relation,
|
|
||||||
reverse: relationship.reverse
|
|
||||||
})
|
|
||||||
for (let person of [relationship.fromPerson, relationship.toPerson]) {
|
|
||||||
if (!getters.isPersonLoaded(person.id)) {
|
|
||||||
dispatch('addMissingPerson', [person, relationship])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add missing person. node is displayed without label (folded).
|
|
||||||
* We stop here and listen on events to unfold person and expand its fetch infos
|
|
||||||
* @param object
|
|
||||||
* @param array
|
|
||||||
*/
|
|
||||||
addMissingPerson({ commit, getters, dispatch }, [person, parent]) {
|
|
||||||
console.log('! add missing Person', person.id)
|
|
||||||
commit('markPersonLoaded', person.id)
|
|
||||||
commit('addPerson', [person, { folded: true }])
|
|
||||||
if (getters.isExcludedNode(parent.id)) {
|
|
||||||
// in init or expand loop, exclude too missing persons if parent have been excluded
|
|
||||||
commit('addExcludedNode', person.id)
|
|
||||||
}
|
|
||||||
commit('updateHack')
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ==================================================================
|
|
||||||
* Triggered by a vis-network event when clicking on a Course Node.
|
|
||||||
* Each folded node is unfold, then expanded with fetch infos
|
|
||||||
* @param object
|
|
||||||
* @param course
|
|
||||||
*/
|
|
||||||
unfoldPersonsByCourse({ getters, commit, dispatch }, course) {
|
|
||||||
const participations = getters.getParticipationsByCourse(course.id)
|
|
||||||
getters.getPersonsGroup(participations)
|
|
||||||
.forEach(person => {
|
|
||||||
if (person.folded === true) {
|
|
||||||
console.log('-=. unfold and expand person', person.id)
|
|
||||||
commit('unfoldPerson', person)
|
|
||||||
dispatch('fetchInfoForPerson', person)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered by a vis-network event when clicking on a Household Node.
|
|
||||||
* Each folded node is unfold, then expanded with fetch infos
|
|
||||||
* @param object
|
|
||||||
* @param household
|
|
||||||
*/
|
|
||||||
unfoldPersonsByHousehold({ getters, commit, dispatch }, household) {
|
|
||||||
const members = getters.getMembersByHousehold(household.id)
|
|
||||||
getters.getPersonsGroup(members)
|
|
||||||
.forEach(person => {
|
|
||||||
if (person.folded === true) {
|
|
||||||
console.log('-=. unfold and expand person', person.id)
|
|
||||||
commit('unfoldPerson', person)
|
|
||||||
dispatch('fetchInfoForPerson', person)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ==================================================================
|
|
||||||
* For an excluded node, add|remove relative persons excluded too
|
|
||||||
* @param object
|
|
||||||
* @param array (add|remove action, id)
|
|
||||||
*/
|
|
||||||
excludedNode({ getters, commit }, [action, id]) {
|
|
||||||
const personGroup = () => {
|
|
||||||
switch (splitId(id, 'type')) {
|
|
||||||
case 'accompanying_period':
|
|
||||||
return getters.getParticipationsByCourse(id)
|
|
||||||
case 'household':
|
|
||||||
return getters.getMembersByHousehold(id)
|
|
||||||
default:
|
|
||||||
throw 'undefined case with this id'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let group = getters.getPersonsGroup(personGroup())
|
|
||||||
if (action === 'add') {
|
|
||||||
commit('addExcludedNode', id)
|
|
||||||
group.forEach(person => {
|
|
||||||
// countLinks < 2 but parent has just already been added !
|
|
||||||
if (!getters.isInWhitelist(person.id) && getters.countLinksByNode(person.id) < 1) {
|
|
||||||
commit('addExcludedNode', person.id)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (action === 'remove') {
|
|
||||||
commit('removeExcludedNode', id)
|
|
||||||
group.forEach(person => {
|
|
||||||
commit('removeExcludedNode', person.id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
commit('updateHack')
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export { store }
|
|
@@ -1,262 +0,0 @@
|
|||||||
import { visMessages } from './i18n'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vis-network initial data/configuration script
|
|
||||||
* Notes:
|
|
||||||
* Use window.network and window.options to avoid conflict between vue and vis
|
|
||||||
* cfr. https://github.com/almende/vis/issues/2524#issuecomment-307108271
|
|
||||||
*/
|
|
||||||
|
|
||||||
window.network = {}
|
|
||||||
|
|
||||||
window.options = {
|
|
||||||
locale: 'fr',
|
|
||||||
locales: visMessages,
|
|
||||||
/*
|
|
||||||
configure: {
|
|
||||||
enabled: true,
|
|
||||||
filter: 'nodes,edges',
|
|
||||||
//container: undefined,
|
|
||||||
showButton: true
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
physics: {
|
|
||||||
enabled: true,
|
|
||||||
barnesHut: {
|
|
||||||
theta: 0.5,
|
|
||||||
gravitationalConstant: -2000,
|
|
||||||
centralGravity: 0.08, //// 0.3
|
|
||||||
springLength: 220, //// 95
|
|
||||||
springConstant: 0.04,
|
|
||||||
damping: 0.09,
|
|
||||||
avoidOverlap: 0
|
|
||||||
},
|
|
||||||
forceAtlas2Based: {
|
|
||||||
theta: 0.5,
|
|
||||||
gravitationalConstant: -50,
|
|
||||||
centralGravity: 0.01,
|
|
||||||
springLength: 100,
|
|
||||||
springConstant: 0.08,
|
|
||||||
damping: 0.4,
|
|
||||||
avoidOverlap: 0
|
|
||||||
},
|
|
||||||
repulsion: {
|
|
||||||
centralGravity: 0.2,
|
|
||||||
springLength: 200,
|
|
||||||
springConstant: 0.05,
|
|
||||||
nodeDistance: 100,
|
|
||||||
damping: 0.09
|
|
||||||
},
|
|
||||||
hierarchicalRepulsion: {
|
|
||||||
centralGravity: 0.0,
|
|
||||||
springLength: 100,
|
|
||||||
springConstant: 0.01,
|
|
||||||
nodeDistance: 120,
|
|
||||||
damping: 0.09,
|
|
||||||
avoidOverlap: 0
|
|
||||||
},
|
|
||||||
maxVelocity: 50,
|
|
||||||
minVelocity: 0.1,
|
|
||||||
solver: 'forceAtlas2Based', //'barnesHut', //
|
|
||||||
stabilization: {
|
|
||||||
enabled: true,
|
|
||||||
iterations: 1000,
|
|
||||||
updateInterval: 100,
|
|
||||||
onlyDynamicEdges: false,
|
|
||||||
fit: true
|
|
||||||
},
|
|
||||||
timestep: 0.5,
|
|
||||||
adaptiveTimestep: true,
|
|
||||||
wind: { x: 0, y: 0 }
|
|
||||||
},
|
|
||||||
interaction: {
|
|
||||||
hover: true,
|
|
||||||
multiselect: true,
|
|
||||||
navigationButtons: false,
|
|
||||||
},
|
|
||||||
manipulation: {
|
|
||||||
enabled: false,
|
|
||||||
initiallyActive: false,
|
|
||||||
addNode: false,
|
|
||||||
deleteNode: false
|
|
||||||
},
|
|
||||||
nodes: {
|
|
||||||
borderWidth: 1,
|
|
||||||
borderWidthSelected: 3,
|
|
||||||
font: {
|
|
||||||
multi: 'md'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
edges: {
|
|
||||||
font: {
|
|
||||||
color: '#b0b0b0',
|
|
||||||
size: 9,
|
|
||||||
face: 'arial',
|
|
||||||
background: 'none',
|
|
||||||
strokeWidth: 2, // px
|
|
||||||
strokeColor: '#ffffff',
|
|
||||||
align: 'middle',
|
|
||||||
multi: false,
|
|
||||||
vadjust: 0,
|
|
||||||
},
|
|
||||||
scaling:{
|
|
||||||
label: true,
|
|
||||||
},
|
|
||||||
smooth: true,
|
|
||||||
},
|
|
||||||
groups: {
|
|
||||||
person: {
|
|
||||||
shape: 'box',
|
|
||||||
shapeProperties: {
|
|
||||||
borderDashes: false,
|
|
||||||
borderRadius: 3,
|
|
||||||
},
|
|
||||||
color: {
|
|
||||||
border: '#b0b0b0',
|
|
||||||
background: 'rgb(193,229,222)',
|
|
||||||
highlight: {
|
|
||||||
border: '#89c9a9',
|
|
||||||
background: 'rgb(156,213,203)'
|
|
||||||
},
|
|
||||||
hover: {
|
|
||||||
border: '#89c9a9',
|
|
||||||
background: 'rgb(156,213,203)'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
opacity: 0.85,
|
|
||||||
shadow:{
|
|
||||||
enabled: true,
|
|
||||||
color: 'rgba(0,0,0,0.5)',
|
|
||||||
size:10,
|
|
||||||
x:5,
|
|
||||||
y:5
|
|
||||||
},
|
|
||||||
},
|
|
||||||
household: {
|
|
||||||
color: 'pink'
|
|
||||||
},
|
|
||||||
accompanying_period: {
|
|
||||||
color: 'orange',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param gender
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
const getGender = (gender) => {
|
|
||||||
switch (gender) {
|
|
||||||
case 'both':
|
|
||||||
return visMessages.fr.visgraph.both
|
|
||||||
case 'woman':
|
|
||||||
return visMessages.fr.visgraph.woman
|
|
||||||
case 'man':
|
|
||||||
return visMessages.fr.visgraph.man
|
|
||||||
default:
|
|
||||||
throw 'gender undefined'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO Repeat getAge() in PersonRenderBox.vue
|
|
||||||
* @param birthdate
|
|
||||||
* @returns {string|null}
|
|
||||||
*/
|
|
||||||
const getAge = (birthdate) => {
|
|
||||||
if (null === birthdate) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
const birthday = new Date(birthdate.datetime)
|
|
||||||
const now = new Date()
|
|
||||||
return (now.getFullYear() - birthday.getFullYear()) + ' '+ visMessages.fr.visgraph.years
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return member position in household
|
|
||||||
* @param member
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
const getHouseholdLabel = (member) => {
|
|
||||||
let position = member.position.label.fr
|
|
||||||
let holder = member.holder ? ` ${visMessages.fr.visgraph.Holder}` : ''
|
|
||||||
return position + holder
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return edge width for member (depends of position in household)
|
|
||||||
* @param member
|
|
||||||
* @returns integer (width)
|
|
||||||
*/
|
|
||||||
const getHouseholdWidth = (member) => {
|
|
||||||
if (member.holder) {
|
|
||||||
return 5
|
|
||||||
}
|
|
||||||
if (member.shareHousehold) {
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return direction edge
|
|
||||||
* @param relationship
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
const getRelationshipDirection = (relationship) => {
|
|
||||||
return (!relationship.reverse) ? 'to' : 'from'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return label edge
|
|
||||||
* !! always set label in title direction (arrow is reversed, see in previous method) !!
|
|
||||||
* @param relationship
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
const getRelationshipLabel = (relationship) => {
|
|
||||||
return relationship.relation.title.fr
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return title edge
|
|
||||||
* @param relationship
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
const getRelationshipTitle = (relationship) => {
|
|
||||||
return (!relationship.reverse) ?
|
|
||||||
relationship.relation.title.fr + ': ' + relationship.fromPerson.text + '\n' + relationship.relation.reverseTitle.fr + ': ' + relationship.toPerson.text :
|
|
||||||
relationship.relation.title.fr + ': ' + relationship.toPerson.text + '\n' + relationship.relation.reverseTitle.fr + ': ' + relationship.fromPerson.text
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Split string id and return type|id substring
|
|
||||||
* @param id
|
|
||||||
* @param position
|
|
||||||
* @returns string|integer
|
|
||||||
*/
|
|
||||||
const splitId = (id, position) => {
|
|
||||||
//console.log(id, position)
|
|
||||||
switch (position) {
|
|
||||||
case 'type': // return 'accompanying_period'
|
|
||||||
return /(.+)_/.exec(id)[1]
|
|
||||||
case 'id': // return 124
|
|
||||||
return parseInt(id.toString()
|
|
||||||
.split("_")
|
|
||||||
.pop())
|
|
||||||
case 'link':
|
|
||||||
return id.split("-")[0] // return first segment
|
|
||||||
default:
|
|
||||||
throw 'position undefined'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
getGender,
|
|
||||||
getAge,
|
|
||||||
getHouseholdLabel,
|
|
||||||
getHouseholdWidth,
|
|
||||||
getRelationshipDirection,
|
|
||||||
getRelationshipLabel,
|
|
||||||
getRelationshipTitle,
|
|
||||||
splitId
|
|
||||||
}
|
|
@@ -20,25 +20,18 @@
|
|||||||
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',
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
<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>
|
|
@@ -1,34 +0,0 @@
|
|||||||
{% 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,11 +103,6 @@
|
|||||||
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 -%}
|
||||||
|
@@ -2,34 +2,26 @@
|
|||||||
|
|
||||||
{% block title 'household.Relationship'|trans %}
|
{% block title 'household.Relationship'|trans %}
|
||||||
|
|
||||||
{#
|
{% block content %}
|
||||||
Give more space to graph:
|
<h1>{{ block('title') }}</h1>
|
||||||
* use parent twig block (layout_wvm_content)
|
<div id="graph-relationship"></div>
|
||||||
* hide title (d-none)
|
|
||||||
* apply negative margin-top
|
|
||||||
#}
|
|
||||||
{% block layout_wvm_content %}
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
|
|
||||||
<div class="col-md-10 col-xxl d-none">
|
{% for m in household.members %}
|
||||||
<h1>{{ block('title') }}</h1>
|
{% if m.endDate is null %}
|
||||||
</div>
|
{{ dump(m) }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<div id="relationship-graph"
|
|
||||||
style="margin-top: -3rem"
|
|
||||||
data-persons="{{ persons|e('html_attr') }}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block block_post_menu %}
|
|
||||||
<div id="visgraph-legend"></div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_script_tags('vue_visgraph') }}
|
{{ parent() }}
|
||||||
|
{{ encore_entry_script_tags('page_vis') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{{ encore_entry_link_tags('vue_visgraph') }}
|
{{ parent() }}
|
||||||
|
{{ encore_entry_link_tags('page_vis') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block block_post_menu %}{% endblock %}
|
||||||
|
@@ -216,23 +216,13 @@ This view should receive those arguments:
|
|||||||
{%- if chill_person.fields.mobilenumber == 'visible' -%}
|
{%- if chill_person.fields.mobilenumber == 'visible' -%}
|
||||||
<dl>
|
<dl>
|
||||||
<dt>{{ 'Mobilenumber'|trans }} :</dt>
|
<dt>{{ 'Mobilenumber'|trans }} :</dt>
|
||||||
<dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber }}">{{ person.mobilenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
|
<dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber }}"><pre>{{ person.mobilenumber|chill_format_phonenumber }}</pre></a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{%- if chill_person.fields.mobilenumber == 'visible' -%}
|
{# TODO
|
||||||
{% if person.otherPhoneNumbers is not empty %}
|
display collection of others phonenumbers
|
||||||
<dl>
|
#}
|
||||||
<dt>{{ 'Others phone numbers'|trans }} :</dt>
|
|
||||||
{% for el in person.otherPhoneNumbers %}
|
|
||||||
{% if el.phonenumber is not empty %}
|
|
||||||
<dd>{% if el.description is not empty %}{{ el.description }} : {% endif %}<a href="tel:{{ el.phonenumber }}">{{ el.phonenumber|chill_format_phonenumber }}</a></dd>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</dl>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{%- if chill_person.fields.contact_info == 'visible' -%}
|
{%- if chill_person.fields.contact_info == 'visible' -%}
|
||||||
<dl>
|
<dl>
|
||||||
|
@@ -263,9 +263,8 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
|||||||
|
|
||||||
public function convertTermsToFormData(array $terms)
|
public function convertTermsToFormData(array $terms)
|
||||||
{
|
{
|
||||||
$data = [];
|
foreach(['firstname', 'lastname', 'gender', '_default']
|
||||||
|
as $key) {
|
||||||
foreach(['firstname', 'lastname', 'gender', '_default'] as $key) {
|
|
||||||
$data[$key] = $terms[$key] ?? null;
|
$data[$key] = $terms[$key] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,43 +2,29 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Search;
|
namespace Chill\PersonBundle\Search;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Chill\MainBundle\Search\SearchApiQuery;
|
use Chill\MainBundle\Search\SearchApiQuery;
|
||||||
use Chill\MainBundle\Search\SearchApiInterface;
|
use Chill\MainBundle\Search\SearchApiInterface;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
|
||||||
use Symfony\Component\Security\Core\Security;
|
|
||||||
|
|
||||||
class SearchPersonApiProvider implements SearchApiInterface
|
class SearchPersonApiProvider implements SearchApiInterface
|
||||||
{
|
{
|
||||||
private PersonRepository $personRepository;
|
private PersonRepository $personRepository;
|
||||||
private Security $security;
|
|
||||||
private AuthorizationHelperInterface $authorizationHelper;
|
|
||||||
|
|
||||||
public function __construct(PersonRepository $personRepository, Security $security, AuthorizationHelperInterface $authorizationHelper)
|
public function __construct(PersonRepository $personRepository)
|
||||||
{
|
{
|
||||||
$this->personRepository = $personRepository;
|
$this->personRepository = $personRepository;
|
||||||
$this->security = $security;
|
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
|
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
|
||||||
{
|
|
||||||
return $this->addAuthorizations($this->buildBaseQuery($pattern, $parameters));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildBaseQuery(string $pattern, array $parameters): SearchApiQuery
|
|
||||||
{
|
{
|
||||||
$query = new SearchApiQuery();
|
$query = new SearchApiQuery();
|
||||||
$query
|
$query
|
||||||
->setSelectKey("person")
|
->setSelectKey("person")
|
||||||
->setSelectJsonbMetadata("jsonb_build_object('id', person.id)")
|
->setSelectJsonbMetadata("jsonb_build_object('id', person.id)")
|
||||||
->setSelectPertinence("".
|
->setSelectPertinence("GREATEST(".
|
||||||
"STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) + ".
|
"STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical), ".
|
||||||
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int + ".
|
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int".
|
||||||
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int"
|
")", [ $pattern, $pattern ])
|
||||||
, [ $pattern, $pattern, $pattern ])
|
|
||||||
->setFromClause("chill_person_person AS person")
|
->setFromClause("chill_person_person AS person")
|
||||||
->setWhereClauses("LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR ".
|
->setWhereClauses("LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR ".
|
||||||
"person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%' ", [ $pattern, $pattern ])
|
"person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%' ", [ $pattern, $pattern ])
|
||||||
@@ -47,28 +33,6 @@ class SearchPersonApiProvider implements SearchApiInterface
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addAuthorizations(SearchApiQuery $query): SearchApiQuery
|
|
||||||
{
|
|
||||||
$authorizedCenters = $this->authorizationHelper
|
|
||||||
->getReachableCenters($this->security->getUser(), PersonVoter::SEE);
|
|
||||||
|
|
||||||
if ([] === $authorizedCenters) {
|
|
||||||
return $query->andWhereClause("FALSE = TRUE", []);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query
|
|
||||||
->andWhereClause(
|
|
||||||
strtr(
|
|
||||||
"person.center_id IN ({{ center_ids }})",
|
|
||||||
[
|
|
||||||
'{{ center_ids }}' => \implode(', ',
|
|
||||||
\array_fill(0, count($authorizedCenters), '?')),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
\array_map(function(Center $c) {return $c->getId();}, $authorizedCenters)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||||
{
|
{
|
||||||
return \in_array('person', $types);
|
return \in_array('person', $types);
|
||||||
|
@@ -86,6 +86,7 @@ class PersonNormalizer implements
|
|||||||
'mobilenumber' => $person->getMobilenumber(),
|
'mobilenumber' => $person->getMobilenumber(),
|
||||||
'altNames' => $this->normalizeAltNames($person->getAltNames()),
|
'altNames' => $this->normalizeAltNames($person->getAltNames()),
|
||||||
'gender' => $person->getGender(),
|
'gender' => $person->getGender(),
|
||||||
|
'gender_numeric' => $person->getGenderNumeric(),
|
||||||
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()),
|
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()),
|
||||||
'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : null,
|
'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : 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();
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user