<?php namespace Lc\CaracoleBundle\Model\User; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Lc\CaracoleBundle\Model\Order\OrderShopInterface; /** * @ORM\MappedSuperclass() */ abstract class VisitorModel { /** * @ORM\Column(type="string", length=255) */ protected $cookie; /** * @ORM\Column(type="datetime") */ protected $lastAccess; /** * @ORM\Column(type="string", length=255) */ protected $ip; /** * @ORM\Column(type="integer") */ protected $totalVisit; /** * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Order\OrderShopInterface", mappedBy="visitor") */ protected $orders; public function __construct() { $this->orders = new ArrayCollection(); } public function __toString() { return $this->getLastAccess()->format('d-m-y h:i') . '( visites :' . $this->totalVisit . ')'; } public function getSummary() { return 'Visiteur non inscrit ( visites :' . $this->totalVisit . ')'; } public function getCookie(): ?string { return $this->cookie; } public function setCookie(?string $cookie): self { $this->cookie = $cookie; return $this; } public function getLastAccess(): ?\DateTimeInterface { return $this->lastAccess; } public function setLastAccess(\DateTimeInterface $lastAccess): self { $this->lastAccess = $lastAccess; return $this; } public function getIp(): ?string { return $this->ip; } public function setIp(?string $ip): self { $this->ip = $ip; return $this; } public function getTotalVisit(): ?int { return $this->totalVisit; } public function setTotalVisit(int $totalVisit): self { $this->totalVisit = $totalVisit; return $this; } /** * @return Collection|OrderShopInterface[] */ public function getOrders(): Collection { return $this->orders; } public function addOrder(OrderShopInterface $order): self { if (!$this->orders->contains($order)) { $this->orders[] = $order; $order->setVisitor($this); } return $this; } public function removeOrder(OrderShopInterface $order): self { if ($this->orders->contains($order)) { $this->orders->removeElement($order); // set the owning side to null (unless already changed) if ($order->getVisitor() === $this) { $order->setVisitor(null); } } return $this; } }