<?php
namespace App\V4\Model\Contact;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Model\IriNormalizableInterface;
use App\Model\NormalizeAsIRITrait;
use App\Model\SpecificFieldsAwareInterface;
use App\Model\Traits\BlamableTrait;
use App\Model\Traits\ImportableObjectTrait;
use App\Model\Traits\TimestampableTrait;
use App\V4\Entity\ActionableEntityInterface;
use App\V4\Model\Address\Address;
use App\V4\Model\Civility\Civility;
use App\V4\Model\ContactSpecificField\ContactSpecificField;
use App\V4\Model\Params\Params;
use App\V4\Model\Prospect\Prospect;
use App\V4\Model\RGPDInfo\RGPDInfo;
use App\V4\Model\Service\Service;
use App\V4\Model\SpecificField\SpecificField;
use App\V4\Model\Task\Task;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* attributes={
* "api_allow_update": true
* },
* collectionOperations={
* "get": {
* "normalization_context": {
* "groups": {"contact:list"}
* },
* "security": "is_granted(constant('App\\V4\\Voters\\ContactVoter::CONTACT_SHOW_LIST'), 'App\V4\Voters\ContactVoter')"
* },
* "post_contact": {
* "method": "POST",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Contact\ContactDataPersisterAction",
* "path": "/V4/contacts",
* "input_formats": {
* "multipart": {"multipart/form-data"}
* },
* "normalization_context": {
* "groups": {"contact:read"}
* },
* "denormalization_context": {
* "groups": {}
* }
* },
* "get_form": {
* "method": "GET",
* "path": "/V4/contacts/form",
* "controller": App\V4\Controller\Contact\GetContactFormAction::class
* },
* "get_search": {
* "method": "GET",
* "path": "/V4/contacts/search/form",
* "controller": App\V4\Controller\Contact\GetContactSearchFormAction::class,
* },
* "post_search": {
* "method": "POST",
* "deserialize": false,
* "path": "/V4/contacts/search/form",
* "normalization_context": {
* "groups": {"contact:list"}
* },
* "controller": App\V4\Controller\Contact\PostContactSearchFormAction::class,
* },
* "post_export_request": {
* "method": "POST",
* "path": "/v4/export/contact",
* "controller": App\V4\Action\Export\EntityExportRequestAction::class,
* "swagger_context": {
* "summary": "Demande de création d'export de contacts",
* "description": "Demande de création d'export de contacts où 'ids' sont les ids des contacts et 'fields' les champs souhaités",
* "parameters": {
* {
* "in": "body",
* "name": "body",
* "schema": {
* "type": "object",
* "properties": {
* "ids": {
* "type": "array",
* "items": {"type": "string"}
* },
* "fields": {
* "type": "array",
* "items": {"type": "string"}
* }
* }
* }
* }
* },
* "responses": {
* "201": {
* "description": "Création de l'export avec succès",
* "schema": {
* "type": "object",
* "properties": {
* "message": {"type": "string", "example": "export_request_created"},
* }
* }
* },
* "400": {
* "description": "Utilisateur non trouvé ou champs 'fields' ou 'ids' manquant dans le body request",
* "schema": {
* "type": "object",
* "properties": {
* "message": {"type": "string", "example": "user_not_found or missing_fields_or_ids"},
* }
* }
* },
* "422": {
* "description": "Les champs 'fields' ou 'ids' du body request sont vides ou l'entité demandée est invalide",
* "schema": {
* "type": "object",
* "properties": {
* "message": {"type": "string", "example": "empty_fields_or_ids or entity_not_valid"},
* }
* }
* },
* },
* }
* },
* "post_export_download": {
* "method": "POST",
* "path": "/v4/export/download/contact/{id}",
* "controller": App\V4\Action\Export\EntityExportDownloadAction::class,
* "swagger_context": {
* "summary": "Demande de téléchargement d'un export contacts",
* "description": "Demande de téléchargement d'un export contacts ou 'id' est le nom du fichier d'export",
* "requestBody": {},
* "parameters": {
* {
* "in": "path",
* "name": "id",
* "type": "string",
* "required": "true"
* }
* },
* "responses": {
* "200": {
* "description": "Téléchargement de l'export réalisé avec succès"
* },
* "401": {
* "description": "Utilisateur non trouvé ou non connecté",
* "schema": {
* "type": "object",
* "properties": {
* "message": {"type": "string", "example": "need_authenticated"},
* }
* }
* },
* "404": {
* "description": "Fichier introuvable",
* "schema": {
* "type": "object",
* "properties": {
* "message": {"type": "string", "example": "export_not_found"},
* }
* }
* },
* },
* }
* }
* },
* itemOperations={
* "get_form": {
* "method": "GET",
* "path": "/V4/contacts/{id}/form",
* "controller": App\V4\Controller\Contact\GetContactFormAction::class
* },
* "put_contact": {
* "method": "POST",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Contact\ContactDataPersisterAction",
* "path": "/V4/contacts/{id}",
* "input_formats": {
* "multipart": {"multipart/form-data"}
* },
* "normalization_context": {
* "groups": {"contact:read"}
* },
* "denormalization_context": {
* "groups": {}
* }
* },
* "get_form_move_contact": {
* "method": "GET",
* "path": "/V4/contacts/{id}/form_move_contact",
* "controller": App\V4\Controller\Contact\GetMoveContactFormAction::class
* },
* "post_move_contact": {
* "method": "POST",
* "path": "/V4/contacts/{id}/form_move_contact",
* "controller": App\V4\Controller\Contact\PostMoveContactFormAction::class
* },
* "delete_contact": {
* "method": "DELETE",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Contact\ContactDataPersisterAction",
* "path": "/V4/contacts/{id}"
* }
* }
* )
*
* @ApiFilter(App\Filters\PagingFilter::class)
*/
class Contact implements IriNormalizableInterface, SpecificFieldsAwareInterface, ActionableEntityInterface
{
public const SPECIFIC_FIELD_CLASS_NAME = ContactSpecificField::class;
use TimestampableTrait;
use BlamableTrait;
use ImportableObjectTrait;
use NormalizeAsIRITrait;
/**
* @ApiProperty(identifier=true)
*
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $id;
/**
* @var Civility|null
*
* @Groups({
* "list", "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $civility;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $firstname;
/**
* @var string|null
*
* @Assert\NotBlank(groups={"individual", "contact_form"})
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $lastname;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $job;
/**
* @var string|null
*
* @Assert\Email()
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $email;
/**
* @Assert\Email()
*
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $emailSecond;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $phone;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $mobile;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $fax;
/**
* @var Prospect|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update", "task:read", "task:list"
* })
* @MaxDepth(1)
*/
private $prospect;
/**
* @var RGPDInfo|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $RGPDInfo;
/**
* @var string|null
*/
private $customerId;
/**
* @var Service|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update"
* })
*/
private $service;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update"
* })
*/
private $externalId;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $assistantFullName;
/**
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $assistantPhone;
/**
* @Assert\Email()
*
* @var string|null
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:read", "prospect:write", "prospect:update", "individual:write", "individual:update"
* })
*/
private $assistantEmail;
/**
* @var DateTime|null
* @Groups({"contact:list", "contact:read", "contact:write", "contact:update"})
*/
private $emailRgpdSentAt;
/**
* @var string|null
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update"
* })
*/
private $memo;
/**
* @var bool
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update"
* })
*/
private $unSubscribedOfMailing = false;
/**
* @var Task[]|Collection
* @Groups({"contact:list", "contact:read"})
*/
private $tasks;
/**
* @var Address[]|Collection
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $addresses;
/**
* @var Address|null
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $mainAddress;
/**
* @var Address|null
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $deliveryAddress;
/**
* @var bool|null
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $isProspectContact;
/**
* @var SpecificField[]|Collection
*
* @Groups({
* "contact:list", "contact:read", "contact:write", "contact:update",
* "prospect:list", "prospect:read", "prospect:write", "prospect:update"
* })
*/
private $specificFields;
/**
* Champ destiné au formulaire de recherche.
*
* @Groups({"contact:list", "contact:read"})
*
* @var string|null
*/
private $name;
public function __construct()
{
$this->tasks = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->specificFields = new ArrayCollection();
}
/**
* @return string|null
*
* @Groups({
* "contact:list", "contact:read",
* "prospect:list", "prospect:read"
* })
*/
public function getName(): ?string
{
return sprintf('%s %s', trim($this->firstname), trim($this->lastname));
}
/**
* @return string|null
*
* @Groups({
* "contact:list", "contact:read",
* "prospect:list", "prospect:read"
* })
*/
public function getFullName(): ?string
{
return $this->name;
}
/**
* @return bool
*/
public function isUnknown(): bool
{
return $this->getProspect() instanceof Prospect && $this->getProspect()->isUnknown();
}
/**
* @param string|null $name
*
* @return Contact
*
* @Groups({
* "contact:list", "contact:read",
* "prospect:list", "prospect:read"
* })
*/
public function setName(?string $name): Contact
{
$this->name = $name;
return $this;
}
/**
* @return string|null
*/
public function getId(): ?string
{
return $this->id;
}
/**
* @param string|null $id
*
* @return $this
*/
public function setId(?string $id): self
{
$this->id = $id;
return $this;
}
/**
* @return Params|null
*/
public function getCivility(): ?Params
{
return $this->civility;
}
/**
* @param Params|null $civility
*
* @return $this
*/
public function setCivility(?Params $civility): self
{
$this->civility = $civility;
return $this;
}
/**
* @return string|null
*/
public function getFirstname(): ?string
{
return $this->firstname;
}
/**
* @param string|null $firstname
*
* @return $this
*/
public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
/**
* @return string|null
*/
public function getLastname(): ?string
{
return $this->lastname;
}
/**
* @param string|null $lastname
*
* @return $this
*/
public function setLastname(?string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
/**
* @return string|null
*/
public function getJob(): ?string
{
return $this->job;
}
/**
* @param string|null $job
*
* @return $this
*/
public function setJob(?string $job): self
{
$this->job = $job;
return $this;
}
/**
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param string|null $email
*
* @return $this
*/
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return string|null
*/
public function getEmailSecond(): ?string
{
return $this->emailSecond;
}
/**
* @param string|null $emailSecond
*
* @return $this
*/
public function setEmailSecond(?string $emailSecond): self
{
$this->emailSecond = $emailSecond;
return $this;
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @param string|null $phone
*
* @return $this
*/
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* @return string|null
*/
public function getMobile(): ?string
{
return $this->mobile;
}
/**
* @param string|null $mobile
*
* @return Contact
*/
public function setMobile(?string $mobile): Contact
{
$this->mobile = $mobile;
return $this;
}
/**
* @return string|null
*/
public function getFax(): ?string
{
return $this->fax;
}
/**
* @param string|null $fax
*
* @return $this
*/
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
/**
* @return Prospect|null
*/
public function getProspect(): ?Prospect
{
return $this->prospect;
}
/**
* @param Prospect|null $prospect
* #TODO trouver une solution pour empecher le trait ImportableObjectTrait de setter quand on a un IRI
*
* @return $this
*/
public function setProspect($prospect): self
{
if ($prospect instanceof Prospect) {
$this->prospect = $prospect;
}
return $this;
}
/**
* @return string|null
*/
public function getCustomerId(): ?string
{
return $this->customerId;
}
/**
* @param string|null $customerId
*
* @return $this
*/
public function setCustomerId(?string $customerId): self
{
$this->customerId = $customerId;
return $this;
}
/**
* @return Task[]|Collection|null
*/
public function getTasks(): ?Collection
{
return $this->tasks;
}
/**
* @param Task $task
*
* @return Contact
*/
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks->add($task);
$task->addContact($this);
}
return $this;
}
/**
* @param Task $task
*
* @return Contact
*/
public function removeTask(Task $task): self
{
if ($this->tasks->contains($task)) {
$this->tasks->removeElement($task);
$task->removeContact($this);
}
return $this;
}
/**
* @return Address[]|Collection|null
*
* @Groups({"list", "read", "read_contact"})
*/
public function getAddresses(): ?Collection
{
return $this->addresses;
}
/**
* @param Address $address
*
* @return $this
*/
public function addAddress(Address $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses->add($address);
$address->setContact($this);
}
return $this;
}
/**
* @param Address $address
*
* @return $this
*/
public function removeAddress(Address $address): self
{
if (!$this->addresses->contains($address)) {
$this->addresses->removeElement($address);
if ($address->getContact() === $this) {
$address->setContact(null);
}
}
return $this;
}
/**
* @return Address|null
*/
public function getMainAddress(): ?Address
{
return $this->mainAddress;
}
/**
* @param Address|null $mainAddress
*
* @return Contact
*/
public function setMainAddress(?Address $mainAddress): Contact
{
$this->mainAddress = $mainAddress;
return $this;
}
/**
* @return string|null
*/
public function __toString(): ?string
{
return $this->getName();
}
/**
* {@inheritdoc}
*/
public function getSpecificFields(): Collection
{
return $this->specificFields;
}
/**
* {@inheritdoc}
*/
public function getSpecificFieldByFieldId(string $id): ?SpecificField
{
foreach ($this->specificFields as $specificField) {
if ($specificField->getFieldId() === $id) {
return $specificField;
}
}
return null;
}
/**
* @see ImportableObjectTrait::class
*
* @param ContactSpecificField $specificField
*
* @return $this
*/
public function addContactSpecificField(ContactSpecificField $specificField): self
{
return $this->addSpecificField($specificField);
}
/**
* {@inheritdoc}
*/
public function addSpecificField($specificField): SpecificFieldsAwareInterface
{
$this->specificFields[] = $specificField;
return $this;
}
/**
* {@inheritdoc}
*/
public function setSpecificFields(Collection $specificFields): self
{
$this->specificFields = $specificFields;
return $this;
}
/**
* @return Params|null
*/
public function getService(): ?Params
{
return $this->service;
}
/**
* @param Params|null $service
*
* @return Contact
*/
public function setService(?Params $service): Contact
{
$this->service = $service;
return $this;
}
/**
* @return string|null
*/
public function getAssistantFullName(): ?string
{
return $this->assistantFullName;
}
/**
* @param string|null $assistantFullName
*
* @return Contact
*/
public function setAssistantFullName(?string $assistantFullName): Contact
{
$this->assistantFullName = $assistantFullName;
return $this;
}
/**
* @return string|null
*/
public function getAssistantPhone(): ?string
{
return $this->assistantPhone;
}
/**
* @param string|null $assistantPhone
*
* @return Contact
*/
public function setAssistantPhone(?string $assistantPhone): Contact
{
$this->assistantPhone = $assistantPhone;
return $this;
}
/**
* @return string|null
*/
public function getAssistantEmail(): ?string
{
return $this->assistantEmail;
}
/**
* @param string|null $assistantEmail
*
* @return Contact
*/
public function setAssistantEmail(?string $assistantEmail): Contact
{
$this->assistantEmail = $assistantEmail;
return $this;
}
/**
* @return string|null
*/
public function getMemo(): ?string
{
return $this->memo;
}
/**
* @param string|null $memo
*
* @return Contact
*/
public function setMemo(?string $memo): Contact
{
$this->memo = $memo;
return $this;
}
/**
* @return bool|null
*/
public function getUnSubscribedOfMailing(): bool
{
return $this->unSubscribedOfMailing;
}
/**
* @param bool|null $unSubscribedOfMailing
*
* @return Contact
*/
public function setUnSubscribedOfMailing(bool $unSubscribedOfMailing): Contact
{
$this->unSubscribedOfMailing = $unSubscribedOfMailing;
return $this;
}
/**
* @return bool|null
*/
public function getIsProspectContact(): ?bool
{
return $this->isProspectContact;
}
/**
* @param bool|null $isProspectContact
*
* @return Contact
*/
public function setIsProspectContact(?bool $isProspectContact): self
{
$this->isProspectContact = $isProspectContact;
return $this;
}
/**
* @return string|null
*/
public function getExternalId(): ?string
{
return $this->externalId;
}
/**
* @param string|null $externalId
*
* @return Contact
*/
public function setExternalId(?string $externalId): Contact
{
$this->externalId = $externalId;
return $this;
}
/**
* @Groups({"list", "read", "read_contact", "read_prospect", "write_post_prospect", "read_post_prospect", "write_post_contact", "read_post_contact"})
*
* @return string|null
*/
public function getCreatedBy(): ?string
{
return $this->createdBy;
}
/**
* @Groups({"list", "read", "read_contact", "read_prospect", "write_post_prospect", "read_post_prospect", "write_post_contact", "read_post_contact"})
*
* @return string|null
*/
public function getUpdatedBy(): ?string
{
return $this->updatedBy;
}
/**
* @Groups({"list", "read", "read_contact", "read_prospect", "write_post_prospect", "read_post_prospect", "write_post_contact", "read_post_contact"})
*
* @return DateTime|null
*/
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
/**
* @Groups({"list", "read", "read_contact", "read_prospect", "write_post_prospect", "read_post_prospect", "write_post_contact", "read_post_contact"})
*
* @return DateTime|null
*/
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
/**
* @return Address|null
*/
public function getDeliveryAddress(): ?Address
{
return $this->deliveryAddress;
}
/**
* @param Address|null $deliveryAddress
*
* @return Contact
*/
public function setDeliveryAddress(?Address $deliveryAddress): Contact
{
$this->deliveryAddress = $deliveryAddress;
return $this;
}
/**
* @return RGPDInfo|null
*/
public function getRGPDInfo(): ?RGPDInfo
{
return $this->RGPDInfo;
}
/**
* @param RGPDInfo|null $RGPDInfo
*
* @return Contact
*/
public function setRGPDInfo(?RGPDInfo $RGPDInfo): Contact
{
$this->RGPDInfo = $RGPDInfo;
return $this;
}
/**
* @return DateTime|null
*/
public function getEmailRgpdSentAt(): ?DateTime
{
return $this->emailRgpdSentAt;
}
/**
* @param DateTime|null $emailRgpdSentAt
*
* @return Contact
*/
public function setEmailRgpdSentAt(?DateTime $emailRgpdSentAt): Contact
{
$this->emailRgpdSentAt = $emailRgpdSentAt;
return $this;
}
}