mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
various improvements on 3party
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
|
||||
namespace Chill\ThirdPartyBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@@ -31,6 +34,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
|
||||
|
||||
/**
|
||||
* ThirdParty is a party recorded in the database.
|
||||
@@ -39,14 +43,13 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||
* 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
|
||||
* @ORM\Table(name="chill_3party.third_party")
|
||||
* @DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "thirdparty"=ThirdParty::class
|
||||
* })
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
class ThirdParty
|
||||
class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
@@ -54,7 +57,15 @@ class ThirdParty
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
private ?int $id = null;
|
||||
|
||||
const KIND_CONTACT = 'contact';
|
||||
const KIND_COMPANY = 'company';
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="kind", type="string", length="20", options={"default":""})
|
||||
*/
|
||||
private ?string $kind = "";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -62,7 +73,7 @@ class ThirdParty
|
||||
* @Assert\Length(min="2")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $name;
|
||||
private ?string $name = "";
|
||||
|
||||
/**
|
||||
* [fr] Raison sociale
|
||||
@@ -71,7 +82,12 @@ class ThirdParty
|
||||
* @Assert\Length(min="3")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $nameCompany;
|
||||
private ?string $nameCompany = "";
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="canonicalized", type="text", options={"default":""})
|
||||
*/
|
||||
private ?string $canonicalized = "";
|
||||
|
||||
/**
|
||||
* [fr] Sigle
|
||||
@@ -80,7 +96,7 @@ class ThirdParty
|
||||
* @Assert\Length(min="2")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $acronym;
|
||||
private ?string $acronym = "";
|
||||
|
||||
/**
|
||||
* @var ThirdPartyCategory
|
||||
@@ -89,18 +105,20 @@ class ThirdParty
|
||||
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
|
||||
*/
|
||||
private $categories;
|
||||
private Collection $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")
|
||||
* @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent",
|
||||
* cascade={"persist"})
|
||||
* @var ThirdParty[]|Collection
|
||||
* @Assert\Valid(traverse=true)
|
||||
*/
|
||||
private Collection $children;
|
||||
|
||||
@@ -108,23 +126,24 @@ class ThirdParty
|
||||
* 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")
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private ?ThirdParty $parent;
|
||||
|
||||
/**
|
||||
* @var ThirdPartyCivility
|
||||
* @ORM\OneToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyCivility")
|
||||
* @ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
|
||||
* @var Civility
|
||||
* @ORM\ManyToOne(targetEntity=Civility::class)
|
||||
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
private $civility;
|
||||
private ?Civility $civility;
|
||||
|
||||
/**
|
||||
* [fr] Qualité
|
||||
* @var ThirdPartyProfession
|
||||
* @ORM\OneToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
|
||||
* @ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
|
||||
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
private $profession;
|
||||
private ?ThirdPartyProfession $profession;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
@@ -132,9 +151,10 @@ class ThirdParty
|
||||
* @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"
|
||||
* )
|
||||
* @PhonenumberConstraint(type="any")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $telephone;
|
||||
private ?string $telephone = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
@@ -142,7 +162,7 @@ class ThirdParty
|
||||
* @Assert\Email(checkMX=false)
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $email;
|
||||
private ?string $email = null;
|
||||
|
||||
/**
|
||||
* @var Address|null
|
||||
@@ -151,27 +171,24 @@ class ThirdParty
|
||||
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
||||
* @Groups({"read", "write"})
|
||||
*/
|
||||
private $address;
|
||||
private ?Address $address = null;
|
||||
|
||||
/**
|
||||
* Soft-delete flag
|
||||
* @var boolean
|
||||
* @ORM\Column(name="active", type="boolean", options={"defaut": true})
|
||||
*/
|
||||
private $active = true;
|
||||
private bool $active = true;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
* @ORM\Column(name="comment", type="text", nullable=true)
|
||||
*/
|
||||
private $comment;
|
||||
private ?string $comment = null;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
* @ORM\ManyToMany(targetEntity="\Chill\MainBundle\Entity\Center")
|
||||
* @ORM\JoinTable(name="chill_3party.party_center")
|
||||
*/
|
||||
private $centers;
|
||||
private Collection $centers;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="created_at", type="datetime_immutable", nullable=false)
|
||||
@@ -179,33 +196,21 @@ class ThirdParty
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
|
||||
* @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true)
|
||||
*/
|
||||
private ?\DateTime $updatedAt;
|
||||
private ?\DateTimeImmutable $updatedAt;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
|
||||
*/
|
||||
private $updatedBy;
|
||||
|
||||
private ?User $updatedBy;
|
||||
|
||||
/**
|
||||
* @ORM\PrePersist()
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
|
||||
*/
|
||||
public function prePersist()
|
||||
{
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PreUpdate()
|
||||
*/
|
||||
public function preUpdate()
|
||||
{
|
||||
$this->updatedAt = new \DateTime();
|
||||
}
|
||||
private ?User $createdBy;
|
||||
|
||||
|
||||
/**
|
||||
@@ -228,6 +233,17 @@ class ThirdParty
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getKind(): ?string
|
||||
{
|
||||
return $this->kind;
|
||||
}
|
||||
|
||||
public function setKind(?string $kind): ThirdParty
|
||||
{
|
||||
$this->kind = $kind;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name.
|
||||
*
|
||||
@@ -331,6 +347,10 @@ class ThirdParty
|
||||
// remove all keys from the input data
|
||||
$this->type = \array_values($type);
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->setTypes($type);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -367,6 +387,9 @@ class ThirdParty
|
||||
public function setActive(bool $active)
|
||||
{
|
||||
$this->active = $active;
|
||||
foreach ($this->children as $child) {
|
||||
$child->setActive($active);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -486,7 +509,14 @@ class ThirdParty
|
||||
*/
|
||||
public function addCategory(ThirdPartyCategory $category): self
|
||||
{
|
||||
$this->categories[] = $category;
|
||||
if (!$this->categories->contains($category)) {
|
||||
$this->categories[] = $category;
|
||||
}
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->addCategory($child);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -497,6 +527,11 @@ class ThirdParty
|
||||
public function removeCategory(ThirdPartyCategory $category): self
|
||||
{
|
||||
$this->categories->removeElement($category);
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
$child->removeCategory($child);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -509,19 +544,18 @@ class ThirdParty
|
||||
}
|
||||
|
||||
/**
|
||||
* isLeaf aliases
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
public function isChild():bool
|
||||
{
|
||||
return $this->isLeaf();
|
||||
return $this->parent !== null;
|
||||
}
|
||||
|
||||
public function isParent():bool
|
||||
{
|
||||
return !$this->isLeaf();
|
||||
return !$this->isChild();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -537,6 +571,8 @@ class ThirdParty
|
||||
public function addChild(ThirdParty $child): self
|
||||
{
|
||||
$this->children[] = $child;
|
||||
$child->setParent($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -547,7 +583,8 @@ class ThirdParty
|
||||
public function removeChild(ThirdParty $child): self
|
||||
{
|
||||
$this->children->removeElement($child);
|
||||
$this->active = false;
|
||||
$child->setActive(false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -617,7 +654,7 @@ class ThirdParty
|
||||
* @param \DateTimeImmutable $createdAt
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedAt(\DateTimeImmutable $createdAt): ThirdParty
|
||||
public function setCreatedAt(\DateTimeInterface $createdAt): ThirdParty
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
@@ -626,16 +663,16 @@ class ThirdParty
|
||||
/**
|
||||
* @return \DateTime|null
|
||||
*/
|
||||
public function getUpdatedAt(): ?\DateTime
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $updatedAt
|
||||
* @param \DateTimeImmutable $updatedAt
|
||||
* @return $this
|
||||
*/
|
||||
public function setUpdatedAt(\DateTime $updatedAt): ThirdParty
|
||||
public function setUpdatedAt(\DateTimeInterface $updatedAt): ThirdParty
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
return $this;
|
||||
@@ -659,6 +696,12 @@ class ThirdParty
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setCreatedBy(User $user): TrackCreationInterface
|
||||
{
|
||||
$this->createdBy = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user