mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add base authorization to person search + improve search ordering
This commit is contained in:
parent
4ba93bb709
commit
8296d60cb6
@ -18,6 +18,8 @@ and this project adheres to
|
|||||||
* add form to create/edit/delete relationship link,
|
* add form to create/edit/delete relationship link,
|
||||||
* improve graph refresh mechanism
|
* improve graph refresh mechanism
|
||||||
* add feature to export canvas as image (png)
|
* 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;
|
||||||
|
|
||||||
|
|
||||||
## Test releases
|
## Test releases
|
||||||
|
|
||||||
|
@ -10,16 +10,6 @@ parameters:
|
|||||||
count: 4
|
count: 4
|
||||||
path: src/Bundle/ChillActivityBundle/Controller/ActivityController.php
|
path: src/Bundle/ChillActivityBundle/Controller/ActivityController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Variable \\$activity might not be defined\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@ -305,11 +295,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php
|
path: src/Bundle/ChillDocStoreBundle/Controller/DocumentCategoryController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Bundle/ChillDocStoreBundle/DataFixtures/ORM/LoadDocumentACL.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
|
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@ -325,11 +310,6 @@ parameters:
|
|||||||
count: 3
|
count: 3
|
||||||
path: src/Bundle/ChillEventBundle/Controller/ParticipationController.php
|
path: src/Bundle/ChillEventBundle/Controller/ParticipationController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Bundle/ChillEventBundle/DataFixtures/ORM/LoadRolesACL.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
|
|
||||||
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;
|
||||||
@ -31,25 +33,19 @@ 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()
|
public function __construct(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
$this->faker = FakerFactory::create('fr_FR');
|
||||||
|
$this->em = $em;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder()
|
public function getOrder()
|
||||||
@ -88,7 +84,7 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
|
|||||||
{
|
{
|
||||||
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
$reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)];
|
||||||
|
|
||||||
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) {
|
if (in_array($this->getReference($reasonRef)->getId(), $excludingIds, true)) {
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
@ -132,20 +128,17 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C
|
|||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$persons = $this->container->get('doctrine.orm.entity_manager')
|
$persons = $this->em
|
||||||
->getRepository('ChillPersonBundle:Person')
|
->getRepository(Person::class)
|
||||||
->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();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
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' ]
|
||||||
|
@ -5,21 +5,20 @@ 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(
|
||||||
EntityManagerInterface $em
|
UserRepository $userRepository
|
||||||
) {
|
) {
|
||||||
$this->userRepository = $em->getRepository(User::class);
|
$this->userRepository = $userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder(): int
|
public function getOrder(): int
|
||||||
|
@ -57,7 +57,7 @@ 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'))) {
|
if (in_array($scope->getName()['en'], array('administrative', 'social'), true)) {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ 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'))) {
|
if (in_array($scope->getName()['en'], array('administrative', 'social'), true)) {
|
||||||
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;
|
||||||
|
@ -88,13 +88,13 @@ class SearchApi
|
|||||||
|
|
||||||
private function buildCountQuery(array $queries, $types, $parameters)
|
private function buildCountQuery(array $queries, $types, $parameters)
|
||||||
{
|
{
|
||||||
$query = "SELECT COUNT(sq.key) AS count FROM ({union_unordered}) AS sq";
|
$query = "SELECT COUNT(*) AS count FROM ({union_unordered}) AS sq";
|
||||||
$unions = [];
|
$unions = [];
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
|
|
||||||
foreach ($queries as $q) {
|
foreach ($queries as $q) {
|
||||||
$unions[] = $q->buildQuery();
|
$unions[] = $q->buildQuery(true);
|
||||||
$parameters = \array_merge($parameters, $q->buildParameters());
|
$parameters = \array_merge($parameters, $q->buildParameters(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
$unionUnordered = \implode(" UNION ", $unions);
|
$unionUnordered = \implode(" UNION ", $unions);
|
||||||
|
@ -76,33 +76,58 @@ class SearchApiQuery
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildQuery(): string
|
public function buildQuery(bool $countOnly = false): string
|
||||||
{
|
{
|
||||||
$where = \implode(' AND ', $this->whereClauses);
|
$isMultiple = count($this->whereClauses);
|
||||||
|
$where =
|
||||||
|
($isMultiple ? '(' : '').
|
||||||
|
\implode(
|
||||||
|
($isMultiple ? ')' : '').' AND '.($isMultiple ? '(' : '')
|
||||||
|
, $this->whereClauses).
|
||||||
|
($isMultiple ? ')' : '')
|
||||||
|
;
|
||||||
|
|
||||||
return \strtr("SELECT
|
if (!$countOnly) {
|
||||||
|
$select = \strtr("
|
||||||
'{key}' AS key,
|
'{key}' AS key,
|
||||||
{metadata} AS metadata,
|
{metadata} AS metadata,
|
||||||
{pertinence} AS pertinence
|
{pertinence} AS pertinence
|
||||||
FROM {from}
|
", [
|
||||||
WHERE {where}
|
'{key}' => $this->selectKey,
|
||||||
|
'{metadata}' => $this->jsonbMetadata,
|
||||||
|
'{pertinence}' => $this->pertinence,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$select = "1 AS c";
|
||||||
|
}
|
||||||
|
|
||||||
|
return \strtr("SELECT
|
||||||
|
{select}
|
||||||
|
FROM {from}
|
||||||
|
WHERE {where}
|
||||||
", [
|
", [
|
||||||
'{key}' => $this->selectKey,
|
'{select}' => $select,
|
||||||
'{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
|
||||||
{
|
{
|
||||||
return \array_merge(
|
if (!$countOnly) {
|
||||||
$this->selectKeyParams,
|
return \array_merge(
|
||||||
$this->jsonbMetadataParams,
|
$this->selectKeyParams,
|
||||||
$this->pertinenceParams,
|
$this->jsonbMetadataParams,
|
||||||
$this->fromClauseParams,
|
$this->pertinenceParams,
|
||||||
\array_merge([], ...$this->whereClausesParams),
|
$this->fromClauseParams,
|
||||||
);
|
\array_merge([], ...$this->whereClausesParams),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return \array_merge(
|
||||||
|
$this->fromClauseParams,
|
||||||
|
\array_merge([], ...$this->whereClausesParams),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ 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,7 +20,12 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,14 +28,12 @@ use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
|
|||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
|
|
||||||
class AccompanyingCourseApiController extends ApiController
|
final class AccompanyingCourseApiController extends ApiController
|
||||||
{
|
{
|
||||||
protected EventDispatcherInterface $eventDispatcher;
|
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
protected ValidatorInterface $validator;
|
private ValidatorInterface $validator;
|
||||||
|
|
||||||
private Registry $registry;
|
private Registry $registry;
|
||||||
|
|
||||||
private ReferralsSuggestionInterface $referralAvailable;
|
private ReferralsSuggestionInterface $referralAvailable;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -262,7 +262,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
|||||||
$manager->persist($accompanyingPeriod);
|
$manager->persist($accompanyingPeriod);
|
||||||
echo "add person'".$person->__toString()."'\n";
|
echo "add person'".$person->__toString()."'\n";
|
||||||
|
|
||||||
$this->addReference(self::PERSON, $person);
|
$this->addReference(self::PERSON.$person->getId(), $person);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRandomUser(): User
|
private function getRandomUser(): User
|
||||||
|
@ -10,7 +10,26 @@ use Doctrine\Persistence\ObjectManager;
|
|||||||
|
|
||||||
class LoadRelations extends Fixture implements FixtureGroupInterface
|
class LoadRelations extends Fixture implements FixtureGroupInterface
|
||||||
{
|
{
|
||||||
public const RELATIONS = 'relations';
|
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
|
public static function getGroups(): array
|
||||||
{
|
{
|
||||||
@ -19,37 +38,17 @@ class LoadRelations extends Fixture implements FixtureGroupInterface
|
|||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$relations = [
|
foreach (self::RELATIONS as $key => $value){
|
||||||
['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']],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($relations as $value){
|
|
||||||
print "Creating a new relation type: relation" . $value['title']['fr'] . "reverse relation: " . $value['reverseTitle']['fr'] . "\n";
|
print "Creating a new relation type: relation" . $value['title']['fr'] . "reverse relation: " . $value['reverseTitle']['fr'] . "\n";
|
||||||
$relation = new Relation();
|
$relation = new Relation();
|
||||||
$relation->setTitle($value['title'])
|
$relation->setTitle($value['title'])
|
||||||
->setReverseTitle($value['reverseTitle']);
|
->setReverseTitle($value['reverseTitle']);
|
||||||
$manager->persist($relation);
|
$manager->persist($relation);
|
||||||
$this->addReference(self::RELATIONS, $relation);
|
|
||||||
|
$this->addReference(self::RELATION_KEY.$key, $relation);
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,24 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
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\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Chill\PersonBundle\DataFixtures\ORM\LoadPeople;
|
|
||||||
use Chill\PersonBundle\DataFixtures\ORM\LoadRelations;
|
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
|
|
||||||
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||||
{
|
{
|
||||||
|
use PersonRandomHelper;
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
public function getDependencies()
|
public function getDependencies()
|
||||||
{
|
{
|
||||||
@ -21,16 +28,33 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
|
|||||||
LoadPeople::class,
|
LoadPeople::class,
|
||||||
LoadRelations::class
|
LoadRelations::class
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$relationship = new Relationship;
|
for ($i = 0; $i < 15; $i++) {
|
||||||
$relationship->setFromPerson($this->getReference(LoadPeople::PERSON));
|
$user = $this->getRandomUser();
|
||||||
$relationship->setToPerson($this->getReference(LoadPeople::PERSON));
|
$date = new \DateTimeImmutable();
|
||||||
$relationship->setRelation($this->getReference(LoadRelations::RELATIONS));
|
$relationship = (new Relationship())
|
||||||
$relationship->setReverse((bool)random_int(0, 1));
|
->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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,6 +37,6 @@ class RelationRepository implements ObjectRepository
|
|||||||
|
|
||||||
public function getClassName(): string
|
public function getClassName(): string
|
||||||
{
|
{
|
||||||
return MaritalStatus::class;
|
return Relation::class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ use Doctrine\Persistence\ObjectRepository;
|
|||||||
|
|
||||||
class RelationshipRepository implements ObjectRepository
|
class RelationshipRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
private EntityRepository $repository;
|
private EntityRepository $repository;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em)
|
||||||
@ -40,7 +39,7 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
|
|
||||||
public function getClassName(): string
|
public function getClassName(): string
|
||||||
{
|
{
|
||||||
return MaritalStatus::class;
|
return Relationship::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByPerson($personId): array
|
public function findByPerson($personId): array
|
||||||
|
@ -2,29 +2,43 @@
|
|||||||
|
|
||||||
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)
|
public function __construct(PersonRepository $personRepository, Security $security, AuthorizationHelperInterface $authorizationHelper)
|
||||||
{
|
{
|
||||||
$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("GREATEST(".
|
->setSelectPertinence("".
|
||||||
"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 + ".
|
||||||
")", [ $pattern, $pattern ])
|
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int"
|
||||||
|
, [ $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 ])
|
||||||
@ -33,6 +47,28 @@ 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);
|
||||||
|
@ -259,7 +259,8 @@ class PersonControllerUpdateTest extends WebTestCase
|
|||||||
return array(
|
return array(
|
||||||
['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ],
|
['firstName', 'random Value', function(Person $person) { return $person->getFirstName(); } ],
|
||||||
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
|
['lastName' , 'random Value', function(Person $person) { return $person->getLastName(); } ],
|
||||||
['placeOfBirth', 'NONE PLACE', function(Person $person) { return $person->getPlaceOfBirth(); }],
|
// reminder: this value is capitalized
|
||||||
|
['placeOfBirth', 'A PLACE', function(Person $person) { return $person->getPlaceOfBirth(); }],
|
||||||
['birthdate', '1980-12-15', function(Person $person) { return $person->getBirthdate()->format('Y-m-d'); }],
|
['birthdate', '1980-12-15', function(Person $person) { return $person->getBirthdate()->format('Y-m-d'); }],
|
||||||
['phonenumber', '+32123456789', function(Person $person) { return $person->getPhonenumber(); }],
|
['phonenumber', '+32123456789', function(Person $person) { return $person->getPhonenumber(); }],
|
||||||
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
|
['memo', 'jfkdlmq jkfldmsq jkmfdsq', function(Person $person) { return $person->getMemo(); }],
|
||||||
|
@ -2,23 +2,32 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\Controller;
|
namespace Chill\PersonBundle\Tests\Controller;
|
||||||
|
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||||
|
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
class RelationshipApiControllerTest extends WebTestCase
|
class RelationshipApiControllerTest extends WebTestCase
|
||||||
{
|
{
|
||||||
public static function setUpBeforeClass()
|
use PrepareClientTrait;
|
||||||
{
|
|
||||||
static::bootKernel();
|
private KernelBrowser $client;
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* A cache for all relations
|
||||||
|
* @var array|null|Relation[]
|
||||||
|
*/
|
||||||
|
private ?array $relations = null;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->client = static::createClient(array(), array(
|
static::bootKernel();
|
||||||
'PHP_AUTH_USER' => 'fred',
|
$this->client = $this->getClientAuthenticated();
|
||||||
'PHP_AUTH_PW' => 'password',
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +48,7 @@ class RelationshipApiControllerTest extends WebTestCase
|
|||||||
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
|
public function testPostRelationship($fromPersonId, $toPersonId, $relationId, $isReverse): void
|
||||||
{
|
{
|
||||||
$this->client->request(Request::METHOD_POST,
|
$this->client->request(Request::METHOD_POST,
|
||||||
'/api/1.0/person/relations/relationship.json',
|
'/api/1.0/relations/relationship.json',
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
@ -57,18 +66,72 @@ class RelationshipApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
public function relationProvider(): array
|
public function relationProvider(): array
|
||||||
{
|
{
|
||||||
//TODO: which different cases to test?
|
static::bootKernel();
|
||||||
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
$countPersons = $em->createQueryBuilder()
|
||||||
|
->select('count(p)')
|
||||||
|
->from(Person::class, 'p')
|
||||||
|
->join('p.center', 'c')
|
||||||
|
->where('c.name LIKE :name')
|
||||||
|
->setParameter('name', 'Center A')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult()
|
||||||
|
;
|
||||||
|
$persons = $em->createQueryBuilder()
|
||||||
|
->select('p')
|
||||||
|
->from(Person::class, 'p')
|
||||||
|
->join('p.center', 'c')
|
||||||
|
->where('c.name LIKE :name')
|
||||||
|
->setParameter('name', 'Center A')
|
||||||
|
->getQuery()
|
||||||
|
->setMaxResults(2)
|
||||||
|
->setFirstResult(\random_int(0, $countPersons - 1))
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[333, 334, 1, true],
|
[$persons[0]->getId(), $persons[1]->getId(), $this->getRandomRelation($em)->getId(), true],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getRandomRelation(EntityManagerInterface $em): Relation
|
||||||
|
{
|
||||||
|
if (null === $this->relations) {
|
||||||
|
$this->relations = $em->getRepository(Relation::class)
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->relations[\array_rand($this->relations)];
|
||||||
|
}
|
||||||
|
|
||||||
public function personProvider(): array
|
public function personProvider(): array
|
||||||
{
|
{
|
||||||
//TODO: which different cases to test?
|
static::bootKernel();
|
||||||
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
$countPersons = $em->createQueryBuilder()
|
||||||
|
->select('count(p)')
|
||||||
|
->from(Person::class, 'p')
|
||||||
|
->join('p.center', 'c')
|
||||||
|
->where('c.name LIKE :name')
|
||||||
|
->setParameter('name', 'Center A')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult()
|
||||||
|
;
|
||||||
|
$person = $em->createQueryBuilder()
|
||||||
|
->select('p')
|
||||||
|
->from(Person::class, 'p')
|
||||||
|
->join('p.center', 'c')
|
||||||
|
->where('c.name LIKE :name')
|
||||||
|
->setParameter('name', 'Center A')
|
||||||
|
->getQuery()
|
||||||
|
->setMaxResults(1)
|
||||||
|
->setFirstResult(\random_int(0, $countPersons - 1))
|
||||||
|
->getSingleResult()
|
||||||
|
;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[333],
|
[$person->getId()],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
Chill\PersonBundle\DataFixtures\ORM\:
|
Chill\PersonBundle\DataFixtures\ORM\:
|
||||||
autowire: true
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
resource: ../../DataFixtures/ORM
|
resource: ../../DataFixtures/ORM
|
||||||
tags: [ 'doctrine.fixture.orm' ]
|
tags: [ 'doctrine.fixture.orm' ]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user