src/Entity/Magasin.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MagasinRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassMagasinRepository::class)]
  8. class Magasin
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length150)]
  15.     private ?string $nom null;
  16.     #[ORM\Column(length255nullabletrue)]
  17.     private ?string $logo_path null;
  18.     #[ORM\Column(nullabletrue)]
  19.     private ?bool $active null;
  20.     // ── Subscription: shop is live on the storefront until this date ──
  21.     #[ORM\Column(name'subscription_paid_until'type'date'nullabletrue)]
  22.     private ?\DateTimeInterface $subscriptionPaidUntil null;
  23.     // ── location ─────────────────────────────────────────────────
  24.     #[ORM\ManyToOne(targetEntityCountry::class)]
  25.     #[ORM\JoinColumn(name'country_id'referencedColumnName'id'nullabletrueonDelete'SET NULL')]
  26.     private ?Country $country null;
  27.     #[ORM\ManyToOne(targetEntityRegion::class)]
  28.     #[ORM\JoinColumn(name'region_id'referencedColumnName'id'nullabletrueonDelete'SET NULL')]
  29.     private ?Region $region null;
  30.     #[ORM\ManyToOne(targetEntityCity::class)]
  31.     #[ORM\JoinColumn(name'city_id'referencedColumnName'id'nullabletrueonDelete'SET NULL')]
  32.     private ?City $city null;
  33.     // ── seller / invoice details (legal info shown on invoices) ──
  34.     #[ORM\Column(name'adresse'length255nullabletrue)]
  35.     private ?string $adresse null;
  36.     #[ORM\Column(name'telephone'length50nullabletrue)]
  37.     private ?string $telephone null;
  38.     /** Commercial Register number (CR / Registre du Commerce). */
  39.     #[ORM\Column(name'numero_cr'length100nullabletrue)]
  40.     private ?string $numeroCR null;
  41.     /** VAT registration number (TVA). */
  42.     #[ORM\Column(name'numero_tva'length100nullabletrue)]
  43.     private ?string $numeroTVA null;
  44.     // ── delivery fee matrix ──────────────────────────────────────
  45.     /** @var Collection<int, MagasinDeliveryFee> */
  46.     #[ORM\OneToMany(mappedBy'magasin'targetEntityMagasinDeliveryFee::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  47.     private Collection $deliveryFees;
  48.     #[ORM\OneToMany(mappedBy'magasin'targetEntityMagasinUser::class)]
  49.     private Collection $magasinsUser;
  50.     #[ORM\OneToMany(mappedBy'magasin'targetEntityProduit::class)]
  51.     private Collection $produits;
  52.     public function __construct()
  53.     {
  54.         $this->user_id = new ArrayCollection();
  55.         $this->users = new ArrayCollection();
  56.         $this->magasinsUser = new ArrayCollection();
  57.         $this->produits = new ArrayCollection();
  58.         $this->deliveryFees = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int { return $this->id; }
  61.     public function getNom(): ?string { return $this->nom; }
  62.     public function setNom(string $nom): static { $this->nom $nom; return $this; }
  63.     public function getLogoPath(): ?string { return $this->logo_path; }
  64.     public function setLogoPath(?string $logo_path): static { $this->logo_path $logo_path; return $this; }
  65.     public function isActive(): ?bool { return $this->active; }
  66.     public function setActive(?bool $active): static { $this->active $active; return $this; }
  67.     // ── Subscription ─────────────────────────────────────────────
  68.     public function getSubscriptionPaidUntil(): ?\DateTimeInterface { return $this->subscriptionPaidUntil; }
  69.     public function setSubscriptionPaidUntil(?\DateTimeInterface $d): static { $this->subscriptionPaidUntil $d; return $this; }
  70.     /** Visible on the storefront: must be active and, if a date is set, not expired. */
  71.     public function isLive(): bool
  72.     {
  73.         if ($this->active !== true) { return false; }
  74.         if ($this->subscriptionPaidUntil === null) { return true; } // grandfathered / no expiry tracked
  75.         return $this->subscriptionPaidUntil >= new \DateTime('today');
  76.     }
  77.     /** Days remaining; null if no date set, negative if already expired. */
  78.     public function daysLeft(): ?int
  79.     {
  80.         if ($this->subscriptionPaidUntil === null) { return null; }
  81.         $diff = (new \DateTime('today'))->diff($this->subscriptionPaidUntil);
  82.         return $diff->invert === ? -((int) $diff->days) : (int) $diff->days;
  83.     }
  84.     // ── location getters/setters ─────────────────────────────────
  85.     public function getCountry(): ?Country { return $this->country; }
  86.     public function setCountry(?Country $country): static { $this->country $country; return $this; }
  87.     public function getRegion(): ?Region { return $this->region; }
  88.     public function setRegion(?Region $region): static { $this->region $region; return $this; }
  89.     public function getCity(): ?City { return $this->city; }
  90.     public function setCity(?City $city): static { $this->city $city; return $this; }
  91.     // ── seller / invoice details getters/setters ─────────────────
  92.     public function getAdresse(): ?string { return $this->adresse; }
  93.     public function setAdresse(?string $adresse): static { $this->adresse $adresse; return $this; }
  94.     public function getTelephone(): ?string { return $this->telephone; }
  95.     public function setTelephone(?string $telephone): static { $this->telephone $telephone; return $this; }
  96.     public function getNumeroCR(): ?string { return $this->numeroCR; }
  97.     public function setNumeroCR(?string $numeroCR): static { $this->numeroCR $numeroCR; return $this; }
  98.     public function getNumeroTVA(): ?string { return $this->numeroTVA; }
  99.     public function setNumeroTVA(?string $numeroTVA): static { $this->numeroTVA $numeroTVA; return $this; }
  100.     // ── delivery fees ────────────────────────────────────────────
  101.     /** @return Collection<int, MagasinDeliveryFee> */
  102.     public function getDeliveryFees(): Collection { return $this->deliveryFees; }
  103.     public function addDeliveryFee(MagasinDeliveryFee $fee): static
  104.     {
  105.         if (!$this->deliveryFees->contains($fee)) {
  106.             $this->deliveryFees->add($fee);
  107.             $fee->setMagasin($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeDeliveryFee(MagasinDeliveryFee $fee): static
  112.     {
  113.         if ($this->deliveryFees->removeElement($fee)) {
  114.             if ($fee->getMagasin() === $this) {
  115.                 $fee->setMagasin(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     /** Convenience: returns the fee row for a given region, or null if none exists yet. */
  121.     public function getDeliveryFeeForRegion(Region $region): ?MagasinDeliveryFee
  122.     {
  123.         foreach ($this->deliveryFees as $f) {
  124.             if ($f->getRegion() && $f->getRegion()->getId() === $region->getId()) {
  125.                 return $f;
  126.             }
  127.         }
  128.         return null;
  129.     }
  130.     /** Convenience: true if shop has explicitly enabled delivery to this region. */
  131.     public function canDeliverTo(Region $region): bool
  132.     {
  133.         $f $this->getDeliveryFeeForRegion($region);
  134.         return $f !== null && $f->canDeliver();
  135.     }
  136.     public function __toString(): string
  137.     {
  138.         return $this->nom ?? '';
  139.     }
  140.     /** @return Collection<int, MagasinUser> */
  141.     public function getMagasinsUser(): Collection { return $this->magasinsUser; }
  142.     public function addMagasinsUser(MagasinUser $magasinsUser): static
  143.     {
  144.         if (!$this->magasinsUser->contains($magasinsUser)) {
  145.             $this->magasinsUser->add($magasinsUser);
  146.             $magasinsUser->setMagasin($this);
  147.         }
  148.         return $this;
  149.     }
  150.     public function removeMagasinsUser(MagasinUser $magasinsUser): static
  151.     {
  152.         if ($this->magasinsUser->removeElement($magasinsUser)) {
  153.             if ($magasinsUser->getMagasin() === $this) {
  154.                 $magasinsUser->setMagasin(null);
  155.             }
  156.         }
  157.         return $this;
  158.     }
  159.     /** @return Collection<int, Produit> */
  160.     public function getProduits(): Collection { return $this->produits; }
  161.     public function addProduit(Produit $produit): static
  162.     {
  163.         if (!$this->produits->contains($produit)) {
  164.             $this->produits->add($produit);
  165.             $produit->setMagasin($this);
  166.         }
  167.         return $this;
  168.     }
  169.     public function removeProduit(Produit $produit): static
  170.     {
  171.         if ($this->produits->removeElement($produit)) {
  172.             if ($produit->getMagasin() === $this) {
  173.                 $produit->setMagasin(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178. }