Build parts to track info on accompanying period

This commit is contained in:
2023-04-18 21:16:40 +02:00
parent 7e3295c71f
commit f2e1c73f37
14 changed files with 459 additions and 0 deletions

View File

@@ -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(),
]
);
}
}

View File

@@ -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';
}
}

View File

@@ -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 '';
}
}

View File

@@ -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;
}

View File

@@ -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';
}
}