src/Entity/UserFollowCompany.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Timestampable\Traits\TimestampableEntity;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\UserFollowCompanyRepository")
  11.  * @ORM\HasLifecycleCallbacks()
  12.  * @UniqueEntity(fields={"user", "company"})
  13.  */
  14. #[ApiResource(
  15.     attributes: ['security' => "is_granted('ROLE_USER')"],
  16.     normalizationContext: ['groups' => ['user_follow_company:read']],
  17.     denormalizationContext: ['groups' => ['user_follow_company:write']],
  18.     collectionOperations: [
  19.         'get',
  20.         'post' => [
  21.             'security' => "is_granted('ROLE_ADMIN')",
  22.         ],
  23.     ],
  24.     itemOperations: [
  25.         'get',
  26.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  27.     ],
  28. )]
  29. class UserFollowCompany
  30. {
  31.     use TimestampableEntity;
  32.     /**
  33.      * @ORM\Id()
  34.      * @ORM\GeneratedValue()
  35.      * @ORM\Column(type="integer")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="userFollowCompanies")
  40.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  41.      * @Groups({"user_follow_company:read", "user_follow_company:write"})
  42.      */
  43.     private $user;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="userFollowedCompanies")
  46.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  47.      * @Groups({"user_follow_company:read", "user_follow_company:write"})
  48.      */
  49.     private $company;
  50.     /**
  51.      * @ORM\Column(type="boolean")
  52.      * @Assert\Type("bool")
  53.      * @Groups({"user_follow_company:read", "user_follow_company:write"})
  54.      */
  55.     private $followed;
  56.     /**
  57.      * UserFollowCompany constructor.
  58.      *
  59.      * @throws \Exception
  60.      */
  61.     public function __construct()
  62.     {
  63.         $this->followed false;
  64.     }
  65.     /**
  66.      * @return mixed
  67.      */
  68.     public function __toString()
  69.     {
  70.         return $this->getCompany()->getName();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getUser(): ?user
  77.     {
  78.         return $this->user;
  79.     }
  80.     public function setUser(?user $user): self
  81.     {
  82.         $this->user $user;
  83.         return $this;
  84.     }
  85.     public function getCompany(): ?company
  86.     {
  87.         return $this->company;
  88.     }
  89.     public function setCompany(?company $company): self
  90.     {
  91.         $this->company $company;
  92.         return $this;
  93.     }
  94.     public function getFollowed(): bool
  95.     {
  96.         return $this->followed;
  97.     }
  98.     public function setFollowed(bool $followed): self
  99.     {
  100.         $this->followed $followed;
  101.         return $this;
  102.     }
  103.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  104.     {
  105.         $this->createdAt $createdAt;
  106.         return $this;
  107.     }
  108. }