src/Entity/ProspectOnHearingAid.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProspectOnHearingAidRepository;
  4. use App\Utils\Formatter;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use App\Validator as McaAssert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=ProspectOnHearingAidRepository::class)
  13.  * @ORM\EntityListeners({"App\Listener\ProspectOnHearingAidListener"})
  14.  */
  15. class ProspectOnHearingAid  implements MediaoptionDeliverable
  16. {
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="datetime")
  25.      * @Gedmo\Timestampable(on="create")
  26.      */
  27.     private $created;
  28.     /**
  29.      * @ORM\Column(type="smallint", nullable=true)
  30.      * @Assert\NotBlank(groups={"API"})
  31.      */
  32.     private $gender;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Assert\NotBlank
  36.      * @Assert\Length(
  37.      *      min = 2,
  38.      *      max = 50,
  39.      * )
  40.      * @Assert\Regex(
  41.      *      pattern="/^[A-Za-zÀ-úœ'\-\s]*$/",
  42.      *      message="Le prénom n'est pas valide"
  43.      * )
  44.      */
  45.     private $firstname;
  46.     /**
  47.      * @ORM\Column(type="string", length=255)
  48.      * @Assert\NotBlank
  49.      * @Assert\Regex(
  50.      *      pattern="/^[A-Za-zÀ-úœ'\-\s]*$/",
  51.      *      message="Le nom n'est pas valide"
  52.      * )
  53.      * @Assert\Length(
  54.      *      min = 2,
  55.      *      max = 50,
  56.      * )
  57.      */
  58.     private $lastname;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      * @Assert\Length(
  62.      *      min = 2,
  63.      *      max = 50,
  64.      * )
  65.      */
  66.     private $address;
  67.     /**
  68.      * @ORM\Column(type="string", length=5)
  69.      * @Assert\NotBlank()
  70.      * @Assert\Regex(
  71.      *      pattern="/^(([0-8][0-9])|(9[0-5])|(2[ab]))[0-9]{3}$/",
  72.      *      message="Le code postal n'est pas valide"
  73.      * )
  74.      */
  75.     private $postalcode;
  76.     /**
  77.      * @ORM\Column(type="string", length=255, nullable=true)
  78.      * @Assert\Length(
  79.      *      min = 2,
  80.      *      max = 50,
  81.      * )
  82.      * @Assert\NotBlank(groups={"API"})
  83.      */
  84.     private $city;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      * @Assert\NotBlank
  88.      * @Assert\Email(
  89.      *     message = "L'email '{{ value }}' n'est pas valide",
  90.      *     mode = "strict"
  91.      * )
  92.      */
  93.     private $email;
  94.     /**
  95.      * @ORM\Column(type="string", length=255, nullable=true)
  96.      * @Assert\NotBlank
  97.      * @McaAssert\ValidPhoneNumber
  98.      */
  99.     private $phoneNumber;
  100.     /**
  101.      * @ORM\Column(type="string", length=4, nullable=true)
  102.      * @Assert\NotBlank()
  103.      * @Assert\Regex(pattern="/^(19|20)\d{2}$/", message="L'année de naissance n'est pas valide.")
  104.      */
  105.     private $yearOfBirth;
  106.     /**
  107.      * @ORM\Column(type="boolean")
  108.      */
  109.     private $isPrivacy;
  110.     /**
  111.      * @ORM\Column(type="boolean")
  112.      */
  113.     private $isOptin;
  114.     /**
  115.      * @ORM\Column(type="boolean", nullable=true)
  116.      */
  117.     private $isPartnerOffer;
  118.     /**
  119.      * @ORM\Column(type="string", length=255)
  120.      */
  121.     private $request;
  122.     /**
  123.      * @ORM\ManyToOne(targetEntity="App\Entity\PhoneValidation", inversedBy="prospect", cascade={"persist", "remove"})
  124.      * @ORM\JoinColumn(nullable=true)
  125.      */
  126.     private $phoneValidation;
  127.     /**
  128.      * @ORM\OneToMany(targetEntity="App\Entity\MediaoptinDelivery", mappedBy="prospectOnHearingAid", cascade={"persist", "remove"})
  129.      */
  130.     private $mediaoptinDeliveries;
  131.     /**
  132.      * @ORM\ManyToOne(targetEntity="App\Entity\HearingAid")
  133.      */
  134.     private $hearingAid;
  135.     /**
  136.      * Mode d'acquisition du lead (emailing, facebook, ...)
  137.      *
  138.      * @ORM\Column(type="string", length=255, nullable=true)
  139.      */
  140.     private $acquisitionMode;
  141.     /**
  142.      * Base emailing de provenance du lead
  143.      *
  144.      * @ORM\Column(type="string", length=255, nullable=true)
  145.      * @Assert\NotBlank(groups={"API"})
  146.      */
  147.     private $acquisitionBase;
  148.     /**
  149.      * Url de provenance du lead (dernière URL avant persist)
  150.      *
  151.      * @ORM\Column(type="string", length=255, nullable=true)
  152.      */
  153.     private $acquisitionUrl;
  154.     /**
  155.      * Meta keyword URL
  156.      * @ORM\Column(type="string", length=255, nullable=true)
  157.      */
  158.     private $acquisitionKeyword;
  159.     /**
  160.      * @var string
  161.      * @ORM\Column(type="string", length=255, nullable=true)
  162.      */
  163.     private $countryCode;
  164.     /**
  165.      * @ORM\Column(type="boolean", nullable=true)
  166.      * @var boolean
  167.      */
  168.     private $isOrlPrescription;
  169.     /**
  170.      * @ORM\Column(type="boolean")
  171.      */
  172.     private $delivered=false;
  173.     public function __construct()
  174.     {
  175.         $this->mediaoptinDeliveries = new ArrayCollection();
  176.     }
  177.     /**
  178.      * Représente l'entité par défault
  179.      * @return string
  180.      */
  181.     public function __toString(){
  182.         return 'ProspectOnHearingAid ['.$this->getId().']';
  183.     }
  184.     /**
  185.      * Obtenir l'adresse complète
  186.      * @return string
  187.      */
  188.     public function getFullAddress() {
  189.         return $this->getAddress() . ' ' $this->getPostalcode() . ' ' $this->getCity();
  190.     }
  191.     /**
  192.      * Représente l'entité dans le BO
  193.      * @return string
  194.      */
  195.     public function getLabel(){
  196.         return '#'.$this->getId();
  197.     }
  198.     public function getId(): ?int
  199.     {
  200.         return $this->id;
  201.     }
  202.     public function getGender(): ?int
  203.     {
  204.         return $this->gender;
  205.     }
  206.     public function setGender(?int $gender): self
  207.     {
  208.         $this->gender $gender;
  209.         return $this;
  210.     }
  211.     public function getFirstname(): ?string
  212.     {
  213.         return $this->firstname;
  214.     }
  215.     public function setFirstname(string $firstname): self
  216.     {
  217.         $this->firstname $firstname;
  218.         return $this;
  219.     }
  220.     public function getLastname(): ?string
  221.     {
  222.         return $this->lastname;
  223.     }
  224.     public function setLastname(string $lastname): self
  225.     {
  226.         $this->lastname $lastname;
  227.         return $this;
  228.     }
  229.     public function getFullname(): ?string
  230.     {
  231.         return ucfirst($this->firstname).' '.ucfirst($this->lastname);
  232.     }
  233.     public function getEmail(): ?string
  234.     {
  235.         return $this->email;
  236.     }
  237.     public function setEmail(string $email): self
  238.     {
  239.         $this->email $email;
  240.         return $this;
  241.     }
  242.     public function getPhoneNumber(): ?string
  243.     {
  244.         return $this->phoneNumber;
  245.     }
  246.     public function setPhoneNumber(?string $phoneNumber): self
  247.     {
  248.         $phoneNumber Formatter::phoneNumberFrenchFormat($phoneNumber);
  249.         $this->phoneNumber $phoneNumber;
  250.         return $this;
  251.     }
  252.     public function getPhoneNumberFormatted() {
  253.         return wordwrap($this->getPhoneNumber() , ' ' true );
  254.     }
  255.     public function getYearOfBirth(): ?string
  256.     {
  257.         return $this->yearOfBirth;
  258.     }
  259.     public function setYearOfBirth(?string $yearOfBirth): self
  260.     {
  261.         //prevent insertion of non numeri value (ex: 1994-05-17). if not numeric field remains blank
  262.         $yearOfBirth substr($yearOfBirth,0,4);
  263.         if(is_numeric($yearOfBirth)){
  264.             $this->yearOfBirth $yearOfBirth;
  265.         }
  266.         return $this;
  267.     }
  268.     public function getDateFromYearOfBirth(): ?\DateTimeInterface {
  269.         return new \DateTime($this->getYearOfBirth() . '-01-01');
  270.     }
  271.     public function getRequest(): ?string
  272.     {
  273.         return $this->request;
  274.     }
  275.     public function setRequest(string $request): self
  276.     {
  277.         $this->request $request;
  278.         return $this;
  279.     }
  280.     public function getIsPrivacy(): ?bool
  281.     {
  282.         return $this->isPrivacy;
  283.     }
  284.     public function setIsPrivacy(bool $isPrivacy): self
  285.     {
  286.         $this->isPrivacy $isPrivacy;
  287.         return $this;
  288.     }
  289.     public function getIsOptin(): ?bool
  290.     {
  291.         return $this->isOptin;
  292.     }
  293.     public function setIsOptin(bool $isOptin): self
  294.     {
  295.         $this->isOptin $isOptin;
  296.         return $this;
  297.     }
  298.     public function getIsPartnerOffer(): ?bool
  299.     {
  300.         return $this->isPartnerOffer;
  301.     }
  302.     public function setIsPartnerOffer(bool $isPartnerOffer): self
  303.     {
  304.         $this->isPartnerOffer $isPartnerOffer;
  305.         return $this;
  306.     }
  307.     public function getAddress(): ?string
  308.     {
  309.         return $this->address;
  310.     }
  311.     public function setAddress(string $address): self
  312.     {
  313.         $this->address $address;
  314.         return $this;
  315.     }
  316.     public function getPostalcode(): ?string
  317.     {
  318.         return $this->postalcode;
  319.     }
  320.     public function setPostalcode(string $postalcode): self
  321.     {
  322.         if(strlen($postalcode) === 4) {
  323.             $this->postalcode str_pad($postalcode5'0'STR_PAD_LEFT);
  324.         } else {
  325.             $this->postalcode $postalcode;
  326.         }
  327.         return $this;
  328.     }
  329.     public function getCity(): ?string
  330.     {
  331.         return $this->city;
  332.     }
  333.     public function setCity(string $city): self
  334.     {
  335.         $this->city $city;
  336.         return $this;
  337.     }
  338.     public function getPhoneValidation(): ?PhoneValidation
  339.     {
  340.         return $this->phoneValidation;
  341.     }
  342.     public function setPhoneValidation(?PhoneValidation $phoneValidation): self
  343.     {
  344.         $this->phoneValidation $phoneValidation;
  345.         return $this;
  346.     }
  347.     public function getCreated(): ?\DateTimeInterface
  348.     {
  349.         return $this->created;
  350.     }
  351.     public function setCreated(\DateTimeInterface $created): self
  352.     {
  353.         $this->created $created;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return Collection|MediaoptinDelivery[]
  358.      */
  359.     public function getMediaoptinDeliveries(): Collection
  360.     {
  361.         return $this->mediaoptinDeliveries;
  362.     }
  363.     public function addMediaoptinDelivery(MediaoptinDelivery $mediaoptinDelivery): self
  364.     {
  365.         if (!$this->mediaoptinDeliveries->contains($mediaoptinDelivery)) {
  366.             $this->mediaoptinDeliveries[] = $mediaoptinDelivery;
  367.             $mediaoptinDelivery->setProspectOnHearingAid($this);
  368.         }
  369.         return $this;
  370.     }
  371.     public function removeMediaoptinDelivery(MediaoptinDelivery $mediaoptinDelivery): self
  372.     {
  373.         if ($this->mediaoptinDeliveries->contains($mediaoptinDelivery)) {
  374.             $this->mediaoptinDeliveries->removeElement($mediaoptinDelivery);
  375.             // set the owning side to null (unless already changed)
  376.             if ($mediaoptinDelivery->getProspect() === $this) {
  377.                 $mediaoptinDelivery->setProspect(null);
  378.             }
  379.         }
  380.         return $this;
  381.     }
  382.     public function getAcquisitionMode(): ?string
  383.     {
  384.         return $this->acquisitionMode;
  385.     }
  386.     public function setAcquisitionMode(?string $acquisitionMode): self
  387.     {
  388.         $this->acquisitionMode $acquisitionMode;
  389.         return $this;
  390.     }
  391.     public function getAcquisitionBase(): ?string
  392.     {
  393.         return $this->acquisitionBase;
  394.     }
  395.     public function setAcquisitionBase(?string $acquisitionBase): self
  396.     {
  397.         $this->acquisitionBase $acquisitionBase;
  398.         return $this;
  399.     }
  400.     public function getAcquisitionUrl(): ?string
  401.     {
  402.         return $this->acquisitionUrl;
  403.     }
  404.     public function setAcquisitionUrl(?string $acquisitionUrl): self
  405.     {
  406.         $this->acquisitionUrl $acquisitionUrl;
  407.         return $this;
  408.     }
  409.     public function getCountryCode(): ?string
  410.     {
  411.         return $this->countryCode;
  412.     }
  413.     public function setCountryCode(?string $countryCode): self
  414.     {
  415.         $this->countryCode $countryCode;
  416.         return $this;
  417.     }
  418.     public function getIsOrlPrescription(): ?bool
  419.     {
  420.         return $this->isOrlPrescription;
  421.     }
  422.     public function setIsOrlPrescription(?bool $isOrlPrescription): self
  423.     {
  424.         $this->isOrlPrescription $isOrlPrescription;
  425.         return $this;
  426.     }
  427.     /**
  428.      * Export for Sonata Admin
  429.      * @return string
  430.      */
  431.     public function getExportIsOrlPrescription() {
  432.         if(isset($this->isOrlPrescription)) {
  433.             return $this->getIsOrlPrescription() ? "Oui" "Non";
  434.         } else {
  435.             return "Non renseigné";
  436.         }
  437.     }
  438.     public function getAcquisitionKeyword(): ?string
  439.     {
  440.         return $this->acquisitionKeyword;
  441.     }
  442.     public function setAcquisitionKeyword(?string $acquisitionKeyword): self
  443.     {
  444.         $this->acquisitionKeyword $acquisitionKeyword;
  445.         return $this;
  446.     }
  447.     /**
  448.      * @return mixed
  449.      */
  450.     public function getHearingAid()
  451.     {
  452.         return $this->hearingAid;
  453.     }
  454.     /**
  455.      * @param mixed $hearingAid
  456.      */
  457.     public function setHearingAid($hearingAid): void
  458.     {
  459.         $this->hearingAid $hearingAid;
  460.     }
  461.     public function getDelivered(): ?bool
  462.     {
  463.         return $this->delivered;
  464.     }
  465.     public function setDelivered(bool $delivered): self
  466.     {
  467.         $this->delivered $delivered;
  468.         return $this;
  469.     }
  470.     public function markDelivered(): self
  471.     {
  472.         return $this->setDelivered(true);
  473.     }
  474. }