diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index fadec8545..277202324 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -96,18 +96,16 @@ class ThirdParty /** * Contact Persons: One Institutional ThirdParty has Many Contact Persons - * @var ThirdParty * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent") */ - private $children; + private Collection $children; /** * Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty - * @var ThirdParty * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") */ - private $parent; + private ?ThirdParty $parent; /** * @var ThirdPartyCivility @@ -169,16 +167,14 @@ class ThirdParty private $centers; /** - * @var \DateTimeImmutable - * @ORM\Column(name="created_at", type="datetime", nullable=false) + * @ORM\Column(name="created_at", type="datetime_immutable", nullable=false) */ - private $createdAt; + private \DateTimeImmutable $createdAt; /** - * @var \DateTime * @ORM\Column(name="updated_at", type="datetime", nullable=true) */ - private $updatedAt; + private ?\DateTime $updatedAt; /** * @var User @@ -497,6 +493,11 @@ class ThirdParty return $this; } + public function isLeaf(): bool + { + return $this->children->count() !== 0; + } + /** * @return Collection */ @@ -526,18 +527,18 @@ class ThirdParty } /** - * @return ThirdParty + * @return ThirdParty|null */ - public function getParent(): ThirdParty + public function getParent(): ?ThirdParty { return $this->parent; } /** - * @param ThirdParty $parent + * @param ThirdParty|null $parent * @return $this */ - public function setParent(ThirdParty $parent): ThirdParty + public function setParent(?ThirdParty $parent): ThirdParty { $this->parent = $parent; return $this; @@ -598,9 +599,9 @@ class ThirdParty } /** - * @return \DateTime + * @return \DateTime|null */ - public function getUpdatedAt(): \DateTime + public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; } @@ -616,9 +617,9 @@ class ThirdParty } /** - * @return User + * @return User|null */ - public function getUpdatedBy(): User + public function getUpdatedBy(): ?User { return $this->updatedBy; } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index ccc9b8bf5..3248e7ff0 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -3,6 +3,11 @@ namespace Chill\ThirdPartyBundle\Form; use Chill\MainBundle\Form\Type\ChillTextareaType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory; +use Chill\ThirdPartyBundle\Entity\ThirdPartyCivility; +use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession; +use Doctrine\ORM\EntityRepository; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,32 +26,24 @@ use Chill\MainBundle\Form\Type\AddressType; class ThirdPartyType extends AbstractType { - /** - * - * @var AuthorizationHelper - */ - protected $authorizationHelper; + protected AuthorizationHelper $authorizationHelper; - /** - * - * @var TokenStorageInterface - */ - protected $tokenStorage; + protected TokenStorageInterface $tokenStorage; - /** - * - * @var ThirdPartyTypeManager - */ - protected $typesManager; + protected ThirdPartyTypeManager $typesManager; + + protected TranslatableStringHelper $translatableStringHelper; public function __construct( AuthorizationHelper $authorizationHelper, TokenStorageInterface $tokenStorage, - ThirdPartyTypeManager $typesManager + ThirdPartyTypeManager $typesManager, + TranslatableStringHelper $translatableStringHelper ) { $this->authorizationHelper = $authorizationHelper; $this->tokenStorage = $tokenStorage; $this->typesManager = $typesManager; + $this->translatableStringHelper = $translatableStringHelper; } /** @@ -60,26 +57,87 @@ class ThirdPartyType extends AbstractType } $builder + ->add('civility', EntityType::class, [ + 'label' => 'thirdparty.Civility', + 'class' => ThirdPartyCivility::class, + 'choice_label' => function (ThirdPartyCivility $civility) { + return $this->translatableStringHelper->localize($civility->getName()); + }, + 'query_builder' => function(EntityRepository $er) { + return $er->createQueryBuilder('c') + ->where('c.active = true'); + }, + 'placeholder' => 'thirdparty.choose civility', + 'required' => true + ]) + ->add('name', TextType::class, [ 'required' => true ]) - ->add('telephone', TextType::class, [ - 'label' => 'Phonenumber', + + ->add('nameCompany', TextType::class, [ + 'label' => 'thirdparty.NameCompany', 'required' => false ]) - ->add('email', EmailType::class, [ + + ->add('profession', EntityType::class, [ + 'label' => 'thirdparty.Profession', + 'class' => ThirdPartyProfession::class, + 'choice_label' => function (ThirdPartyProfession $profession) { + return $this->translatableStringHelper->localize($profession->getName()); + }, + 'query_builder' => function (EntityRepository $er) { + return $er->createQueryBuilder('p') + ->where('p.active = true'); + }, + 'placeholder' => 'thirdparty.choose profession', 'required' => false ]) - ->add('comment', ChillTextareaType::class, [ + + ->add('acronym', TextType::class, [ + 'label' => 'thirdparty.Acronym', 'required' => false ]) + + ->add('categories', EntityType::class, [ + 'label' => 'thirdparty.Categories', + 'class' => ThirdPartyCategory::class, + 'choice_label' => function (ThirdPartyCategory $category) { + return $this->translatableStringHelper->localize($category->getName()); + }, + 'query_builder' => function (EntityRepository $er) { + return $er->createQueryBuilder('c') + ->where('c.active = true'); + }, + 'required' => true, + 'multiple' => true, + 'attr' => ['class' => 'select2'] + ]) + ->add('type', ChoiceType::class, [ 'choices' => $types, 'expanded' => true, 'multiple' => true, 'label' => 'thirdparty.Type' ]) + + ->add('telephone', TextType::class, [ + 'label' => 'Phonenumber', + 'required' => false + ]) + + ->add('email', EmailType::class, [ + 'required' => false + ]) + + ->add('address', AddressType::class, [ + 'has_valid_from' => false, + 'null_if_empty' => true, + 'required' => false + ]) + ->add('active', ChoiceType::class, [ + 'label' => 'thirdparty.Status', 'choices' => [ 'Active, shown to users' => true, 'Inactive, not shown to users' => false @@ -87,18 +145,18 @@ class ThirdPartyType extends AbstractType 'expanded' => true, 'multiple' => false ]) + + ->add('comment', ChillTextareaType::class, [ + 'required' => false + ]) + ->add('centers', EntityType::class, [ 'choices' => $this->getReachableCenters($options), 'class' => \Chill\MainBundle\Entity\Center::class, 'multiple' => true, - 'expanded' => true + 'attr' => ['class' => 'select2'] ]) - ->add('address', AddressType::class, [ - 'has_valid_from' => false, - 'null_if_empty' => true, - 'required' => false - ]) - ; + ; } /** diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig index aa3f61088..ed23fb671 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/index.html.twig @@ -40,6 +40,9 @@