diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/HouseholdMemberSelectionContext.php b/src/Bundle/ChillDocGeneratorBundle/Context/HouseholdMemberSelectionContext.php index a7a539227..689360d65 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/HouseholdMemberSelectionContext.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/HouseholdMemberSelectionContext.php @@ -3,6 +3,7 @@ namespace Chill\DocGeneratorBundle\Context; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\SocialWork\SocialAction; /** @@ -21,11 +22,22 @@ class HouseholdMemberSelectionContext implements DocGeneratorContextInterface * Generate the form that display */ public function getForm($entity) { - // TODO Get FormFactory and create a form + 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(); + } + } - // access to the house hold for the AccompanyingPeriod pr the SocialAction - // and configure the form to select member of the family + $builder->add('members', ChoiceType::class, [ + 'choices' => $choices, + 'placeholder' => 'Choose a person', + 'label' => 'Person to add' + ]); + + return $builder; } /** @@ -41,17 +53,26 @@ class HouseholdMemberSelectionContext implements DocGeneratorContextInterface * Get the data that will be injected to the generated document */ public function getData($entity): array { - $ret = []; + $datas = array( + 'setValue' => array(), + 'cloneRowAndSetValues' => array() + ); // TODO CREER UNE CLASSE POUR CA - if(get_class($entity) == AccompanyingPeriod::class) { - // TODO mettre ça dans un service - $ret = ['AccompanyingPeriod' => $entity]; - } elseif(get_class($entity) == SocialAction::class) { - $ret = ['SocialAction' => $entity]; + if(get_class($entity) == AccompanyingPeriodWorkEvaluation::class) { + $values = array(); + foreach($entity->getAccompanyingPeriodWork()->getPersons() as $person) { + $i = 1; + $values[] = array( + 'personRowId' => $i, + 'personFirstName' => $person->getFirstName(), + 'personLastName' => $person->getLastName(), + ); + } + + $datas['cloneRowAndSetValues'][] = array( + 'personRowId', $values); } - // TODO AJOUTER LES DONNES DU FORMULAIRE - - return $ret; + return $datas; } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index 62093c065..56cc5c8da 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -68,14 +68,17 @@ class DocGeneratorTemplateController extends AbstractController if ($template->getContext() == HouseholdMemberSelectionContext::class) { $context = new HouseholdMemberSelectionContext(); - // $datas = $context->getData($entity); - $datas = []; + $datas = $context->getData($entity); } else { throw new \Exception("Not implemented", 1); } $templateProcessor = new TemplateProcessor($tmpfname); - $templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe')); + + // TODO foreach ($datas['setValue'] as $key => $value) { + foreach ($datas['cloneRowAndSetValues'] as $cloneRowAndSetValues) { + $templateProcessor->cloneRowAndSetValues($cloneRowAndSetValues[0], $cloneRowAndSetValues[1]); + } $tmpfname2 = tempnam(sys_get_temp_dir(), 'DOC_GENERATED'); $templateProcessor->saveAs($tmpfname2); diff --git a/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php b/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php index 0d5904865..06d26a446 100644 --- a/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php +++ b/src/Bundle/ChillDocGeneratorBundle/DataFixtures/ORM/LoadDocGeneratorTemplate.php @@ -24,9 +24,9 @@ class LoadDocGeneratorTemplate extends AbstractFixture [ 'name' => ['fr' => 'FORMULAIRE AEB'], 'desc' => 'stocké sur openstack comedienbe', - 'file' => 'FORMULAIRE_AEB.docx', + 'file' => 'FORMULAIRE_AEB_WITH_DATA_INJ.docx', 'context' => 'Chill\DocGeneratorBundle\Context\HouseholdMemberSelectionContext', - 'entities' => ['Chill\PersonBundle\Entity\AccompanyingPeriod', 'Chill\PersonBundle\Entity\SocialWork\SocialAction', AccompanyingPeriodWorkEvaluation::class], + 'entities' => [AccompanyingPeriodWorkEvaluation::class], ], [ 'name' => ['fr' => 'AIDE ALIMENTAIRE'], 'desc' => 'stocké sur openstack comedienbe', diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig index 07a5b5764..c601b8836 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/views/Admin/DocGeneratorTemplate/index.html.twig @@ -3,6 +3,7 @@ {% block layout_wvm_content %} {% embed '@ChillMain/CRUD/_index.html.twig' %} {% block table_entities_thead_tr %} + {{ 'Title'|trans }} {{ 'File'|trans }} {% endblock %} @@ -10,6 +11,7 @@ {% block table_entities_tbody %} {% for entity in entities %} + {{ entity.id }} {{ entity.name | localize_translatable_string }} {{ entity.file }}