<?php
namespace App\Entity;
use App\Repository\ProspectOnHearingAidRepository;
use App\Utils\Formatter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validator as McaAssert;
/**
* @ORM\Entity(repositoryClass=ProspectOnHearingAidRepository::class)
* @ORM\EntityListeners({"App\Listener\ProspectOnHearingAidListener"})
*/
class ProspectOnHearingAid implements MediaoptionDeliverable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $created;
/**
* @ORM\Column(type="smallint", nullable=true)
* @Assert\NotBlank(groups={"API"})
*/
private $gender;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Length(
* min = 2,
* max = 50,
* )
* @Assert\Regex(
* pattern="/^[A-Za-zÀ-úœ'\-\s]*$/",
* message="Le prénom n'est pas valide"
* )
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Regex(
* pattern="/^[A-Za-zÀ-úœ'\-\s]*$/",
* message="Le nom n'est pas valide"
* )
* @Assert\Length(
* min = 2,
* max = 50,
* )
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* min = 2,
* max = 50,
* )
*/
private $address;
/**
* @ORM\Column(type="string", length=5)
* @Assert\NotBlank()
* @Assert\Regex(
* pattern="/^(([0-8][0-9])|(9[0-5])|(2[ab]))[0-9]{3}$/",
* message="Le code postal n'est pas valide"
* )
*/
private $postalcode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* min = 2,
* max = 50,
* )
* @Assert\NotBlank(groups={"API"})
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank
* @Assert\Email(
* message = "L'email '{{ value }}' n'est pas valide",
* mode = "strict"
* )
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank
* @McaAssert\ValidPhoneNumber
*/
private $phoneNumber;
/**
* @ORM\Column(type="string", length=4, nullable=true)
* @Assert\NotBlank()
* @Assert\Regex(pattern="/^(19|20)\d{2}$/", message="L'année de naissance n'est pas valide.")
*/
private $yearOfBirth;
/**
* @ORM\Column(type="boolean")
*/
private $isPrivacy;
/**
* @ORM\Column(type="boolean")
*/
private $isOptin;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isPartnerOffer;
/**
* @ORM\Column(type="string", length=255)
*/
private $request;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\PhoneValidation", inversedBy="prospect", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
*/
private $phoneValidation;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MediaoptinDelivery", mappedBy="prospectOnHearingAid", cascade={"persist", "remove"})
*/
private $mediaoptinDeliveries;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\HearingAid")
*/
private $hearingAid;
/**
* Mode d'acquisition du lead (emailing, facebook, ...)
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $acquisitionMode;
/**
* Base emailing de provenance du lead
*
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"API"})
*/
private $acquisitionBase;
/**
* Url de provenance du lead (dernière URL avant persist)
*
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $acquisitionUrl;
/**
* Meta keyword URL
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $acquisitionKeyword;
/**
* @var string
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $countryCode;
/**
* @ORM\Column(type="boolean", nullable=true)
* @var boolean
*/
private $isOrlPrescription;
/**
* @ORM\Column(type="boolean")
*/
private $delivered=false;
public function __construct()
{
$this->mediaoptinDeliveries = new ArrayCollection();
}
/**
* Représente l'entité par défault
* @return string
*/
public function __toString(){
return 'ProspectOnHearingAid ['.$this->getId().']';
}
/**
* Obtenir l'adresse complète
* @return string
*/
public function getFullAddress() {
return $this->getAddress() . ' ' . $this->getPostalcode() . ' ' . $this->getCity();
}
/**
* Représente l'entité dans le BO
* @return string
*/
public function getLabel(){
return '#'.$this->getId();
}
public function getId(): ?int
{
return $this->id;
}
public function getGender(): ?int
{
return $this->gender;
}
public function setGender(?int $gender): self
{
$this->gender = $gender;
return $this;
}
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 getFullname(): ?string
{
return ucfirst($this->firstname).' '.ucfirst($this->lastname);
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$phoneNumber = Formatter::phoneNumberFrenchFormat($phoneNumber);
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getPhoneNumberFormatted() {
return wordwrap($this->getPhoneNumber() , 2 , ' ' , true );
}
public function getYearOfBirth(): ?string
{
return $this->yearOfBirth;
}
public function setYearOfBirth(?string $yearOfBirth): self
{
//prevent insertion of non numeri value (ex: 1994-05-17). if not numeric field remains blank
$yearOfBirth = substr($yearOfBirth,0,4);
if(is_numeric($yearOfBirth)){
$this->yearOfBirth = $yearOfBirth;
}
return $this;
}
public function getDateFromYearOfBirth(): ?\DateTimeInterface {
return new \DateTime($this->getYearOfBirth() . '-01-01');
}
public function getRequest(): ?string
{
return $this->request;
}
public function setRequest(string $request): self
{
$this->request = $request;
return $this;
}
public function getIsPrivacy(): ?bool
{
return $this->isPrivacy;
}
public function setIsPrivacy(bool $isPrivacy): self
{
$this->isPrivacy = $isPrivacy;
return $this;
}
public function getIsOptin(): ?bool
{
return $this->isOptin;
}
public function setIsOptin(bool $isOptin): self
{
$this->isOptin = $isOptin;
return $this;
}
public function getIsPartnerOffer(): ?bool
{
return $this->isPartnerOffer;
}
public function setIsPartnerOffer(bool $isPartnerOffer): self
{
$this->isPartnerOffer = $isPartnerOffer;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getPostalcode(): ?string
{
return $this->postalcode;
}
public function setPostalcode(string $postalcode): self
{
if(strlen($postalcode) === 4) {
$this->postalcode = str_pad($postalcode, 5, '0', STR_PAD_LEFT);
} else {
$this->postalcode = $postalcode;
}
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getPhoneValidation(): ?PhoneValidation
{
return $this->phoneValidation;
}
public function setPhoneValidation(?PhoneValidation $phoneValidation): self
{
$this->phoneValidation = $phoneValidation;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
/**
* @return Collection|MediaoptinDelivery[]
*/
public function getMediaoptinDeliveries(): Collection
{
return $this->mediaoptinDeliveries;
}
public function addMediaoptinDelivery(MediaoptinDelivery $mediaoptinDelivery): self
{
if (!$this->mediaoptinDeliveries->contains($mediaoptinDelivery)) {
$this->mediaoptinDeliveries[] = $mediaoptinDelivery;
$mediaoptinDelivery->setProspectOnHearingAid($this);
}
return $this;
}
public function removeMediaoptinDelivery(MediaoptinDelivery $mediaoptinDelivery): self
{
if ($this->mediaoptinDeliveries->contains($mediaoptinDelivery)) {
$this->mediaoptinDeliveries->removeElement($mediaoptinDelivery);
// set the owning side to null (unless already changed)
if ($mediaoptinDelivery->getProspect() === $this) {
$mediaoptinDelivery->setProspect(null);
}
}
return $this;
}
public function getAcquisitionMode(): ?string
{
return $this->acquisitionMode;
}
public function setAcquisitionMode(?string $acquisitionMode): self
{
$this->acquisitionMode = $acquisitionMode;
return $this;
}
public function getAcquisitionBase(): ?string
{
return $this->acquisitionBase;
}
public function setAcquisitionBase(?string $acquisitionBase): self
{
$this->acquisitionBase = $acquisitionBase;
return $this;
}
public function getAcquisitionUrl(): ?string
{
return $this->acquisitionUrl;
}
public function setAcquisitionUrl(?string $acquisitionUrl): self
{
$this->acquisitionUrl = $acquisitionUrl;
return $this;
}
public function getCountryCode(): ?string
{
return $this->countryCode;
}
public function setCountryCode(?string $countryCode): self
{
$this->countryCode = $countryCode;
return $this;
}
public function getIsOrlPrescription(): ?bool
{
return $this->isOrlPrescription;
}
public function setIsOrlPrescription(?bool $isOrlPrescription): self
{
$this->isOrlPrescription = $isOrlPrescription;
return $this;
}
/**
* Export for Sonata Admin
* @return string
*/
public function getExportIsOrlPrescription() {
if(isset($this->isOrlPrescription)) {
return $this->getIsOrlPrescription() ? "Oui" : "Non";
} else {
return "Non renseigné";
}
}
public function getAcquisitionKeyword(): ?string
{
return $this->acquisitionKeyword;
}
public function setAcquisitionKeyword(?string $acquisitionKeyword): self
{
$this->acquisitionKeyword = $acquisitionKeyword;
return $this;
}
/**
* @return mixed
*/
public function getHearingAid()
{
return $this->hearingAid;
}
/**
* @param mixed $hearingAid
*/
public function setHearingAid($hearingAid): void
{
$this->hearingAid = $hearingAid;
}
public function getDelivered(): ?bool
{
return $this->delivered;
}
public function setDelivered(bool $delivered): self
{
$this->delivered = $delivered;
return $this;
}
public function markDelivered(): self
{
return $this->setDelivered(true);
}
}