<?php
namespace App\Entity;
use App\Entity\Reference\PersonTypeReference;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Reference\ReferencePersonMaritalStatus;
use App\Repository\AbstractPeopleRepository;
use App\Traits\TimeStampTrait;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use App\Filter\ContactCityFilter;
/**
* @ApiResource(
* security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* normalizationContext={
* "groups"={ "abstract-people:read","directory:people:search" },
* "swagger_definition_name"="Read"
* },
* denormalizationContext={
* "groups"={"abstract-people:write"},
* "swagger_definition_name"="Write","skip_null_values" = true
* },
* itemOperations={
* "get"={
* "path"="/peoples/{id}",
* "controller"=NotFoundAction::class,
* "read"=false,
* "output"=false,
* },
* },
* collectionOperations={
* "get"={
* "path"="/peoples",
* "controller"=NotFoundAction::class,
* "read"=false,
* "output"=false,
* },
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
*
* )
* @ApiFilter(ContactCityFilter::class)
* @ApiFilter(SearchFilter::class, properties={
* "id": "exact",
* "firstName": "ipartial",
* "lastName": "ipartial",
* "email": "partial",
* "mainPhone":"partial",
* "address.city.name":"ipartial",
* })
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string", length=12)
* @ORM\DiscriminatorMap({
* "contact"="Contact",
* "candidate"="Candidate",
* "prescriber" = "Prescriber"
*
* })
* @ORM\Entity(repositoryClass=AbstractPeopleRepository::class)
* @ORM\Table(indexes={@ORM\Index(name="abstract_people_search_idx", columns={"first_name","last_name","email","main_phone"})})
* @ORM\HasLifecycleCallbacks()
*/
abstract class AbstractPeople
{
use TimeStampTrait;
public const ROLE_CONTACT = 'ROLE_CONTACT';
public const ROLE_CANDIDATE = 'ROLE_CANDIDATE';
public const ROLE_PRESCRIBER = 'ROLE_PRESCRIBER';
public const PERSON_TYPE_PHYSICAL = 'Physical';
public const PERSON_TYPE_MORAL = 'Moral';
public const ALL_PEOPLE_ROLE = [
self::ROLE_CANDIDATE,
self::ROLE_PRESCRIBER,
self::ROLE_CONTACT
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "directory:people:search",
* "candidate:read",
* "contact:read",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read",
* "property-visit:read",
* "business-indication:item:read"
* })
*/
protected ?int $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Type("string")
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "property-visit:read",
* "business-indication:item:read"
* })
*/
protected ?string $firstName;
/**
*
* @ORM\Column(type="string", length=255)
* @Assert\Type("string")
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "property-visit:read",
* "business-indication:item:read"
* })
*
*/
protected ?string $lastName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*
* @Groups({
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put"
* })
*/
protected ?string $cin;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "business-indication:item:read"
* })
*
*/
protected ?string $email;
/**
* @ORM\Column(type="date", nullable=true)
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "business-indication:item:read"
* })
*
*/
protected $birthDay;
/**
* @ORM\Column(type="string", length=255,nullable=true)
*
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "business-indication:item:read"
*
* })
*
*/
protected ?string $phone;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "prescriber:read","prescriber:write","prescriber:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "business-indication:item:read"
* })
*
*/
protected ?string $mainPhone;
/**
* @ORM\OneToOne(targetEntity=Address::class, cascade={"persist", "remove"})
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:put","prescriber:write",
* "business-indication:item:read"
* })
*
*/
protected ?Address $address;
/**
* @ORM\ManyToOne(targetEntity=Gender::class, inversedBy="abstractPeople")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read","prescriber:read","prescriber:put","prescriber:write",
* "business-indication:item:read"
* })
*
*/
protected ?Gender $gender;
/**
* @ORM\Column(type="json")
*
* @Groups({
* "directory:people:search",
* "candidate:read",
* "prescriber:read",
* })
*/
protected array $roles = [];
/**
* @ORM\ManyToOne(targetEntity=ReferencePersonMaritalStatus::class)
*
* @Groups({
* "candidate:read","candidate:write","candidate:put"
* })
*/
private ?ReferencePersonMaritalStatus $referenceMaritalStatus;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Groups({
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "prescriber:read","prescriber:write","prescriber:put"
* })
*/
protected ?string $companyName;
/**
* ICE (identifiant commun de l'entreprise)
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Groups({
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "prescriber:read","prescriber:write","prescriber:put"
* })
*/
protected ?string $commonCompanyIdentifier;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*
* @Groups({
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "prescriber:read","prescriber:write","prescriber:put"
* })
*/
protected ?string $rc;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Groups({
* "directory:people:search",
* "candidate:write","candidate:put",
* "contact:write","contact:put",
* "prescriber:write","prescriber:put",
* "siege:write",
* "property:read"
* })
*/
private ?string $personType = null;
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getBirthDay(): ?DateTimeInterface
{
return $this->birthDay;
}
public function setBirthDay(?DateTimeInterface $birthDay): self
{
$this->birthDay = $birthDay;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getMainPhone(): ?string
{
return $this->mainPhone;
}
public function setMainPhone(string $mainPhone): self
{
$this->mainPhone = $mainPhone;
return $this;
}
/**
* @return string|null
*/
public function getCin(): ?string
{
return $this->cin;
}
/**
* @param string|null $cin
*
* @return $this
*/
public function setCin(?string $cin): self
{
$this->cin = $cin;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param string $email
* @return $this
*/
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(Address $address): self
{
$this->address = $address;
return $this;
}
public function getGender(): ?Gender
{
return $this->gender;
}
public function setGender(?Gender $gender): self
{
$this->gender = $gender;
return $this;
}
public function getRoles(): array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getReferenceMaritalStatus(): ?ReferencePersonMaritalStatus
{
return $this->referenceMaritalStatus;
}
public function setReferenceMaritalStatus(?ReferencePersonMaritalStatus $referenceMaritalStatus): self
{
$this->referenceMaritalStatus = $referenceMaritalStatus;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
/**
* @return string|null
*/
public function getCommonCompanyIdentifier(): ?string
{
return $this->commonCompanyIdentifier;
}
/**
* @param string|null $commonCompanyIdentifier
*
* @return $this
*/
public function setCommonCompanyIdentifier(?string $commonCompanyIdentifier): self
{
$this->commonCompanyIdentifier = $commonCompanyIdentifier;
return $this;
}
/**
* @return string|null
*/
public function getRc(): ?string
{
return $this->rc;
}
/**
* @param string|null $rc
*
* @return $this
*/
public function setRc(?string $rc): self
{
$this->rc = $rc;
return $this;
}
/**
* @return bool
*/
public function isCompany(): bool
{
if (null === $this->getPersonType()) {
return false;
}
return $this->getPersonType() === self::PERSON_TYPE_MORAL;
}
/**
* @return bool
*/
public function isFemale(): bool
{
if (null === $this->getGender()) {
return false;
}
return $this->getGender()->getCode(
) === Gender::REFERENCE_CODE_GENDER_FEMALE;
}
/**
* @return bool
*/
public function isMale(): bool
{
if (null === $this->getGender()) {
return false;
}
return $this->getGender()->getCode(
) === Gender::REFERENCE_CODE_GENDER_MALE;
}
/**
* @return string
* @Groups({
* "directory:people:search",
* "candidate:read","candidate:write","candidate:put",
* "contact:read","contact:write","contact:put",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read","prescriber:write","prescriber:put",
* "property-visit:read",
* "business-indication:item:read"
* })
*/
public function getFullName(): string
{
if (null === $this->firstName && null === $this->lastName) {
return '';
}
return sprintf('%s %s', ucfirst($this->firstName), strtoupper($this->lastName));
}
public function getPersonType(): ?string
{
return $this->personType;
}
public function setPersonType(?string $personType): self
{
$this->personType = $personType;
return $this;
}
/**
* @return PersonTypeReference|null
*
* @Groups({
* "directory:people:search",
* "candidate:read",
* "contact:read",
* "transaction-item:read",
* "mandate:read",
* "property:read",
* "prescriber:read",
* "property-visit:read",
* "business-indication:item:read",
* })
*
* @SerializedName("personType")
*/
public function getReferencePersonType(): ?PersonTypeReference
{
if (null === $this->personType) {
return null;
}
return PersonTypeReference::createFromCode($this->getPersonType());
}
}