mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Build parts to track info on accompanying period
This commit is contained in:
parent
7e3295c71f
commit
f2e1c73f37
@ -30,6 +30,7 @@ use Chill\MainBundle\Search\SearchApiInterface;
|
||||
use Chill\MainBundle\Security\ProvideRoleInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverInterface;
|
||||
use Chill\MainBundle\Security\Resolver\ScopeResolverInterface;
|
||||
use Chill\MainBundle\Service\EntityInfo\ViewEntityInfoProviderInterface;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
||||
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
||||
@ -62,6 +63,8 @@ class ChillMainBundle extends Bundle
|
||||
->addTag('chill_main.workflow_handler');
|
||||
$container->registerForAutoconfiguration(CronJobInterface::class)
|
||||
->addTag('chill_main.cron_job');
|
||||
$container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class)
|
||||
->addTag('chill_main.entity_info_provider');
|
||||
|
||||
$container->addCompilerPass(new SearchableServicesCompilerPass());
|
||||
$container->addCompilerPass(new ConfigConsistencyCompilerPass());
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Command;
|
||||
|
||||
use Chill\MainBundle\Service\EntityInfo\ViewEntityInfoManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class SynchronizeEntityInfoViewsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private ViewEntityInfoManager $viewEntityInfoManager,
|
||||
) {
|
||||
parent::__construct('chill:db:sync-views');
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDescription('Update or create sql views which provide info for various entities');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->viewEntityInfoManager->synchronizeOnDB();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\EntityInfo;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class ViewEntityInfoManager
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var ViewEntityInfoProviderInterface[]
|
||||
*/
|
||||
private iterable $vienEntityInfoProviders,
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
public function synchronizeOnDB(): void
|
||||
{
|
||||
$this->connection->transactional(function (Connection $conn): void {
|
||||
foreach ($this->vienEntityInfoProviders as $viewProvider) {
|
||||
foreach ($this->createOrReplaceViewSQL($viewProvider, $viewProvider->getViewName()) as $sql) {
|
||||
$conn->executeQuery($sql);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
private function createOrReplaceViewSQL(ViewEntityInfoProviderInterface $viewProvider, string $viewName): array
|
||||
{
|
||||
return [
|
||||
"DROP VIEW IF EXISTS {$viewName}",
|
||||
sprintf("CREATE VIEW {$viewName} AS %s", $viewProvider->getViewQuery())
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Service\EntityInfo;
|
||||
|
||||
interface ViewEntityInfoProviderInterface
|
||||
{
|
||||
public function getViewQuery(): string;
|
||||
|
||||
public function getViewName(): string;
|
||||
}
|
@ -118,3 +118,7 @@ services:
|
||||
lazy: true
|
||||
arguments:
|
||||
$jobs: !tagged_iterator chill_main.cron_job
|
||||
|
||||
Chill\MainBundle\Service\EntityInfo\ViewEntityInfoManager:
|
||||
arguments:
|
||||
$vienEntityInfoProviders: !tagged_iterator chill_main.entity_info_provider
|
||||
|
@ -67,3 +67,7 @@ services:
|
||||
autowire: true
|
||||
tags:
|
||||
- {name: console.command }
|
||||
|
||||
Chill\MainBundle\Command\SynchronizeEntityInfoViewsCommand:
|
||||
tags:
|
||||
- {name: console.command}
|
||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle;
|
||||
|
||||
use Chill\PersonBundle\DependencyInjection\CompilerPass\AccompanyingPeriodTimelineCompilerPass;
|
||||
use Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoUnionQueryPartInterface;
|
||||
use Chill\PersonBundle\Widget\PersonListWidgetFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
@ -26,5 +27,7 @@ class ChillPersonBundle extends Bundle
|
||||
->addWidgetFactory(new PersonListWidgetFactory());
|
||||
|
||||
$container->addCompilerPass(new AccompanyingPeriodTimelineCompilerPass());
|
||||
$container->registerForAutoconfiguration(AccompanyingPeriodInfoUnionQueryPartInterface::class)
|
||||
->addTag('chill_person.accompanying_period_info_part');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Informations about AccompanyingPeriod
|
||||
*
|
||||
* This entity allow access to some basic information about the AccompanyingPeriod. It is
|
||||
* populated from a SQL view, dynamically build from various sources.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* - get the user involved with an accompanying period
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="view_chill_person_accompanying_period_info")
|
||||
*/
|
||||
class AccompanyingPeriodInfo
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var AccompanyingPeriod
|
||||
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
||||
*/
|
||||
public readonly AccompanyingPeriod $accompanyingPeriod,
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="text")
|
||||
* @ORM\Id
|
||||
*/
|
||||
public readonly string $relatedEntity,
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Id
|
||||
*/
|
||||
public readonly int $relatedEntityId,
|
||||
|
||||
/**
|
||||
* @var User
|
||||
* @ORM\ManyToOne(targetEntity=User::class)
|
||||
*/
|
||||
public readonly ?User $user,
|
||||
|
||||
/**
|
||||
* @var \DateTimeImmutable
|
||||
* @ORM\Column(type="datetime_immutable")
|
||||
*/
|
||||
public readonly \DateTimeImmutable $infoDate,
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
public readonly array $metadata,
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
public readonly string $discriminator,
|
||||
) {
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\EntityInfo;
|
||||
|
||||
/**
|
||||
* Build a list of different Query parts into a single query
|
||||
*/
|
||||
class AccompanyingPeriodInfoQueryBuilder
|
||||
{
|
||||
private const BASE_QUERY = <<<'SQL'
|
||||
SELECT
|
||||
{period_id_column} AS accompanyingperiod_id,
|
||||
'{related_entity_column_id}' AS relatedentity,
|
||||
{related_entity_id_column_id} AS relatedentityid,
|
||||
{user_id} AS user_id,
|
||||
{datetime} AS infodate,
|
||||
'{discriminator}' AS discriminator,
|
||||
{metadata} AS metadata
|
||||
FROM {from_statement}
|
||||
{where_statement}
|
||||
SQL;
|
||||
|
||||
public function buildQuery(AccompanyingPeriodInfoUnionQueryPartInterface $query): string
|
||||
{
|
||||
return strtr(
|
||||
self::BASE_QUERY,
|
||||
[
|
||||
'{period_id_column}' => $query->getAccompanyingPeriodIdColumn(),
|
||||
'{related_entity_column_id}' => $query->getRelatedEntityColumn(),
|
||||
'{related_entity_id_column_id}' => $query->getRelatedEntityIdColumn(),
|
||||
'{user_id}' => $query->getUserIdColumn(),
|
||||
'{datetime}' => $query->getDateTimeColumn(),
|
||||
'{discriminator}' => $query->getDiscriminator(),
|
||||
'{metadata}' => $query->getMetadataColumn(),
|
||||
'{from_statement}' => $query->getFromStatement(),
|
||||
'{where_statement}' => '' === $query->getWhereClause() ? '' : 'WHERE '.$query->getWhereClause(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoQueryPart;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoUnionQueryPartInterface;
|
||||
|
||||
class AccompanyingPeriodWorkEndQueryPartForAccompanyingPeriodInfo implements AccompanyingPeriodInfoUnionQueryPartInterface
|
||||
{
|
||||
public function getAccompanyingPeriodIdColumn(): string
|
||||
{
|
||||
return 'w.accompanyingperiod_id';
|
||||
}
|
||||
|
||||
public function getRelatedEntityColumn(): string
|
||||
{
|
||||
return AccompanyingPeriodWork::class;
|
||||
}
|
||||
|
||||
public function getRelatedEntityIdColumn(): string
|
||||
{
|
||||
return 'w.id';
|
||||
}
|
||||
|
||||
public function getUserIdColumn(): string
|
||||
{
|
||||
return 'cpapwr.user_id';
|
||||
}
|
||||
|
||||
public function getDateTimeColumn(): string
|
||||
{
|
||||
return 'w.endDate';
|
||||
}
|
||||
|
||||
public function getMetadataColumn(): string
|
||||
{
|
||||
return "'{}'::jsonb";
|
||||
}
|
||||
|
||||
public function getDiscriminator(): string
|
||||
{
|
||||
return 'accompanying_period_work_end';
|
||||
}
|
||||
|
||||
public function getFromStatement(): string
|
||||
{
|
||||
return 'chill_person_accompanying_period_work w
|
||||
LEFT JOIN chill_person_accompanying_period_work_referrer cpapwr on w.id = cpapwr.accompanyingperiodwork_id';
|
||||
}
|
||||
|
||||
public function getWhereClause(): string
|
||||
{
|
||||
return 'w.endDate IS NOT NULL';
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoQueryPart;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodInfoUnionQueryPartInterface;
|
||||
|
||||
class AccompanyingPeriodWorkStartQueryPartForAccompanyingPeriodInfo implements AccompanyingPeriodInfoUnionQueryPartInterface
|
||||
{
|
||||
public function getAccompanyingPeriodIdColumn(): string
|
||||
{
|
||||
return 'w.accompanyingperiod_id';
|
||||
}
|
||||
|
||||
public function getRelatedEntityColumn(): string
|
||||
{
|
||||
return AccompanyingPeriodWork::class;
|
||||
}
|
||||
|
||||
public function getRelatedEntityIdColumn(): string
|
||||
{
|
||||
return 'w.id';
|
||||
}
|
||||
|
||||
public function getUserIdColumn(): string
|
||||
{
|
||||
return 'cpapwr.user_id';
|
||||
}
|
||||
|
||||
public function getDateTimeColumn(): string
|
||||
{
|
||||
return 'w.startDate';
|
||||
}
|
||||
|
||||
public function getMetadataColumn(): string
|
||||
{
|
||||
return "'{}'::jsonb";
|
||||
}
|
||||
|
||||
public function getDiscriminator(): string
|
||||
{
|
||||
return 'accompanying_period_work_start';
|
||||
}
|
||||
|
||||
public function getFromStatement(): string
|
||||
{
|
||||
return 'chill_person_accompanying_period_work w
|
||||
LEFT JOIN chill_person_accompanying_period_work_referrer cpapwr on w.id = cpapwr.accompanyingperiodwork_id';
|
||||
}
|
||||
|
||||
public function getWhereClause(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\EntityInfo;
|
||||
|
||||
interface AccompanyingPeriodInfoUnionQueryPartInterface
|
||||
{
|
||||
public function getAccompanyingPeriodIdColumn(): string;
|
||||
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
public function getRelatedEntityColumn(): string;
|
||||
|
||||
public function getRelatedEntityIdColumn(): string;
|
||||
|
||||
public function getUserIdColumn(): string;
|
||||
|
||||
public function getDateTimeColumn(): string;
|
||||
|
||||
public function getDiscriminator(): string;
|
||||
|
||||
public function getMetadataColumn(): string;
|
||||
|
||||
public function getFromStatement(): string;
|
||||
|
||||
public function getWhereClause(): string;
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\EntityInfo;
|
||||
|
||||
use Chill\MainBundle\Service\EntityInfo\ViewEntityInfoProviderInterface;
|
||||
|
||||
class AccompanyingPeriodViewEntityInfoProvider implements ViewEntityInfoProviderInterface
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var AccompanyingPeriodInfoUnionQueryPartInterface[]
|
||||
*/
|
||||
private iterable $unions,
|
||||
private AccompanyingPeriodInfoQueryBuilder $builder,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getViewQuery(): string
|
||||
{
|
||||
return implode(
|
||||
' UNION ',
|
||||
array_map(
|
||||
fn (AccompanyingPeriodInfoUnionQueryPartInterface $part) => $this->builder->buildQuery($part),
|
||||
iterator_to_array($this->unions)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getViewName(): string
|
||||
{
|
||||
return 'view_chill_person_accompanying_period_info';
|
||||
}
|
||||
}
|
@ -98,3 +98,7 @@ services:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
resource: '../Workflow/'
|
||||
|
||||
Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodViewEntityInfoProvider:
|
||||
arguments:
|
||||
$unions: !tagged_iterator chill_person.accompanying_period_info_part
|
||||
|
Loading…
x
Reference in New Issue
Block a user