před 4 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\OrderShop;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\MappedSuperclass()
  9. */
  10. abstract class Visitor
  11. {
  12. /**
  13. * @ORM\Column(type="string", length=255)
  14. */
  15. protected $cookie;
  16. /**
  17. * @ORM\Column(type="datetime")
  18. */
  19. protected $lastAccess;
  20. /**
  21. * @ORM\Column(type="string", length=255)
  22. */
  23. protected $ip;
  24. /**
  25. * @ORM\Column(type="integer")
  26. */
  27. protected $totalVisit;
  28. /**
  29. * @ORM\OneToMany(targetEntity="App\Entity\OrderShop", mappedBy="visitor")
  30. */
  31. protected $orders;
  32. public function __construct()
  33. {
  34. $this->orders = new ArrayCollection();
  35. }
  36. public function __toString()
  37. {
  38. return $this->getLastAccess()->format('d-m-y h:i') .'( visites :'.$this->totalVisit.')';
  39. }
  40. public function getSummary(){
  41. return 'Visiteur non inscrit ( visites :'.$this->totalVisit.')';
  42. }
  43. public function getCookie(): ?string
  44. {
  45. return $this->cookie;
  46. }
  47. public function setCookie(?string $cookie): self
  48. {
  49. $this->cookie = $cookie;
  50. return $this;
  51. }
  52. public function getLastAccess(): ?\DateTimeInterface
  53. {
  54. return $this->lastAccess;
  55. }
  56. public function setLastAccess(\DateTimeInterface $lastAccess): self
  57. {
  58. $this->lastAccess = $lastAccess;
  59. return $this;
  60. }
  61. public function getIp(): ?string
  62. {
  63. return $this->ip;
  64. }
  65. public function setIp(?string $ip): self
  66. {
  67. $this->ip = $ip;
  68. return $this;
  69. }
  70. public function getTotalVisit(): ?int
  71. {
  72. return $this->totalVisit;
  73. }
  74. public function setTotalVisit(int $totalVisit): self
  75. {
  76. $this->totalVisit = $totalVisit;
  77. return $this;
  78. }
  79. /**
  80. * @return Collection|OrderShop[]
  81. */
  82. public function getOrders(): Collection
  83. {
  84. return $this->orders;
  85. }
  86. public function addOrder(OrderShop $order): self
  87. {
  88. if (!$this->orders->contains($order)) {
  89. $this->orders[] = $order;
  90. $order->setVisitor($this);
  91. }
  92. return $this;
  93. }
  94. public function removeOrder(OrderShop $order): self
  95. {
  96. if ($this->orders->contains($order)) {
  97. $this->orders->removeElement($order);
  98. // set the owning side to null (unless already changed)
  99. if ($order->getVisitor() === $this) {
  100. $order->setVisitor(null);
  101. }
  102. }
  103. return $this;
  104. }
  105. }