src/Entity/ShopFollow.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ShopFollowRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. #[ORM\Entity(repositoryClassShopFollowRepository::class)]
  8. #[ORM\Table(name'shop_follows')]
  9. #[ORM\UniqueConstraint(name'unique_user_shop_follow'columns: ['user_id''shop_id'])]
  10. class ShopFollow
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\ManyToOne(targetEntityUser::class)]
  17.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id'nullablefalseonDelete'CASCADE')]
  18.     private ?User $user null;
  19.     #[ORM\ManyToOne(targetEntityShop::class, inversedBy'follows')]
  20.     #[ORM\JoinColumn(name'shop_id'referencedColumnName'id'nullablefalseonDelete'CASCADE')]
  21.     private ?Shop $shop null;
  22.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  23.     private ?\DateTimeImmutable $followedAt null;
  24.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => true])]
  25.     private bool $isActive true;
  26.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  27.     private ?\DateTimeImmutable $unfollowedAt null;
  28.     public function __construct()
  29.     {
  30.         $this->followedAt = new \DateTimeImmutable();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getUser(): ?User
  37.     {
  38.         return $this->user;
  39.     }
  40.     public function setUser(?User $user): static
  41.     {
  42.         $this->user $user;
  43.         return $this;
  44.     }
  45.     public function getShop(): ?Shop
  46.     {
  47.         return $this->shop;
  48.     }
  49.     public function setShop(?Shop $shop): static
  50.     {
  51.         $this->shop $shop;
  52.         return $this;
  53.     }
  54.     public function getFollowedAt(): ?\DateTimeImmutable
  55.     {
  56.         return $this->followedAt;
  57.     }
  58.     public function setFollowedAt(\DateTimeImmutable $followedAt): static
  59.     {
  60.         $this->followedAt $followedAt;
  61.         return $this;
  62.     }
  63.     public function isActive(): bool
  64.     {
  65.         return $this->isActive;
  66.     }
  67.     public function setIsActive(bool $isActive): static
  68.     {
  69.         $this->isActive $isActive;
  70.         return $this;
  71.     }
  72.     public function getUnfollowedAt(): ?\DateTimeImmutable
  73.     {
  74.         return $this->unfollowedAt;
  75.     }
  76.     public function setUnfollowedAt(?\DateTimeImmutable $unfollowedAt): static
  77.     {
  78.         $this->unfollowedAt $unfollowedAt;
  79.         return $this;
  80.     }
  81.     public function unfollow(): static
  82.     {
  83.         $this->isActive false;
  84.         $this->unfollowedAt = new \DateTimeImmutable();
  85.         return $this;
  86.     }
  87.     public function refollow(): static
  88.     {
  89.         $this->isActive true;
  90.         $this->unfollowedAt null;
  91.         return $this;
  92.     }
  93. }