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.8KB

před 3 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. }