src/Entity/Store.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Enum\StorePriorityEnum;
  4. use App\Utils\Formatter;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  9. use Wits\PaymentBundle\Entity\PaymentMethod;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Gedmo\Mapping\Annotation as Gedmo;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. use ApiPlatform\Core\Annotation\ApiResource;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. /**
  18.  * @ORM\Entity(repositoryClass="App\Repository\StoreRepository")
  19.  * @ORM\EntityListeners({"App\Listener\StoreListener"})
  20.  * @Gedmo\SoftDeleteable(fieldName="deletedAt")
  21.  * @Vich\Uploadable
  22.  *
  23.  * @ApiResource(
  24.  *     collectionOperations={
  25.  *          "get",
  26.  *          "search_stores"={
  27.  *             "method"="GET",
  28.  *             "path"="/stores/search",
  29.  *             "controller"=App\Controller\Api\SearchStoresAction::class,
  30.  *             "read"=true
  31.  *         }
  32.  *     },
  33.  *     itemOperations={"get"},
  34.  *     normalizationContext={"groups"={"store:read"}},
  35.  *     denormalizationContext={"groups"={"store:write"}}
  36.  * )
  37.  */
  38. class Store
  39. {
  40.     const STATE_NEW 'new';
  41.     const STATE_VALID 'valid';
  42.     const STATE_REJECTED 'rejected';
  43.     const STATE_TOBEDELETED 'to_be_deleted';
  44.     const AREA_SEARCH 20// perimetre de recherche des stores par défaut (reach)
  45.     const AREA_SEARCH_EXT 100// perimetre de recherche étendu si aucun store (reach extends)
  46.     const NUM_STORE_PER_PAGE 10// nombre de store par page (finder)
  47.     const NUM_TOP_CLIENT_STORE 3// nombre de store dans la selection MCA (top page)
  48.     // paramètres d'application de l'algorithme de tri des centres (SAW)
  49.     const WEIGHT_DISTANCE 0.1;
  50.     const WEIGHT_LEAD_COST 0;
  51.     const WEIGHT_RATIO_CAPPING 0.9;
  52.     /**
  53.      * @ORM\Id()
  54.      * @ORM\GeneratedValue()
  55.      * @ORM\Column(type="integer")
  56.      * @Groups({"store:read", "pos:read"})
  57.      */
  58.     private $id;
  59.     /**
  60.      * @ORM\Column(type="string", length=25)
  61.      */
  62.     private $state self::STATE_NEW;
  63.     /**
  64.      * @ORM\Column(type="string", length=255)
  65.      * @Groups({"store:read", "pos:read"})
  66.      */
  67.     private $name;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      * @Groups({"pos:read", "store:read"})
  71.      */
  72.     private $address;
  73.     /**
  74.      * @ORM\Column(type="string", length=255, nullable=true)
  75.      */
  76.     private $addressDetail;
  77.     /**
  78.      * @ORM\Column(type="string", length=5)
  79.      * @Assert\Regex(
  80.      *     pattern="/^(([0-8][0-9])|(9[0-5])|(2[ab]))[0-9]{3}$/",
  81.      *     message="Le code postal n'est pas valide"
  82.      * )
  83.      * @Groups({"pos:read", "store:read"})
  84.      */
  85.     private $zipCode;
  86.     /**
  87.      * @ORM\Column(type="string", length=255)
  88.      * @Groups({"pos:read", "store:read"})
  89.      */
  90.     private $city;
  91.     /**
  92.      * @Assert\Regex(pattern="/^(?:\+33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/", message="Le numéro de téléphone n'est pas valide.")
  93.      * @ORM\Column(type="string", length=255, nullable=true)
  94.      */
  95.     private $phoneNumber;
  96.     /**
  97.      * @ORM\Column(type="string", length=255, nullable=true)
  98.      */
  99.     private $fax;
  100.     /**
  101.      * @ORM\ManyToMany(targetEntity="App\Entity\Owner", mappedBy="store")
  102.      */
  103.     private $owner;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity="App\Entity\HearingBrand", inversedBy="stores")
  106.      * @ORM\JoinColumn(nullable=true)
  107.      */
  108.     private $hearingBrand;
  109.     /**
  110.      * @ORM\Column(type="float", nullable=true)
  111.      */
  112.     private $latitude;
  113.     /**
  114.      * @ORM\Column(type="float", nullable=true)
  115.      */
  116.     private $longitude;
  117.     /**
  118.      * @ORM\ManyToOne(targetEntity="App\Entity\Administrator", inversedBy="stores")
  119.      */
  120.     private $administrator;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="App\Entity\ProspectOnStore", mappedBy="store")
  123.      */
  124.     private $prospectsOnStore;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity="App\Entity\StoreManagementRequest", mappedBy="store", cascade={"persist"})
  127.      */
  128.     private $managementRequests;
  129.     /**
  130.      * @ORM\Column(type="datetime", nullable=true)
  131.      */
  132.     private $deletedAt;
  133.     /**
  134.      * @var bool
  135.      * @ORM\Column(type="boolean", options={"default" : false})
  136.      */
  137.     private $acquisitionEnabled false;
  138.     /**
  139.      * @var float
  140.      * @ORM\Column(type="float", nullable=true)
  141.      */
  142.     private $reach;
  143.     /**
  144.      * @var bool
  145.      * @ORM\Column(type="integer", options={"default" : 0})
  146.      */
  147.     private int $priority 0;
  148.     /**
  149.      * @ORM\Column(type="string", length=255, nullable=true)
  150.      */
  151.     private $logoPath;
  152.     /**
  153.      * @assert\File( mimeTypes = {"image/jpeg", "image/png", "image/gif", "image/jpg", "image/webp"})
  154.      * @Vich\UploadableField(mapping="store_logo", fileNameProperty="logoPath")
  155.      * @var File
  156.      */
  157.     private $logoFile;
  158.     /**
  159.      * @ORM\Column(type="string", length=25, nullable=true)
  160.      */
  161.     private $siretNumber;
  162.     /**
  163.      * @ORM\Column(type="datetime", nullable=true)
  164.      * @var DateTime
  165.      */
  166.     private $updatedAt;
  167.     /**
  168.      * @ORM\OneToOne(targetEntity="App\Entity\EstimatedReach")
  169.      * @ORM\JoinColumn(nullable=true)
  170.      */
  171.     private $estimatedReach;
  172.     /**
  173.      * String w/ multiple email adresses, splitted with ';'
  174.      * @ORM\Column(type="string", length=255, nullable=true)
  175.      */
  176.     private $emailNotification;
  177.     /**
  178.      * @ORM\Column(type="boolean", nullable=true)
  179.      */
  180.     private $isEmailNotification;
  181.     /**
  182.      * @ORM\OneToMany(targetEntity=StoreCentralPurchasingRelation::class, mappedBy="store", orphanRemoval=true)
  183.      */
  184.     private $storeCentralPurchasingRelations;
  185.     /**
  186.      * @ORM\OneToOne(targetEntity=StorePage::class, inversedBy="store")
  187.      */
  188.     private $storePage;
  189.     /**
  190.      * @var string
  191.      *
  192.      * @Gedmo\Slug(fields={"name","city", "zipCode"})
  193.      * @ORM\Column(type="string", length=255, nullable=false, unique=false)
  194.      */
  195.     private $slug;
  196.     /**
  197.      * Teaser (short text) to help promote this store during qualification
  198.      * ex:
  199.      * Le centre se situe dans le centre commercial des terrasses du port.
  200.      * Ce centre commercialise du haut de gamme à des prix très attractifs.
  201.      * @Assert\Length(
  202.      *      min = 2,
  203.      *      max = 255
  204.      * )
  205.      * @ORM\Column(type="string", length=255, nullable=true)
  206.      * @Groups({"store:read"})
  207.      */
  208.     private $teaser;
  209.     /**
  210.      * @ORM\Column(type="boolean", nullable=true)
  211.      */
  212.     private $handicapAccess;
  213.     /**
  214.      * @ORM\OneToOne(targetEntity=PaymentMethod::class, cascade={"persist", "remove"})
  215.      */
  216.     private $paymentMethod;
  217.     /**
  218.      * @ORM\Column(type="boolean")
  219.      */
  220.     private bool $qualificationEnabled;
  221.     /**
  222.      * @ORM\OneToMany(targetEntity=StoreIndexation::class, mappedBy="store", orphanRemoval=true)
  223.      * @ORM\OrderBy ({"endAt" = "ASC"})
  224.      */
  225.     private Collection $storeIndexations;
  226.     /**
  227.      * @ORM\OneToOne(targetEntity=StorePlaceData::class, mappedBy="store", cascade={"persist", "remove"})
  228.      */
  229.     private ?StorePlaceData $storePlaceData;
  230.     public function __construct()
  231.     {
  232.         $this->owner = new ArrayCollection();
  233.         $this->prospectsOnStore = new ArrayCollection();
  234.         $this->managementRequests = new ArrayCollection();
  235.         $this->storeCentralPurchasingRelations = new ArrayCollection();
  236.         $this->qualificationEnabled true;
  237.         $this->storeIndexations = new ArrayCollection();
  238.     }
  239.     /**
  240.      * Représente l'entité par défault
  241.      * @return string
  242.      */
  243.     public function __toString()
  244.     {
  245.         $string '';
  246.         if (!is_null($this->deletedAt)) {
  247.             $string .= ' SUPPRIME ';
  248.         } else {
  249.             $string .= 'Store ' $this->getName();
  250.         }
  251.         $string .= ' [' $this->getId() . ']';
  252.         return $string;
  253.     }
  254.     /**
  255.      * @Assert\Callback()
  256.      */
  257.     public function validate(ExecutionContextInterface $context$payload)
  258.     {
  259.         //acquisition can NOT be activated if state not valid
  260.         if ($this->acquisitionEnabled && !$this->isStateValid()) {
  261.             $context->buildViolation('L\'acquisition de lead n\'est pas possible tant que le centre n\'a pas été validé')
  262.                 ->atPath('acquisitionEnabled')
  263.                 ->addViolation();
  264.         }
  265.     }
  266.     public function getName(): ?string
  267.     {
  268.         if (!is_null($this->deletedAt)) {
  269.             return $this->name ' (supprimé)';
  270.         }
  271.         return $this->name;
  272.     }
  273.     public function setName(string $name): self
  274.     {
  275.         $this->name $name;
  276.         return $this;
  277.     }
  278.     public function getId(): ?int
  279.     {
  280.         return $this->id;
  281.     }
  282.     /**
  283.      * Représente l'entité dans le BO
  284.      * @return string
  285.      */
  286.     public function getLabel()
  287.     {
  288.         return $this->getName();
  289.     }
  290.     /**
  291.      * @Groups({"store:read"})
  292.      * @return string
  293.      */
  294.     public function getNameAndAddress()
  295.     {
  296.         return $this->name ' (' $this->getAddress() . ', ' $this->getZipCode() . ', ' iconv("UTF-8""UTF-8//IGNORE"$this->getCity()) . ')';
  297.     }
  298.     public function getAddress(): ?string
  299.     {
  300.         return $this->address;
  301.     }
  302.     public function setAddress(?string $address): self
  303.     {
  304.         $this->address $address;
  305.         return $this;
  306.     }
  307.     public function getCity(): ?string
  308.     {
  309.         return strtoupper($this->city);
  310.     }
  311.     public function setCity(?string $city): self
  312.     {
  313.         $this->city $city;
  314.         return $this;
  315.     }
  316.     public function getNameAndZipcodeAndId(): ?string
  317.     {
  318.         return $this->getNameAndZipcode() . ' [' $this->getId() . ']';
  319.     }
  320.     public function getNameAndZipcode()
  321.     {
  322.         return $this->getName() . ' (' $this->getZipCode() . ')';
  323.     }
  324.     public function getZipCode(): ?string
  325.     {
  326.         return $this->zipCode;
  327.     }
  328.     public function setZipCode(?string $zipCode): self
  329.     {
  330.         if (strlen($zipCode) === 4) {
  331.             $this->zipCode str_pad($zipCode5'0'STR_PAD_LEFT);
  332.         } else {
  333.             $this->zipCode $zipCode;
  334.         }
  335.         return $this;
  336.     }
  337.     /**
  338.      * Obtenir l'adresse complète
  339.      * @return string
  340.      */
  341.     public function getFullAddress()
  342.     {
  343.         return $this->getAddress() . ' ' $this->getZipCode() . ' ' $this->getCity();
  344.     }
  345.     public function getAddressDetail(): ?string
  346.     {
  347.         return $this->addressDetail;
  348.     }
  349.     public function setAddressDetail(?string $addressDetail): self
  350.     {
  351.         $this->addressDetail $addressDetail;
  352.         return $this;
  353.     }
  354.     public function getPhoneNumberFormatted(): ?string
  355.     {
  356.         $phoneNumber $this->phoneNumber;
  357.         $formattedPhoneNumber chunk_split($phoneNumber2' ');;
  358.         return $formattedPhoneNumber;
  359.     }
  360.     public function getPhoneNumber(): ?string
  361.     {
  362.         return $this->phoneNumber;
  363.     }
  364.     public function setPhoneNumber(?string $phoneNumber): self
  365.     {
  366.         $phoneNumber Formatter::phoneNumberFrenchFormat($phoneNumber);
  367.         $this->phoneNumber $phoneNumber;
  368.         return $this;
  369.     }
  370.     public function getFax(): ?string
  371.     {
  372.         return $this->fax;
  373.     }
  374.     public function setFax(?string $fax): self
  375.     {
  376.         $this->fax $fax;
  377.         return $this;
  378.     }
  379.     /**
  380.      * @return Collection|Owner[]
  381.      */
  382.     public function getOwners(): Collection
  383.     {
  384.         return $this->owners;
  385.     }
  386.     public function addOwner(Owner $owner): self
  387.     {
  388.         if (!$this->owners->contains($owner)) {
  389.             $this->owners[] = $owner;
  390.             $owner->setStore($this);
  391.         }
  392.         return $this;
  393.     }
  394.     public function removeOwner(Owner $owner): self
  395.     {
  396.         if ($this->owners->contains($owner)) {
  397.             $this->owners->removeElement($owner);
  398.             // set the owning side to null (unless already changed)
  399.             if ($owner->getStore() === $this) {
  400.                 $owner->setStore(null);
  401.             }
  402.         }
  403.         return $this;
  404.     }
  405.     /**
  406.      * @return Collection|Prospect[]
  407.      */
  408.     public function getProspects(): Collection
  409.     {
  410.         return $this->prospects;
  411.     }
  412.     public function addProspect(Prospect $prospect): self
  413.     {
  414.         if (!$this->prospects->contains($prospect)) {
  415.             $this->prospects[] = $prospect;
  416.             $prospect->addStore($this);
  417.         }
  418.         return $this;
  419.     }
  420.     public function removeProspect(Prospect $prospect): self
  421.     {
  422.         if ($this->prospects->contains($prospect)) {
  423.             $this->prospects->removeElement($prospect);
  424.             $prospect->removeStore($this);
  425.         }
  426.         return $this;
  427.     }
  428.     public function getHearingBrand(): ?HearingBrand
  429.     {
  430.         return $this->hearingBrand;
  431.     }
  432.     public function setHearingBrand(?HearingBrand $hearingBrand): self
  433.     {
  434.         $this->hearingBrand $hearingBrand;
  435.         return $this;
  436.     }
  437.     public function getLatitude()
  438.     {
  439.         return $this->latitude;
  440.     }
  441.     public function setLatitude($latitude): self
  442.     {
  443.         $this->latitude $latitude;
  444.         return $this;
  445.     }
  446.     public function getLongitude()
  447.     {
  448.         return $this->longitude;
  449.     }
  450.     public function setLongitude($longitude): self
  451.     {
  452.         $this->longitude $longitude;
  453.         return $this;
  454.     }
  455.     public function hasLatitudeAndLongitude()
  456.     {
  457.         return !is_null($this->longitude) && !is_null($this->latitude);
  458.     }
  459.     /**
  460.      * @return Collection|Owner[]
  461.      */
  462.     public function getOwner(): Collection
  463.     {
  464.         return $this->owner;
  465.     }
  466.     /**
  467.      * @return Collection|ProspectOnStore[]
  468.      */
  469.     public function getProspectsOnStore(): Collection
  470.     {
  471.         return $this->prospectsOnStore;
  472.     }
  473.     public function addProspectsOnStore(ProspectOnStore $prospectsOnStore): self
  474.     {
  475.         if (!$this->prospectsOnStore->contains($prospectsOnStore)) {
  476.             $this->prospectsOnStore[] = $prospectsOnStore;
  477.             $prospectsOnStore->setStore($this);
  478.         }
  479.         return $this;
  480.     }
  481.     public function removeProspectsOnStore(ProspectOnStore $prospectsOnStore): self
  482.     {
  483.         if ($this->prospectsOnStore->contains($prospectsOnStore)) {
  484.             $this->prospectsOnStore->removeElement($prospectsOnStore);
  485.             // set the owning side to null (unless already changed)
  486.             if ($prospectsOnStore->getStore() === $this) {
  487.                 $prospectsOnStore->setStore(null);
  488.             }
  489.         }
  490.         return $this;
  491.     }
  492.     public function addManagementRequests(StoreManagementRequest $managementRequest): self
  493.     {
  494.         if (!$this->managementRequests->contains($managementRequest)) {
  495.             $this->managementRequests[] = $managementRequest;
  496.             $managementRequest->setStore($this);
  497.         }
  498.         return $this;
  499.     }
  500.     public function getState(): ?string
  501.     {
  502.         return $this->state;
  503.     }
  504.     public function setState(string $state): self
  505.     {
  506.         $this->state $state;
  507.         return $this;
  508.     }
  509.     public function isStateValid(): ?string
  510.     {
  511.         return $this->state == self::STATE_VALID;
  512.     }
  513.     public function getDeletedAt(): ?\DateTimeInterface
  514.     {
  515.         return $this->deletedAt;
  516.     }
  517.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  518.     {
  519.         $this->deletedAt $deletedAt;
  520.         return $this;
  521.     }
  522.     /**
  523.      * @return Collection|StoreManagementRequest[]
  524.      */
  525.     public function getManagementRequests(): Collection
  526.     {
  527.         return $this->managementRequests;
  528.     }
  529.     public function addManagementRequest(StoreManagementRequest $managementRequest): self
  530.     {
  531.         if (!$this->managementRequests->contains($managementRequest)) {
  532.             $this->managementRequests[] = $managementRequest;
  533.             $managementRequest->setStore($this);
  534.         }
  535.         return $this;
  536.     }
  537.     public function removeManagementRequest(StoreManagementRequest $managementRequest): self
  538.     {
  539.         if ($this->managementRequests->contains($managementRequest)) {
  540.             $this->managementRequests->removeElement($managementRequest);
  541.             // set the owning side to null (unless already changed)
  542.             if ($managementRequest->getStore() === $this) {
  543.                 $managementRequest->setStore(null);
  544.             }
  545.         }
  546.         return $this;
  547.     }
  548.     public function getReach(): ?float
  549.     {
  550.         return $this->reach;
  551.     }
  552.     public function setReach(float $reach): self
  553.     {
  554.         $this->reach $reach;
  555.         return $this;
  556.     }
  557.     public function getIsPriority(): ?bool
  558.     {
  559.         return $this->priority 0;
  560.     }
  561.     public function getPriority(): int
  562.     {
  563.         return $this->priority;
  564.     }
  565.     public function getPriorityLabel(): string
  566.     {
  567.         return StorePriorityEnum::getPriorityName($this->priority);
  568.     }
  569.     public function setPriority(int $priority): self
  570.     {
  571.         $this->priority $priority;
  572.         return $this;
  573.     }
  574.     public function getLogoFile()
  575.     {
  576.         return $this->logoFile;
  577.     }
  578.     public function setLogoFile(File $image null)
  579.     {
  580.         $this->logoFile $image;
  581.         //update timestamp
  582.         if ($image) {
  583.             $this->updatedAt = new DateTime('now');
  584.         }
  585.         return $this;
  586.     }
  587.     public function hasLogo()
  588.     {
  589.         return !empty($this->getLogoPath());
  590.     }
  591.     public function getLogoPath(): ?string
  592.     {
  593.         return $this->logoPath;
  594.     }
  595.     public function setLogoPath(string $logoPath null): self
  596.     {
  597.         $this->logoPath $logoPath;
  598.         return $this;
  599.     }
  600.     public function getUpdatedAt(): ?\DateTimeInterface
  601.     {
  602.         return $this->updatedAt;
  603.     }
  604.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  605.     {
  606.         $this->updatedAt $updatedAt;
  607.         return $this;
  608.     }
  609.     public function getSiretNumber(): ?string
  610.     {
  611.         return $this->siretNumber;
  612.     }
  613.     public function setSiretNumber(?string $siretNumber): self
  614.     {
  615.         $siretNumber str_replace(' '''$siretNumber);
  616.         $this->siretNumber $siretNumber;
  617.         return $this;
  618.     }
  619.     public function getEmailList(): array
  620.     {
  621.         // Optim: use constant for delimiter?
  622.         return explode(";"$this->getEmailNotification());
  623.     }
  624.     public function getEmailNotification(): ?string
  625.     {
  626.         return $this->emailNotification;
  627.     }
  628.     public function mustBeNotifiedByEmail(): ?bool
  629.     {
  630.         return $this->getIsEmailNotification() && !empty($this->getEmailNotification());
  631.     }
  632.     public function setEmailNotification(?string $email): self
  633.     {
  634.         $this->emailNotification $email;
  635.         return $this;
  636.     }
  637.     public function getEstimatedReach(): ?EstimatedReach
  638.     {
  639.         return $this->estimatedReach;
  640.     }
  641.     public function setEstimatedReach(EstimatedReach $estimatedReach): self
  642.     {
  643.         $this->estimatedReach $estimatedReach;
  644.         return $this;
  645.     }
  646.     public function getIsEmailNotification(): ?bool
  647.     {
  648.         return $this->isEmailNotification;
  649.     }
  650.     // Returns an array with every mail addresses for a store
  651.     public function setIsEmailNotification(?bool $isEmailNotification): self
  652.     {
  653.         $this->isEmailNotification $isEmailNotification;
  654.         return $this;
  655.     }
  656.     public function isOpenedForProspect(): bool
  657.     {
  658.         if (!$this->isIndexable()) {
  659.             return false;
  660.         }
  661.         $isAcquisitionEnabled $this->getAcquisitionEnabled();
  662.         //business model
  663.         $businessModelPerformance = !is_null($this->getAdministrator()) && $this->administrator->isPerformance();
  664.         //if not performance, search for credit
  665.         if (!$businessModelPerformance) {
  666.             //adminIsActive : partner or freelance with credit
  667.             $adminIsActive = !is_null($this->getAdministrator()) && $this->getAdministrator()->isCustomer();
  668.             $associatedToCentralPurchasingWithCredit false;
  669.             //is not active, search for active centralPurchasing
  670.             if (!$adminIsActive) {
  671.                 foreach ($this->getStoreCentralPurchasingRelations() as $cpr) {
  672.                     if ($cpr->isEnabled() && $cpr->getCentralPurchasing()->getNbCredit() > 0) {
  673.                         $associatedToCentralPurchasingWithCredit true;
  674.                         break;
  675.                     }
  676.                 }
  677.             }
  678.         }
  679.         return $isAcquisitionEnabled && ($businessModelPerformance || ($adminIsActive || $associatedToCentralPurchasingWithCredit));
  680.     }
  681.     public function getAcquisitionEnabled(): ?bool
  682.     {
  683.         return $this->acquisitionEnabled;
  684.     }
  685.     public function setAcquisitionEnabled(bool $acquisitionEnabled): self
  686.     {
  687.         $this->acquisitionEnabled $acquisitionEnabled;
  688.         return $this;
  689.     }
  690.     public function getAdministrator(): ?Administrator
  691.     {
  692.         return $this->administrator;
  693.     }
  694.     public function setAdministrator(?Administrator $administrator): self
  695.     {
  696.         $this->administrator $administrator;
  697.         return $this;
  698.     }
  699.     /**
  700.      * @return Collection|StoreCentralPurchasingRelation[]
  701.      */
  702.     public function getStoreCentralPurchasingRelations(): Collection
  703.     {
  704.         return $this->storeCentralPurchasingRelations;
  705.     }
  706.     public function addStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
  707.     {
  708.         if (!$this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
  709.             $this->storeCentralPurchasingRelations[] = $storeCentralPurchasingRelation;
  710.             $storeCentralPurchasingRelation->setStore($this);
  711.         }
  712.         return $this;
  713.     }
  714.     public function removeStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
  715.     {
  716.         if ($this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
  717.             $this->storeCentralPurchasingRelations->removeElement($storeCentralPurchasingRelation);
  718.             // set the owning side to null (unless already changed)
  719.             if ($storeCentralPurchasingRelation->getStore() === $this) {
  720.                 $storeCentralPurchasingRelation->setStore(null);
  721.             }
  722.         }
  723.         return $this;
  724.     }
  725.     public function getFreelancerAssistant(): ?FreelancerAssistant
  726.     {
  727.         return $this->freelancerAssistant;
  728.     }
  729.     public function setFreelancerAssistant(?FreelancerAssistant $freelancerAssistant): self
  730.     {
  731.         $this->freelancerAssistant $freelancerAssistant;
  732.         return $this;
  733.     }
  734.     public function hasStorePage(): bool
  735.     {
  736.         return !is_null($this->storePage);
  737.     }
  738.     public function getStorePage(): ?StorePage
  739.     {
  740.         return $this->storePage;
  741.     }
  742.     public function setStorePage(?StorePage $storePage): self
  743.     {
  744.         $this->storePage $storePage;
  745.         return $this;
  746.     }
  747.     public function hasPagePremium(): bool
  748.     {
  749.         return !is_null($this->storePage);
  750.     }
  751.     public function getSlug(): ?string
  752.     {
  753.         return $this->slug;
  754.     }
  755.     public function setSlug(?string $slug): self
  756.     {
  757.         $this->slug $slug;
  758.         return $this;
  759.     }
  760.     public function getTeaser(): ?string
  761.     {
  762.         return $this->teaser;
  763.     }
  764.     public function setTeaser(?string $teaser): self
  765.     {
  766.         $this->teaser $teaser;
  767.         return $this;
  768.     }
  769.     /**
  770.      * Return name and city.
  771.      * If city as area, the number of the area is displayed. ex: AUDIKA (13006)
  772.      * Lyon (690xx) Marseille (130xx) and Paris (750xx)
  773.      * @return string
  774.      */
  775.     public function getNameAndCity()
  776.     {
  777.         $areaString '';
  778.         $cityString iconv("UTF-8""UTF-8//IGNORE"$this->getCity());
  779.         preg_match('/^(?:13|75|69)0(\d{2})$/'$this->getZipCode(), $areaNumberResult);
  780.         if (count($areaNumberResult) > 0) {
  781.             $areaString ' ' $areaNumberResult[1];
  782.         }
  783.         return $this->name ' (' $cityString $areaString ')';
  784.     }
  785.     public function getHandicapAccess(): ?bool
  786.     {
  787.         return $this->handicapAccess;
  788.     }
  789.     public function setHandicapAccess(?bool $handicapAccess): self
  790.     {
  791.         $this->handicapAccess $handicapAccess;
  792.         return $this;
  793.     }
  794.     public function getPaymentMethod(): ?PaymentMethod
  795.     {
  796.         return $this->paymentMethod;
  797.     }
  798.     public function setPaymentMethod(?PaymentMethod $paymentMethod): self
  799.     {
  800.         $this->paymentMethod $paymentMethod;
  801.         return $this;
  802.     }
  803.     public function isQualificationEnabled(): ?bool
  804.     {
  805.         return $this->qualificationEnabled;
  806.     }
  807.     public function setQualificationEnabled(bool $qualificationEnabled): self
  808.     {
  809.         $this->qualificationEnabled $qualificationEnabled;
  810.         return $this;
  811.     }
  812.     /**
  813.      * @return Collection<int, StoreIndexation>
  814.      */
  815.     public function getStoreIndexations(): Collection
  816.     {
  817.         return $this->storeIndexations;
  818.     }
  819.     /**
  820.      * Return current store indexation
  821.      * @return StoreIndexation|null
  822.      */
  823.     public function getCurrentStoreIndexation(): ?StoreIndexation
  824.     {
  825.         $now = new DateTime();
  826.         $firstIndexation $this->storeIndexations->filter(function (StoreIndexation $storeIndexation) use ($now) {
  827.             return $storeIndexation->getStartAt() <= $now && $storeIndexation->getEndAt() >= $now;
  828.         })->first();
  829.         return $firstIndexation $firstIndexation null;
  830.     }
  831.     public function hasCurrentStoreIndexation(): bool
  832.     {
  833.         return !is_null($this->getCurrentStoreIndexation());
  834.     }
  835.     /**
  836.      * Return not expired store indexation
  837.      * @return ArrayCollection
  838.      */
  839.     public function getNotExpiredStoreIndexations(): ArrayCollection
  840.     {
  841.         $now = new DateTime();
  842.         return $this->storeIndexations->filter(function (StoreIndexation $storeIndexation) use ($now) {
  843.             return $storeIndexation->getEndAt() >= $now;
  844.         });
  845.     }
  846.     public function getLastNotExpiredStoreIndexation(): ?StoreIndexation
  847.     {
  848.         $notExpiredStoreIndexations $this->getNotExpiredStoreIndexations();
  849.         $last $notExpiredStoreIndexations->last();
  850.         return $last $last null;
  851.     }
  852.     public function isIndexableFromBusinessModel(): bool
  853.     {
  854.         $admin $this->getAdministrator();
  855.         //only true for partner and freelance who had credit when we changed the business model (v2)
  856.         return $admin && ($admin->isPartner() || ($admin->isFreelancer() && $admin->hasAllStoresIndexableTemporary()));
  857.     }
  858.     public function isIndexable(): bool
  859.     {
  860.         //TODO: quand plus aucun indé n'aura de business model "crédit" sans centre indexé, le 1er test pourra être remplacé par "isPartner()"
  861.         return $this->isIndexableFromBusinessModel() ||
  862.             $this->hasCurrentStoreIndexation();
  863.     }
  864.     public function addStoreIndexation(StoreIndexation $storeIndexation): self
  865.     {
  866.         if (!$this->storeIndexations->contains($storeIndexation)) {
  867.             $this->storeIndexations[] = $storeIndexation;
  868.             $storeIndexation->setStore($this);
  869.         }
  870.         return $this;
  871.     }
  872.     public function removeStoreIndexation(StoreIndexation $storeIndexation): self
  873.     {
  874.         if ($this->storeIndexations->removeElement($storeIndexation)) {
  875.             // set the owning side to null (unless already changed)
  876.             if ($storeIndexation->getStore() === $this) {
  877.                 $storeIndexation->setStore(null);
  878.             }
  879.         }
  880.         return $this;
  881.     }
  882.     public function getStorePlaceData(): ?StorePlaceData
  883.     {
  884.         return $this->storePlaceData;
  885.     }
  886.     public function setStorePlaceData(?StorePlaceData $storePlaceData): self
  887.     {
  888.         // unset the owning side of the relation if necessary
  889.         if ($storePlaceData === null && $this->storePlaceData !== null) {
  890.             $this->storePlaceData->setStore(null);
  891.         }
  892.         // set the owning side of the relation if necessary
  893.         if ($storePlaceData !== null && $storePlaceData->getStore() !== $this) {
  894.             $storePlaceData->setStore($this);
  895.         }
  896.         $this->storePlaceData $storePlaceData;
  897.         return $this;
  898.     }
  899. }