Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VisitorModel.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /**
  8. * @ORM\MappedSuperclass()
  9. */
  10. abstract class VisitorModel
  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="Lc\CaracoleBundle\Model\Order\OrderShopInterface", 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. {
  42. return 'Visiteur non inscrit ( visites :' . $this->totalVisit . ')';
  43. }
  44. public function getCookie(): ?string
  45. {
  46. return $this->cookie;
  47. }
  48. public function setCookie(?string $cookie): self
  49. {
  50. $this->cookie = $cookie;
  51. return $this;
  52. }
  53. public function getLastAccess(): ?\DateTimeInterface
  54. {
  55. return $this->lastAccess;
  56. }
  57. public function setLastAccess(\DateTimeInterface $lastAccess): self
  58. {
  59. $this->lastAccess = $lastAccess;
  60. return $this;
  61. }
  62. public function getIp(): ?string
  63. {
  64. return $this->ip;
  65. }
  66. public function setIp(?string $ip): self
  67. {
  68. $this->ip = $ip;
  69. return $this;
  70. }
  71. public function getTotalVisit(): ?int
  72. {
  73. return $this->totalVisit;
  74. }
  75. public function setTotalVisit(int $totalVisit): self
  76. {
  77. $this->totalVisit = $totalVisit;
  78. return $this;
  79. }
  80. /**
  81. * @return Collection|OrderShopInterface[]
  82. */
  83. public function getOrders(): Collection
  84. {
  85. return $this->orders;
  86. }
  87. public function addOrder(OrderShopInterface $order): self
  88. {
  89. if (!$this->orders->contains($order)) {
  90. $this->orders[] = $order;
  91. $order->setVisitor($this);
  92. }
  93. return $this;
  94. }
  95. public function removeOrder(OrderShopInterface $order): self
  96. {
  97. if ($this->orders->contains($order)) {
  98. $this->orders->removeElement($order);
  99. // set the owning side to null (unless already changed)
  100. if ($order->getVisitor() === $this) {
  101. $order->setVisitor(null);
  102. }
  103. }
  104. return $this;
  105. }
  106. }