mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Build parts to track info on accompanying period
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user