diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 7a3c59668..5d7a4cc6e 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -85,6 +85,10 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface private ?string $nameCompany = ""; /** + * Canonicalized form composed of name, company name and acronym. + * + * This field is read-only, and is generated on database side. + * * @ORM\Column(name="canonicalized", type="text", options={"default":""}) */ private ?string $canonicalized = ""; @@ -116,7 +120,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface /** * Contact Persons: One Institutional ThirdParty has Many Contact Persons * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent", - * cascade={"persist"}) + * cascade={"persist"}, orphanRemoval=true) * @var ThirdParty[]|Collection * @Assert\Valid(traverse=true) */ @@ -319,6 +323,17 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface return $this->email; } + public function isContactDataAnonymous(): bool + { + return $this->contactDataAnonymous; + } + + public function setContactDataAnonymous(bool $contactDataAnonymous): ThirdParty + { + $this->contactDataAnonymous = $contactDataAnonymous; + return $this; + } + /** * Set comment. * @@ -570,6 +585,47 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface return $this->children; } + /** + * Get the children where active = true + * + * @return Collection + */ + public function getActiveChildren(): Collection + { + return $this->children->filter(fn (ThirdParty $tp) => $tp->getActive()); + } + + /** + * Add a child and set the child as active + * + * Method used in conjonction with getActiveChildren in form. + * + * @internal use the method addChild + * @param ThirdParty $child + * @return $this + */ + public function addActiveChild(ThirdParty $child): self + { + $child->setActive(true); + + return $this->addChild($child); + } + + /** + * mark the child as unactive, but keep the child existing in the + * database. To effectively remove the child, use removeChild instead. + * + * @param ThirdParty $child + * @return $this + */ + public function removeActiveChild(ThirdParty $child): self + { + $child->setActive(false); + + return $this; + } + + /** * @param ThirdParty $child * @return $this @@ -583,13 +639,17 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface } /** + * Remove the child from the database. + * + * If you want to keep the child into the database + * but desactivate it, use removeActiveChildren instead. + * * @param ThirdParty $child * @return $this */ public function removeChild(ThirdParty $child): self { $this->children->removeElement($child); - $child->setActive(false); return $this; } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index a0527a07e..64c9fabda 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -16,6 +16,7 @@ use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -138,6 +139,10 @@ class ThirdPartyType extends AbstractType 'placeholder' => 'thirdparty.choose profession', 'required' => false ]) + ->add('contactDataAnonymous', CheckboxType::class, [ + 'required' => false, + 'label' => 'thirdparty.Contact data are confidential' + ]) ; // Institutional ThirdParty (parent) @@ -165,12 +170,13 @@ class ThirdPartyType extends AbstractType 'multiple' => true, 'attr' => ['class' => 'select2'] ]) - ->add('children', ChillCollectionType::class, [ + ->add('activeChildren', ChillCollectionType::class, [ 'entry_type' => ThirdPartyType::class, 'entry_options' => [ 'is_child' => true, 'block_name' => 'children' ], + 'block_name' => 'active_children', 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig index b0968e7ad..38f1181e8 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/_form.html.twig @@ -23,7 +23,7 @@ {{ form_row(form.email) }}