diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 6db871e5b..799967c82 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -11,30 +11,50 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; +use Chill\PersonBundle\Entity\Person\PersonResource; use Chill\PersonBundle\Form\PersonResourceType; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonResourceRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; final class PersonResourceController extends AbstractController { private PersonResourceRepository $personResourceRepository; + private PersonRepository $personRepository; + private EntityManagerInterface $em; public function __construct( PersonResourceRepository $personResourceRepository, - PersonRepository $personRepository + PersonRepository $personRepository, + EntityManagerInterface $em ) { $this->personResourceRepository = $personResourceRepository; $this->personRepository = $personRepository; + $this->em = $em; } - public function listAction($person_id) + public function listAction(Request $request, $person_id) { $person = $this->personRepository->find($person_id); + $personResource = new PersonResource(); $form = $this->createForm(PersonResourceType::class); + $form->handleRequest($request); + + if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { + $this->em->persist($personResource); + $this->em->flush(); + + return $this->redirectToRoute( + 'chill_person_resource', + ['person_id' => $person->getId()] + ); + } + return $this->render( 'ChillPersonBundle:PersonResource:list.html.twig', [ diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php index 03b2aa858..619382f68 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php @@ -31,7 +31,7 @@ class PersonResourceKind /** * @ORM\Column(type="json", length=255) */ - private array $label; + private array $title; /** * @ORM\Column(type="boolean") @@ -48,14 +48,14 @@ class PersonResourceKind return $this->isActive; } - public function getLabel(): ?array + public function getTitle(): ?array { - return $this->label; + return $this->title; } - public function setLabel(array $label): self + public function setTitle(array $title): self { - $this->label = $label; + $this->title = $title; return $this; } diff --git a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php index 8863d705c..fabc30e5e 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php @@ -13,8 +13,12 @@ namespace Chill\PersonBundle\Form; use Chill\AsideActivityBundle\Templating\Entity\CategoryRender; use Chill\MainBundle\Form\Type\ChillTextareaType; +use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\PersonResource; use Chill\PersonBundle\Entity\Person\PersonResourceKind; +use Chill\PersonBundle\Templating\Entity\PersonRender; +use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; @@ -26,10 +30,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; final class PersonResourceType extends AbstractType { private CategoryRender $categoryRender; + private PersonRender $personRender; + private ThirdPartyRender $thirdPartyRender; - public function __construct(CategoryRender $categoryRender) + public function __construct(CategoryRender $categoryRender, PersonRender $personRender, ThirdPartyRender $thirdPartyRender) { $this->categoryRender = $categoryRender; + $this->personRender = $personRender; + $this->thirdPartyRender = $thirdPartyRender; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -58,6 +66,28 @@ final class PersonResourceType extends AbstractType 'expanded' => true, 'label' => 'Associer un' ]) + ->add('person', EntityType::class, [ + 'label' => 'Usager', + 'class' => Person::class, + 'required' => false, + 'choice_label' => function (Person $person) { + $options = []; + return $this->personRender->renderString($person, $options); + } + ]) + ->add('thirdparty', EntityType::class, [ + 'label' => 'Tiers', + 'class' => ThirdParty::class, + 'required' => false, + 'choice_label' => function (ThirdParty $thirdParty) { + $options = []; + return $this->thirdPartyRender->renderString($thirdParty, $options); + } + ]) + ->add('freetext', ChillTextareaType::class, [ + 'label' => 'Description libre', + 'required' => false + ]) ->add('comment', ChillTextareaType::class, [ 'label' => 'Note', 'required' => false @@ -71,9 +101,9 @@ final class PersonResourceType extends AbstractType ]); } - // public function getBlockPrefix(): string - // { - // return 'chill_personbundle_personresource'; - // } + public function getBlockPrefix(): string + { + return 'chill_personbundle_person_resource'; + } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js b/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js new file mode 100644 index 000000000..8ef2021f1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js @@ -0,0 +1,33 @@ +import {ShowHide} from 'ChillMainAssets/lib/show_hide/show_hide.js'; + +window.addEventListener('DOMContentLoaded', function() { + let + linkedEntityContainer = document.querySelector('#linked-entity'), + personContainer = document.querySelector('#person-entity'), + thirdpartyContainer = document.querySelector('#thirdparty-entity'), + freetextContainer = document.querySelector('#freetext-entity') + ; + + if (null === linkedEntityContainer) { + return; + } + + new ShowHide({ + debug: true, + load_event: null, + froms: [linkedEntityContainer], + container: [personContainer, thirdpartyContainer, freetextContainer], + test: function(containers, arg2, arg3) { + for (let container of containers) { + for (let input of container.querySelectorAll('input')) { + if (!input.checked) { + return true; + } else { + return false; + } + } + } + + }, + }) +}); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig index 9ba297d8b..74bdeb57e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig @@ -6,7 +6,19 @@ {{ form_row(form.kind) }} - {{ form_row(form.linkedEntity) }} +