mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Adding context
This commit is contained in:
parent
8df4c93c97
commit
cbdf976885
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\DocGeneratorBundle\Context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for context for for document generation
|
||||||
|
*/
|
||||||
|
interface DocGeneratorContextInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* has form
|
||||||
|
*/
|
||||||
|
public function hasForm(): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the form that display
|
||||||
|
*/
|
||||||
|
public function getForm($entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True of false which entity supports
|
||||||
|
*/
|
||||||
|
public function supports(string $entityClass): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data that will be injected to the generated document
|
||||||
|
*/
|
||||||
|
public function getData($entity): array;
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\DocGeneratorBundle\Context;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context that display a form to select a member of a houseHold
|
||||||
|
*/
|
||||||
|
class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* has form
|
||||||
|
*/
|
||||||
|
public function hasForm(): bool {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the form that display
|
||||||
|
*/
|
||||||
|
public function getForm($entity) {
|
||||||
|
// TODO Get FormFactory and create a form
|
||||||
|
|
||||||
|
|
||||||
|
// access to the house hold for the AccompanyingPeriod pr the SocialAction
|
||||||
|
// and configure the form to select member of the family
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True of false which entity supports
|
||||||
|
*/
|
||||||
|
public function supports(string $entityClass): bool {
|
||||||
|
return
|
||||||
|
($entityClass == AccompanyingPeriod::class) ||
|
||||||
|
($entityClass == SocialAction::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data that will be injected to the generated document
|
||||||
|
*/
|
||||||
|
public function getData($entity): array {
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
if(get_class($entity) == AccompanyingPeriod::class) {
|
||||||
|
// TODO mettre ça dans un service
|
||||||
|
$ret = ['AccompanyingPeriod' => $entity];
|
||||||
|
} elseif(get_class($entity) == SocialAction::class) {
|
||||||
|
$ret = ['SocialAction' => $entity];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO AJOUTER LES DONNES DU FORMULAIRE
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
@ -23,11 +23,15 @@ class LoadDocGeneratorTemplate extends AbstractFixture
|
|||||||
[
|
[
|
||||||
'name' => ['fr' => 'FORMULAIRE AEB'],
|
'name' => ['fr' => 'FORMULAIRE AEB'],
|
||||||
'desc' => 'stocké sur openstack comedienbe',
|
'desc' => 'stocké sur openstack comedienbe',
|
||||||
'file' => 'FORMULAIRE_AEB.docx'
|
'file' => 'FORMULAIRE_AEB.docx',
|
||||||
|
'context' => 'Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext',
|
||||||
|
'entities' => ['Chill\PersonBundle\Entity\AccompanyingPeriod', 'Chill\PersonBundle\Entity\SocialWork\SocialAction'],
|
||||||
], [
|
], [
|
||||||
'name' => ['fr' => 'AIDE ALIMENTAIRE'],
|
'name' => ['fr' => 'AIDE ALIMENTAIRE'],
|
||||||
'desc' => 'stocké sur openstack comedienbe',
|
'desc' => 'stocké sur openstack comedienbe',
|
||||||
'file' => 'AIDE_ALIMENTAIRE.docx'
|
'file' => 'AIDE_ALIMENTAIRE.docx',
|
||||||
|
'context' => 'Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext',
|
||||||
|
'entities' => ['Chill\PersonBundle\Entity\AccompanyingPeriod', 'Chill\PersonBundle\Entity\SocialWork\SocialAction'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -39,6 +43,8 @@ class LoadDocGeneratorTemplate extends AbstractFixture
|
|||||||
->setName($template['name'])
|
->setName($template['name'])
|
||||||
->setDescription($template['desc'])
|
->setDescription($template['desc'])
|
||||||
->setFile($template['file'])
|
->setFile($template['file'])
|
||||||
|
->setContext($template['context'])
|
||||||
|
->setEntities($template['entities'])
|
||||||
;
|
;
|
||||||
|
|
||||||
$manager->persist($newTemplate);
|
$manager->persist($newTemplate);
|
||||||
|
@ -29,6 +29,28 @@ class DocGeneratorTemplate
|
|||||||
*/
|
*/
|
||||||
private string $description;
|
private string $description;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="simple_array")
|
||||||
|
*
|
||||||
|
* Class name of the entities for which this template can be used
|
||||||
|
*
|
||||||
|
* so if $entities = ['Chill\PersonBundle\Entity\AccompanyingPeriod', 'Chill\PersonBundle\Entity\SocialWork\SocialAction']
|
||||||
|
* this template can be selected for an AccompanyingPeriod or a SocialAction
|
||||||
|
*/
|
||||||
|
private array $entities = [];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=255)
|
||||||
|
*
|
||||||
|
* Class name of the context to use
|
||||||
|
*
|
||||||
|
* so if $context = ''
|
||||||
|
* this template will use '' as context
|
||||||
|
*/
|
||||||
|
private string $context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
*/
|
*/
|
||||||
@ -74,4 +96,28 @@ class DocGeneratorTemplate
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getEntities(): ?array
|
||||||
|
{
|
||||||
|
return $this->entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEntities(array $entities): self
|
||||||
|
{
|
||||||
|
$this->entities = $entities;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContext(): ?string
|
||||||
|
{
|
||||||
|
return $this->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContext(string $context): self
|
||||||
|
{
|
||||||
|
$this->context = $context;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\Migrations\DocGenerator;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add entities and context fields to DocGenTemplate
|
||||||
|
*/
|
||||||
|
final class Version20210812214310 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add entities and context fields to DocGenTemplate';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_docgen_template ADD entities TEXT');
|
||||||
|
$this->addSql('ALTER TABLE chill_docgen_template ADD context VARCHAR(255)');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_docgen_template.entities IS \'(DC2Type:simple_array)\'');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_docgen_template.name IS \'(DC2Type:json_array)\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_docgen_template DROP entities');
|
||||||
|
$this->addSql('ALTER TABLE chill_docgen_template DROP context');
|
||||||
|
$this->addSql('COMMENT ON COLUMN chill_docgen_template.name IS NULL');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user