From cbdf9768858f2051e2cd7f0bb56c39efcf8268e6 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 12 Aug 2021 23:55:01 +0200 Subject: [PATCH] Adding context --- .../Context/DocGeneratorContextInterface.php | 29 ++++++++++ .../HouseholdMemberSelectionContext.php | 57 +++++++++++++++++++ .../ORM/LoadDocGeneratorTemplate.php | 10 +++- .../Entity/DocGeneratorTemplate.php | 46 +++++++++++++++ .../migrations/Version20210812214310.php | 34 +++++++++++ 5 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextInterface.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Context/HouseholdMemberSelectionContext.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/migrations/Version20210812214310.php diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextInterface.php new file mode 100644 index 000000000..5d3cf349b --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextInterface.php @@ -0,0 +1,29 @@ + $entity]; + } elseif(get_class($entity) == SocialAction::class) { + $ret = ['SocialAction' => $entity]; + } + + // TODO AJOUTER LES DONNES DU FORMULAIRE + + return $ret; + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php b/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php index 3469e3820..ade47e307 100644 --- a/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php +++ b/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php @@ -23,11 +23,15 @@ class LoadDocGeneratorTemplate extends AbstractFixture [ 'name' => ['fr' => 'FORMULAIRE AEB'], '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'], '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']) ->setDescription($template['desc']) ->setFile($template['file']) + ->setContext($template['context']) + ->setEntities($template['entities']) ; $manager->persist($newTemplate); diff --git a/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php index 430042024..bf9c89839 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php +++ b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php @@ -29,6 +29,28 @@ class DocGeneratorTemplate */ 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) */ @@ -74,4 +96,28 @@ class DocGeneratorTemplate 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; + } } diff --git a/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210812214310.php b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210812214310.php new file mode 100644 index 000000000..c055bf428 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210812214310.php @@ -0,0 +1,34 @@ +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'); + } +}