mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 07:33:50 +00:00
move logic of context to different interfaces
This commit is contained in:
@@ -13,26 +13,12 @@ namespace Chill\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Interface for context for document generation.
|
||||
*/
|
||||
interface DocGeneratorContextInterface
|
||||
{
|
||||
public function adminFormReverseTransform(array $data): array;
|
||||
|
||||
public function adminFormTransform(array $data): array;
|
||||
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void;
|
||||
|
||||
/**
|
||||
* Generate the form that display.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
|
||||
|
||||
/**
|
||||
* Get the data that will be injected to the generated document.
|
||||
*
|
||||
@@ -48,14 +34,5 @@ interface DocGeneratorContextInterface
|
||||
|
||||
public function getName(): string;
|
||||
|
||||
public function hasAdminForm(): bool;
|
||||
|
||||
/**
|
||||
* has form.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
<?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\DocGeneratorBundle\Context;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
interface DocGeneratorContextWithAdminFormInterface
|
||||
{
|
||||
public function adminFormReverseTransform(array $data): array;
|
||||
|
||||
public function adminFormTransform(array $data): array;
|
||||
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void;
|
||||
|
||||
public function hasAdminForm(): bool;
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
<?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\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
interface DocGeneratorContextWithPublicFormInterface
|
||||
{
|
||||
/**
|
||||
* Generate the form that display.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
|
||||
|
||||
/**
|
||||
* has form.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
<?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\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use function count;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* Context that display a form to select a member of a houseHold.
|
||||
*/
|
||||
class HouseholdMemberSelectionContext //implements DocGeneratorContextInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data that will be injected to the generated document.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function getData($entity): array
|
||||
{
|
||||
$datas = [
|
||||
'setValues' => [],
|
||||
'cloneRowAndSetValues' => [],
|
||||
];
|
||||
|
||||
$persons = $entity->getAccompanyingPeriodWork()->getPersons();
|
||||
|
||||
if (count($persons) > 0) {
|
||||
$firstPerson = $persons[0];
|
||||
|
||||
$datas['setValues'][] = [
|
||||
'firstPersonFirstName' => $firstPerson->getFirstName(),
|
||||
'firstPersonLastName' => $firstPerson->getLastName(), ];
|
||||
}
|
||||
|
||||
if (get_class($entity) === AccompanyingPeriodWorkEvaluation::class) {
|
||||
$values = [];
|
||||
|
||||
foreach ($entity->getAccompanyingPeriodWork()->getPersons() as $person) {
|
||||
$i = 1;
|
||||
$values[] = [
|
||||
'personRowId' => $i,
|
||||
'personFirstName' => $person->getFirstName(),
|
||||
'personLastName' => $person->getLastName(),
|
||||
];
|
||||
}
|
||||
|
||||
$datas['cloneRowAndSetValues'][] = [
|
||||
'personRowId', $values, ];
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the form that display.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function getForm($entity)
|
||||
{
|
||||
throw new Exception('No implemented yet', 1);
|
||||
$choices = [];
|
||||
|
||||
if (get_class($entity) === AccompanyingPeriodWorkEvaluation::class) {
|
||||
foreach ($entity->getAccompanyingPeriodWork()->getPersons() as $person) {
|
||||
$choices[$person->getId()] = $person->getName();
|
||||
}
|
||||
}
|
||||
|
||||
$builder->add('members', ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'placeholder' => 'Choose a person',
|
||||
'label' => 'Person to add',
|
||||
]);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public static function getKey(): string
|
||||
{
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'household member';
|
||||
}
|
||||
|
||||
/**
|
||||
* has form.
|
||||
*/
|
||||
public function hasForm(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity): void
|
||||
{
|
||||
// Only for evaluation
|
||||
if ($entity instanceof AccompanyingPeriodWorkEvaluation) {
|
||||
$doc = new AccompanyingPeriodWorkEvaluationDocument();
|
||||
$doc
|
||||
->setStoredObject($storedObject)
|
||||
->setTemplate($template);
|
||||
$entity->addDocument($doc);
|
||||
$this->em->persist($doc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True of false which entity supports.
|
||||
*/
|
||||
public function supports(string $entityClass): bool
|
||||
{
|
||||
return
|
||||
(AccompanyingPeriod::class === $entityClass)
|
||||
|| (SocialAction::class === $entityClass);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user