124 line
2.8KB

  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 getCookie(): ?string
  37. {
  38. return $this->cookie;
  39. }
  40. public function setCookie(?string $cookie): self
  41. {
  42. $this->cookie = $cookie;
  43. return $this;
  44. }
  45. public function getLastAccess(): ?\DateTimeInterface
  46. {
  47. return $this->lastAccess;
  48. }
  49. public function setLastAccess(\DateTimeInterface $lastAccess): self
  50. {
  51. $this->lastAccess = $lastAccess;
  52. return $this;
  53. }
  54. public function getIp(): ?string
  55. {
  56. return $this->ip;
  57. }
  58. public function setIp(?string $ip): self
  59. {
  60. $this->ip = $ip;
  61. return $this;
  62. }
  63. public function getTotalVisit(): ?int
  64. {
  65. return $this->totalVisit;
  66. }
  67. public function setTotalVisit(int $totalVisit): self
  68. {
  69. $this->totalVisit = $totalVisit;
  70. return $this;
  71. }
  72. /**
  73. * @return Collection|OrderShop[]
  74. */
  75. public function getOrders(): Collection
  76. {
  77. return $this->orders;
  78. }
  79. public function addOrder(OrderShop $order): self
  80. {
  81. if (!$this->orders->contains($order)) {
  82. $this->orders[] = $order;
  83. $order->setVisitor($this);
  84. }
  85. return $this;
  86. }
  87. public function removeOrder(OrderShop $order): self
  88. {
  89. if ($this->orders->contains($order)) {
  90. $this->orders->removeElement($order);
  91. // set the owning side to null (unless already changed)
  92. if ($order->getVisitor() === $this) {
  93. $order->setVisitor(null);
  94. }
  95. }
  96. return $this;
  97. }
  98. }