mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add basic context for AccompanyingPeriodWorkEvalution WIP
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationContext implements
|
||||
DocGeneratorContextWithAdminFormInterface,
|
||||
DocGeneratorContextWithPublicFormInterface
|
||||
{
|
||||
private AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private EvaluationRepository $evaluationRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext,
|
||||
EntityManagerInterface $em,
|
||||
EvaluationRepository $evaluationRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext;
|
||||
$this->em = $em;
|
||||
$this->evaluationRepository = $evaluationRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function adminFormReverseTransform(array $data): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->accompanyingPeriodWorkContext->adminFormReverseTransform($data),
|
||||
[
|
||||
'evaluations' => array_map(
|
||||
static function (Evaluation $e) { return $e->getId(); },
|
||||
$data['evaluations']
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function adminFormTransform(array $data): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->accompanyingPeriodWorkContext->adminFormTransform($data),
|
||||
[
|
||||
'evaluations' => array_map(
|
||||
function ($id) { return $this->evaluationRepository->find($id); },
|
||||
$data['evaluations'] ?? []
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$this->accompanyingPeriodWorkContext->buildAdminForm($builder);
|
||||
|
||||
$builder->remove('category');
|
||||
|
||||
$builder->add('evaluations', EntityType::class, [
|
||||
'class' => Evaluation::class,
|
||||
'label' => 'Linked evaluations',
|
||||
'choices' => $this->evaluationRepository->findAll(),
|
||||
'choice_label' => function (Evaluation $e) {
|
||||
return $this->translatableStringHelper->localize($e->getTitle());
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
// TODO: Implement buildPublicForm() method.
|
||||
}
|
||||
|
||||
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
|
||||
{
|
||||
// TODO: Implement getData() method.
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Context for accompanying period work';
|
||||
}
|
||||
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return AccompanyingPeriodWorkEvaluation::class;
|
||||
}
|
||||
|
||||
public static function getKey(): string
|
||||
{
|
||||
return 'accompanying_period_work_evaluation_regular';
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Accompanying period work context';
|
||||
}
|
||||
|
||||
public function hasAdminForm(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
|
||||
{
|
||||
// TODO: Implement hasPublicForm() method.
|
||||
}
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
|
||||
{
|
||||
$doc = new AccompanyingPeriodWorkEvaluationDocument();
|
||||
$doc->setStoredObject($storedObject)
|
||||
->setAccompanyingPeriodWorkEvaluation($entity)
|
||||
->setTemplate($template);
|
||||
$this->em->persist($doc);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user