, * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace Chill\ThirdPartyBundle\Entity; use Chill\MainBundle\Entity\User; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Chill\MainBundle\Entity\Center; use Symfony\Component\Validator\Constraints as Assert; use Chill\MainBundle\Entity\Address; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; /** * ThirdParty is a party recorded in the database. * * A party may be attached to multiple centers. Being attach to a center allow * all users with the right 'CHILL_3PARTY_3PARTY_SEE', 'CHILL_3PARTY_3 to see, select and edit parties for this * center. * * @ORM\Table(name="chill_3party.third_party") * @ORM\Entity(repositoryClass="Chill\ThirdPartyBundle\Repository\ThirdPartyRepository") * @DiscriminatorMap(typeProperty="type", mapping={ * "thirdparty"=ThirdParty::class * }) * @ORM\HasLifecycleCallbacks() */ class ThirdParty { /** * @var int * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * @ORM\Column(name="name", type="string", length=255) * @Assert\Length(min="2") * @Groups({"read", "write"}) */ private $name; /** * [fr] Raison sociale * @var string * @ORM\Column(name="name_company", type="string", length=255, nullable=true) * @Assert\Length(min="3") * @Groups({"read", "write"}) */ private $nameCompany; /** * [fr] Sigle * @var string * @ORM\Column(name="acronym", type="string", length=64, nullable=true) * @Assert\Length(min="2") * @Groups({"read", "write"}) */ private $acronym; /** * @var ThirdPartyCategory * @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyCategory") * @ORM\JoinTable(name="chill_3party.thirdparty_category", * joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}) */ private $categories; /** * @var array|null * @ORM\Column(name="types", type="json", nullable=true) * @Assert\Count(min=1) */ private $types; /** * Contact Persons: One Institutional ThirdParty has Many Contact Persons * @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent") */ private Collection $children; /** * Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") */ private ?ThirdParty $parent; /** * @var ThirdPartyCivility * @ORM\OneToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyCivility") * @ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true) */ private $civility; /** * [fr] Qualité * @var ThirdPartyProfession * @ORM\OneToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession") * @ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true) */ private $profession; /** * @var string|null * @ORM\Column(name="telephone", type="string", length=64, nullable=true) * @Assert\Regex("/^([\+{1}])([0-9\s*]{4,20})$/", * message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789" * ) * @Groups({"read", "write"}) */ private $telephone; /** * @var string|null * @ORM\Column(name="email", type="string", length=255, nullable=true) * @Assert\Email(checkMX=false) * @Groups({"read", "write"}) */ private $email; /** * @var Address|null * @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address", * cascade={"persist", "remove"}) * @ORM\JoinColumn(nullable=true, onDelete="SET NULL") * @Groups({"read", "write"}) */ private $address; /** * Soft-delete flag * @var boolean * @ORM\Column(name="active", type="boolean", options={"defaut": true}) */ private $active = true; /** * @var string|null * @ORM\Column(name="comment", type="text", nullable=true) */ private $comment; /** * @var Collection * @ORM\ManyToMany(targetEntity="\Chill\MainBundle\Entity\Center") * @ORM\JoinTable(name="chill_3party.party_center") */ private $centers; /** * @ORM\Column(name="created_at", type="datetime_immutable", nullable=false) */ private \DateTimeImmutable $createdAt; /** * @ORM\Column(name="updated_at", type="datetime", nullable=true) */ private ?\DateTime $updatedAt; /** * @var User * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") * @ORM\JoinColumn(name="updated_by", referencedColumnName="id") */ private $updatedBy; /** * @ORM\PrePersist() */ public function prePersist() { $this->createdAt = new \DateTimeImmutable(); } /** * @ORM\PreUpdate() */ public function preUpdate() { $this->updatedAt = new \DateTime(); } /** * ThirdParty constructor. */ public function __construct() { $this->centers = new ArrayCollection(); $this->categories = new ArrayCollection(); $this->children = new ArrayCollection(); } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Set name. * * @param string $name * @return ThirdParty */ public function setName($name) { $this->name = $name; return $this; } /** * Get name. * * @return string */ public function getName() { return $this->name; } /** * Set telephone. * * @param string|null $telephone * @return ThirdParty */ public function setTelephone($telephone = null) { $this->telephone = $telephone; return $this; } /** * Get telephone. * * @return string|null */ public function getTelephone() { return $this->telephone; } /** * Set email. * * @param string|null $email * @return ThirdParty */ public function setEmail($email = null) { $this->email = $email; return $this; } /** * Get email. * * @return string|null */ public function getEmail() { return $this->email; } /** * Set comment. * * @param string|null $comment * @return ThirdParty */ public function setComment($comment = null) { $this->comment = $comment; return $this; } /** * Get comment. * * @return string|null */ public function getComment() { return $this->comment; } /** * Set type. * * @param array|null $type * @return ThirdParty */ public function setTypes(array $type = null) { // remove all keys from the input data $this->type = \array_values($type); return $this; } /** * Get type. * * @return array|null */ public function getTypes() { return $this->types; } /** * @return bool */ public function getActive(): bool { return $this->active; } /** * @return Collection */ public function getCenters(): Collection { return $this->centers; } /** * @param bool $active * @return $this */ public function setActive(bool $active) { $this->active = $active; return $this; } /** * @param Center $center */ public function addCenter(Center $center) { if (FALSE === $this->centers->contains($center)) { $this->centers->add($center); } } /** * @param Center $center */ public function removeCenter(Center $center) { if ($this->centers->contains($center)) { $this->centers->removeElement($center); } } /** * @param Collection $centers * @return $this */ public function setCenters(Collection $centers) { foreach ($centers as $center) { $this->addCenter($center); } foreach ($this->centers as $center) { if (FALSE === $centers->contains($center)) { $this->removeCenter($center); } } return $this; } /** * @return Address|null */ public function getAddress(): ?Address { return $this->address; } /** * @param Address $address * @return $this */ public function setAddress(Address $address) { $this->address = $address; return $this; } /** * @return string */ public function __toString() { return $this->getName(); } /** * @return string|null */ public function getNameCompany(): ?string { return $this->nameCompany; } /** * @param string $nameCompany * @return ThirdParty */ public function setNameCompany(string $nameCompany): ThirdParty { $this->nameCompany = $nameCompany; return $this; } /** * @return string */ public function getAcronym(): ?string { return $this->acronym; } /** * @param string $acronym * @return $this */ public function setAcronym(string $acronym): ThirdParty { $this->acronym = $acronym; return $this; } /** * @return Collection */ public function getCategories(): Collection { return $this->categories; } /** * @param ThirdPartyCategory $category * @return $this */ public function addCategory(ThirdPartyCategory $category): self { $this->categories[] = $category; return $this; } /** * @param ThirdPartyCategory $category * @return $this */ public function removeCategory(ThirdPartyCategory $category): self { $this->categories->removeElement($category); return $this; } /** * Mechanism to differentiate children and parents */ public function isLeaf(): bool { return $this->children->count() !== 0; } /** * isLeaf aliases */ public function isChild():bool { return $this->isLeaf(); } public function isParent():bool { return !$this->isLeaf(); } /** * @return Collection */ public function getChildren(): Collection { return $this->children; } /** * @param ThirdParty $child * @return $this */ public function addChild(ThirdParty $child): self { $this->children[] = $child; return $this; } /** * @param ThirdParty $child * @return $this */ public function removeChild(ThirdParty $child): self { $this->children->removeElement($child); $this->active = false; return $this; } /** * @return ThirdParty|null */ public function getParent(): ?ThirdParty { return $this->parent; } /** * @param ThirdParty|null $parent * @return $this */ public function setParent(?ThirdParty $parent): ThirdParty { $this->parent = $parent; return $this; } /** * @return ThirdPartyCivility|null */ public function getCivility(): ?ThirdPartyCivility { return $this->civility; } /** * @param ThirdPartyCivility $civility * @return $this */ public function setCivility(ThirdPartyCivility $civility): ThirdParty { $this->civility = $civility; return $this; } /** * @return ThirdPartyProfession */ public function getProfession(): ?ThirdPartyProfession { return $this->profession; } /** * @param ThirdPartyProfession $profession * @return $this */ public function setProfession(ThirdPartyProfession $profession): ThirdParty { $this->profession = $profession; return $this; } /** * @return \DateTimeImmutable */ public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } /** * @param \DateTimeImmutable $createdAt * @return $this */ public function setCreatedAt(\DateTimeImmutable $createdAt): ThirdParty { $this->createdAt = $createdAt; return $this; } /** * @return \DateTime|null */ public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; } /** * @param \DateTime $updatedAt * @return $this */ public function setUpdatedAt(\DateTime $updatedAt): ThirdParty { $this->updatedAt = $updatedAt; return $this; } /** * @return User|null */ public function getUpdatedBy(): ?User { return $this->updatedBy; } /** * @param User $updatedBy * @return $this */ public function setUpdatedBy(User $updatedBy): ThirdParty { $this->updatedBy = $updatedBy; return $this; } }