mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'master' into bootstrap5
This commit is contained in:
commit
794c7d0c4a
@ -32,9 +32,8 @@ use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
|
||||
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
||||
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
||||
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Chill\MainBundle\Doctrine\DQL\Replace;
|
||||
use Chill\MainBundle\Doctrine\ORM\Hydration\FlatHierarchyEntityHydrator;
|
||||
use Chill\MainBundle\Doctrine\Type\NativeDateIntervalType;
|
||||
use Chill\MainBundle\Doctrine\Type\PointType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -186,6 +185,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'OVERLAPSI' => OverlapsI::class,
|
||||
],
|
||||
],
|
||||
'hydrators' => [
|
||||
'chill_flat_hierarchy_list' => FlatHierarchyEntityHydrator::class,
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Doctrine\ORM\Hydration;
|
||||
|
||||
use Doctrine\ORM\Internal\Hydration\ObjectHydrator;
|
||||
use Generator;
|
||||
|
||||
final class FlatHierarchyEntityHydrator extends ObjectHydrator
|
||||
{
|
||||
public const LIST = 'chill_flat_hierarchy_list';
|
||||
|
||||
protected function hydrateAllData()
|
||||
{
|
||||
return array_values(iterator_to_array($this->flatListGenerator($this->buildChildrenHashmap(parent::hydrateAllData()))));
|
||||
}
|
||||
|
||||
private function flatListGenerator(array $hashMap, ?object $parent = null): Generator
|
||||
{
|
||||
$parent = null === $parent ? null : spl_object_id($parent);
|
||||
$hashMap += [$parent => []];
|
||||
|
||||
foreach ($hashMap[$parent] as $node) {
|
||||
yield spl_object_id($node) => $node;
|
||||
yield from $this->flatListGenerator($hashMap, $node);
|
||||
}
|
||||
}
|
||||
|
||||
private function buildChildrenHashmap(array $nodes): array
|
||||
{
|
||||
return array_reduce(
|
||||
$nodes,
|
||||
static function (array $collect, $node): array {
|
||||
$parentId = (null === $parent = $node->getParent()) ?
|
||||
null :
|
||||
spl_object_id($parent);
|
||||
|
||||
$collect[$parentId][] = $node;
|
||||
|
||||
return $collect;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -3,8 +3,12 @@
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Chill\MainBundle\Doctrine\ORM\Hydration\FlatHierarchyEntityHydrator;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SocialIssueApiController extends ApiController
|
||||
{
|
||||
@ -16,6 +20,25 @@ class SocialIssueApiController extends ApiController
|
||||
$query->expr()->isNull('e.desactivationDate')
|
||||
)
|
||||
);
|
||||
$query->setParameter('now', new \DateTimeImmutable());
|
||||
$query->setParameter('now', new DateTimeImmutable());
|
||||
}
|
||||
|
||||
protected function getQueryResult(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query)
|
||||
{
|
||||
// In order to work, this hydrator only works with
|
||||
// entities having the field "children" set up.
|
||||
return $query
|
||||
->getQuery()
|
||||
->setHint(Query::HINT_INCLUDE_META_COLUMNS, true)
|
||||
->getResult(FlatHierarchyEntityHydrator::LIST);
|
||||
}
|
||||
|
||||
protected function onPostIndexBuildQuery(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query): ?Response
|
||||
{
|
||||
$query
|
||||
->orderBy("GET_JSON_FIELD_BY_KEY(e.title, :locale)", 'ASC')
|
||||
->setParameter(':locale', $request->getLocale());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user