mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[generic doc] add doc provider and renderer for evaluation document
This commit is contained in:
parent
2b5d007fda
commit
08874d734e
@ -73,7 +73,7 @@ class Manager
|
||||
): iterable {
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $origin);
|
||||
|
||||
$runSql = "{$sql} LIMIT ? OFFSET ?";
|
||||
$runSql = "{$sql} ORDER BY doc_date DESC LIMIT ? OFFSET ?";
|
||||
$runParams = [...$params, ...[$limit, $offset]];
|
||||
$runTypes = [...$types, ...[Types::INTEGER, Types::INTEGER]];
|
||||
|
||||
|
@ -63,9 +63,10 @@ class AccompanyingCourseDocumentProviderTest extends KernelTestCase
|
||||
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
|
||||
|
||||
$this->entityManager->getConnection()->executeQuery($sql, $params, $types);
|
||||
$nb = $this->entityManager->getConnection()->executeQuery('SELECT COUNT(*) FROM ('.$sql.') AS sq', $params, $types)
|
||||
->fetchOne();
|
||||
|
||||
self::assertTrue(true, "test that no errors occurs");
|
||||
self::assertIsInt($nb);
|
||||
}
|
||||
|
||||
public function provideSearchArguments(): iterable
|
||||
|
@ -0,0 +1,75 @@
|
||||
{% import "@ChillDocStore/Macro/macro.html.twig" as m %}
|
||||
{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %}
|
||||
{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %}
|
||||
|
||||
{% set w = document.accompanyingPeriodWorkEvaluation.accompanyingPeriodWork %}
|
||||
|
||||
<div class="item-bloc">
|
||||
<div class="item-row">
|
||||
<div class="item-col" style="width: unset">
|
||||
{% if document.storedObject.isPending %}
|
||||
<div class="badge text-bg-info" data-docgen-is-pending="{{ document.storedObject.id }}">{{ 'docgen.Doc generation is pending'|trans }}</div>
|
||||
{% elseif document.storedObject.isFailure %}
|
||||
<div class="badge text-bg-warning">{{ 'docgen.Doc generation failed'|trans }}</div>
|
||||
{% endif %}
|
||||
<div class="denomination h2">
|
||||
{{ document.title }}
|
||||
</div>
|
||||
{% if document.storedObject.type is not empty %}
|
||||
<div>
|
||||
{{ mm.mimeIcon(document.storedObject.type) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if document.storedObject.hasTemplate %}
|
||||
<div>
|
||||
<p>{{ document.storedObject.template.name|localize_translatable_string }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="item-col">
|
||||
<div class="container">
|
||||
<div class="dates row text-end">
|
||||
<span>{{ document.storedObject.createdAt|format_date('short') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item-row separator accompanying-course-work">
|
||||
<div class="item-col">
|
||||
<h2 class="badge-title">
|
||||
<span class="title_label"></span>
|
||||
<span class="title_action">{{ w.socialAction|chill_entity_render_string }} > {{ document.accompanyingPeriodWorkEvaluation.evaluation.title|localize_translatable_string }}
|
||||
</span>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="item-row separator">
|
||||
<div class="item-col item-meta">
|
||||
{{ mmm.createdBy(document) }}
|
||||
</div>
|
||||
<ul class="item-col record_actions flex-shrink-1">
|
||||
<li>
|
||||
{{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }}
|
||||
</li>
|
||||
{% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_EVALUATION_DOCUMENT_SHOW', document) %}
|
||||
<li>
|
||||
{{ document.storedObject|chill_document_button_group(document.title, is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', document.accompanyingPeriodWorkEvaluation.accompanyingPeriodWork)) }}
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_SEE', w)%}
|
||||
<li>
|
||||
<a href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_show', {'id': w.id, 'docId': document.id}) }}" class="btn btn-show"></a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', w) %}
|
||||
<li>
|
||||
<a href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', {'id': w.id, 'docId': document.id}) }}" class="btn btn-edit"></a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,105 @@
|
||||
<?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\GenericDoc\Providers;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final readonly class AccompanyingPeriodWorkEvaluationGenericDocProvider implements GenericDocForAccompanyingPeriodProviderInterface
|
||||
{
|
||||
public const KEY = 'accompanying_period_work_evaluation_document';
|
||||
|
||||
public function __construct(
|
||||
private Security $security,
|
||||
private EntityManagerInterface $entityManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument::class);
|
||||
$storedObjectMetadata = $this->entityManager->getClassMetadata(StoredObject::class);
|
||||
$evaluationMetadata = $this->entityManager->getClassMetadata(AccompanyingPeriod\AccompanyingPeriodWorkEvaluation::class);
|
||||
$accompanyingPeriodWorkMetadata = $this->entityManager->getClassMetadata(AccompanyingPeriod\AccompanyingPeriodWork::class);
|
||||
|
||||
$query = new FetchQuery(
|
||||
self::KEY,
|
||||
sprintf("jsonb_build_object('id', apwed.%s)", $classMetadata->getColumnName('id')),
|
||||
sprintf('apwed.'.$storedObjectMetadata->getColumnName('createdAt')),
|
||||
$classMetadata->getTableName().' AS apwed'
|
||||
);
|
||||
$query->addJoinClause(sprintf(
|
||||
'JOIN %s doc_store ON doc_store.%s = apwed.%s',
|
||||
$storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName(),
|
||||
$storedObjectMetadata->getColumnName('id'),
|
||||
$classMetadata->getSingleAssociationJoinColumnName('storedObject')
|
||||
));
|
||||
$query->addJoinClause(sprintf(
|
||||
'JOIN %s evaluation ON apwed.%s = evaluation.%s',
|
||||
$evaluationMetadata->getTableName(),
|
||||
$classMetadata->getAssociationMapping('accompanyingPeriodWorkEvaluation')['joinColumns'][0]['name'],
|
||||
$evaluationMetadata->getColumnName('id')
|
||||
));
|
||||
$query->addJoinClause(sprintf(
|
||||
'JOIN %s action ON evaluation.%s = action.%s',
|
||||
$accompanyingPeriodWorkMetadata->getTableName(),
|
||||
$evaluationMetadata->getAssociationMapping('accompanyingPeriodWork')['joinColumns'][0]['name'],
|
||||
$accompanyingPeriodWorkMetadata->getColumnName('id')
|
||||
));
|
||||
|
||||
$query->addWhereClause(
|
||||
sprintf('action.%s = ?', $accompanyingPeriodWorkMetadata->getAssociationMapping('accompanyingPeriod')['joinColumns'][0]['name']),
|
||||
[$accompanyingPeriod->getId()],
|
||||
[Types::INTEGER]
|
||||
);
|
||||
|
||||
if (null !== $startDate) {
|
||||
$query->addWhereClause(
|
||||
sprintf('doc_store.%s <= ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||
[$startDate],
|
||||
[Types::DATE_IMMUTABLE]
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $endDate) {
|
||||
$query->addWhereClause(
|
||||
sprintf('doc_store.%s > ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||
[$endDate],
|
||||
[Types::DATE_IMMUTABLE]
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $content) {
|
||||
$query->addWhereClause(
|
||||
sprintf('apwed.%s ilike ?', $classMetadata->getColumnName('title')),
|
||||
['%' . $content . '%'],
|
||||
[Types::STRING]
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
||||
{
|
||||
return $this->security->isGranted(AccompanyingPeriodWorkVoter::SEE, $accompanyingPeriod);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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\GenericDoc\Renderer;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||
use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
|
||||
use Chill\PersonBundle\Service\GenericDoc\Providers\AccompanyingPeriodWorkEvaluationGenericDocProvider;
|
||||
|
||||
final readonly class AccompanyingPeriodWorkEvaluationGenericDocRenderer implements GenericDocRendererInterface
|
||||
{
|
||||
public function __construct(
|
||||
private AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function supports(GenericDocDTO $genericDocDTO, $options = []): bool
|
||||
{
|
||||
return $genericDocDTO->key === AccompanyingPeriodWorkEvaluationGenericDocProvider::KEY;
|
||||
}
|
||||
|
||||
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
||||
{
|
||||
return '@ChillPerson/GenericDoc/evaluation_document.html.twig';
|
||||
}
|
||||
|
||||
public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array
|
||||
{
|
||||
return [
|
||||
'document' => $this->accompanyingPeriodWorkEvaluationDocumentRepository->find($genericDocDTO->identifiers['id'])
|
||||
];
|
||||
}
|
||||
}
|
@ -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 Service\GenericDoc\Providers;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryToSqlBuilder;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Service\GenericDoc\Providers\AccompanyingPeriodWorkEvaluationGenericDocProvider;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class AccompanyingPeriodWorkEvaluationGenericDocProviderTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSearchArguments
|
||||
*/
|
||||
public function testBuildFetchQueryForAccompanyingPeriod(
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null
|
||||
): void {
|
||||
$period = $this->entityManager->createQuery("SELECT a FROM " . AccompanyingPeriod::class . ' a')
|
||||
->setMaxResults(1)
|
||||
->getSingleResult();
|
||||
|
||||
if (null === $period) {
|
||||
throw new \RuntimeException('no accompanying period in databasee');
|
||||
}
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
|
||||
$provider = new AccompanyingPeriodWorkEvaluationGenericDocProvider(
|
||||
$security->reveal(),
|
||||
$this->entityManager
|
||||
);
|
||||
|
||||
$query = $provider->buildFetchQueryForAccompanyingPeriod($period, $startDate, $endDate, $content);
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
|
||||
|
||||
$nb = $this->entityManager->getConnection()->executeQuery(
|
||||
'SELECT COUNT(*) FROM ('.$sql.') AS sq',
|
||||
$params,
|
||||
$types
|
||||
)->fetchOne();
|
||||
|
||||
self::assertIsInt($nb, "Test that there are no errors");
|
||||
}
|
||||
|
||||
public function provideSearchArguments(): iterable
|
||||
{
|
||||
yield [null, null, null];
|
||||
yield [new \DateTimeImmutable('1 month ago'), null, null];
|
||||
yield [new \DateTimeImmutable('1 month ago'), new \DateTimeImmutable('now'), null];
|
||||
yield [null, null, 'test'];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user