<?phpnamespace App\Entity;use App\Repository\ShopPanierRepository;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Doctrine\Persistence\Event\LifecycleEventArgs;/** * @ORM\Entity(repositoryClass=ShopPanierRepository::class) * @ORM\HasLifecycleCallbacks */class ShopPanier{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\ManyToOne(targetEntity=User::class, inversedBy="shopPaniers") * @ORM\JoinColumn(nullable=false) */ private $user; /** * @ORM\ManyToOne(targetEntity=ShopProduit::class) * @ORM\JoinColumn(nullable=false) */ private $produit; /** * @ORM\Column(type="integer") */ private $unit; /** * @ORM\Column(type="datetime") * @Gedmo\Timestampable(on="create") */ private $createdAt; /** * @ORM\Column(type="datetime") * @Gedmo\Timestampable(on="update") */ private $updatedAt; /** * @ORM\Column(type="string", length=50) */ private $domaine; /** * @ORM\Column(type="string", length=255) */ private $reference; /** * @ORM\ManyToOne(targetEntity=ShopUserAdress::class, inversedBy="paniers") * @ORM\JoinColumn(nullable=false) */ private $adress; public function getId(): ?int { return $this->id; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): self { $this->user = $user; return $this; } public function getProduit(): ?ShopProduit { return $this->produit; } public function setProduit(?ShopProduit $produit): self { $this->produit = $produit; return $this; } public function getUnit(): ?int { return $this->unit; } public function setUnit(int $unit): self { $this->unit = $unit; return $this; } public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } public function setCreatedAt(?\DateTimeInterface $createdAt): self { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } public function setUpdatedAt(?\DateTimeInterface $updatedAt): self { $this->updatedAt = $updatedAt; return $this; } public function getDomaine(): ?string { return $this->domaine; } public function setDomaine(string $domaine): self { $this->domaine = $domaine; return $this; } public function getReference(): ?string { return $this->reference; } public function setReference(?string $reference=null): self { if (!$reference) { $brother = $this->getUser()->getShopPaniers()->filter(function($element) { return $element->getReference(); })->current(); if ($brother) { $reference = $brother->getReference(); } } if (!$reference) { $reference = $this->getUser()->getId().date('dmYHis'); } $this->reference = $reference; return $this; } /** * @ORM\PrePersist */ public function PrePersist(){ $this->setReference(); } public function getAdress(): ?ShopUserAdress { return $this->adress; } public function setAdress(?ShopUserAdress $adress): self { $this->adress = $adress; return $this; }}