src/ProductBundle/Entity/ProductFavorite.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\ProductBundle\Entity;
  3. use App\UserBundle\Entity\User;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * @ORM\HasLifecycleCallbacks
  7. * @ORM\Table("product_favorite")
  8. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\ProductFavoriteRepository")
  9. */
  10. class ProductFavorite
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User")
  15. */
  16. private ?User $user = null;
  17. /**
  18. * @ORM\Id
  19. * @ORM\ManyToOne(targetEntity="App\ProductBundle\Entity\Product", inversedBy="favorites")
  20. */
  21. private ?Product $product = null;
  22. /**
  23. * @ORM\Column(type="datetime")
  24. */
  25. private ?\DateTimeInterface $created = null;
  26. /**
  27. * Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
  28. *
  29. * @ORM\PrePersist
  30. * @ORM\PreUpdate
  31. */
  32. public function updatedTimestamps(): void
  33. {
  34. if ($this->getCreated() == null) {
  35. $this->setCreated(new \DateTime(date('Y-m-d H:i:s')));
  36. }
  37. }
  38. public function getCreated(): ?\DateTimeInterface
  39. {
  40. return $this->created;
  41. }
  42. public function setCreated(\DateTimeInterface $created): self
  43. {
  44. $this->created = $created;
  45. return $this;
  46. }
  47. public function getUser(): ?User
  48. {
  49. return $this->user;
  50. }
  51. public function setUser(?User $user): self
  52. {
  53. $this->user = $user;
  54. return $this;
  55. }
  56. public function getProduct(): ?Product
  57. {
  58. return $this->product;
  59. }
  60. public function setProduct(?Product $product): self
  61. {
  62. $this->product = $product;
  63. return $this;
  64. }
  65. }