You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
2.8KB

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