src/Entity/UserCompany.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use App\Validator\CompanyDomainEmail;
  9. use DateTimeImmutable;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity(repositoryClass="App\Repository\UserCompanyRepository")
  15.  * @ORM\HasLifecycleCallbacks()
  16.  * @CompanyDomainEmail()
  17.  */
  18. #[ApiResource(
  19.     attributes: ['security' => "is_granted('ROLE_USER')"],
  20.     normalizationContext: ['groups' => ['userCompany:read']],
  21.     denormalizationContext: ['groups' => ['userCompany:write']],
  22.     collectionOperations: ['get''post'],
  23.     itemOperations: ['get''put']
  24. )]
  25. #[ApiFilter(PropertyFilter::class)]
  26. #[ApiFilter(SearchFilter::class, properties: ['id''email' => 'partial''user' => 'exact''company' => 'exact'])]
  27. #[ApiFilter(OrderFilter::class, properties: ['id''email''user' => 'exact''company' => 'exact'], arguments: ['orderParameterName' => 'order'])]
  28. class UserCompany
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="userCompanies")
  38.      * @ORM\JoinColumn(nullable=false)
  39.      */
  40.     private $user;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="userCompanies")
  43.      * @ORM\JoinColumn(nullable=false)
  44.      * @Groups({"user:item", "user:write","userCompany:read", "userCompany:write"})
  45.      */
  46.     private $company;
  47.     /**
  48.      * @ORM\Column(type="string", length=20, nullable=true)
  49.      * @Groups({"user:item", "user:write","userCompany:read", "userCompany:write"})
  50.      */
  51.     private $token;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      * @Assert\Email()
  55.      * @Assert\NotBlank()
  56.      * @Groups({"user:item", "user:write","userCompany:read", "userCompany:write"})
  57.      */
  58.     private $email;
  59.     /**
  60.      * @ORM\Column(type="boolean")
  61.      * @Groups({"user:item", "user:write","userCompany:read", "userCompany:write"})
  62.      */
  63.     private $verified;
  64.     /**
  65.      * @var DateTimeImmutable
  66.      *
  67.      * @ORM\Column(type="datetimetz_immutable", nullable=true)
  68.      */
  69.     private $verifiedAt;
  70.     public function __construct()
  71.     {
  72.         $this->verified false;
  73.     }
  74.     public function __toString()
  75.     {
  76.         return $this->getCompany()->getName() . (($this->verified) ? '(Verified)' 'Unverified');
  77.     }
  78.     public function getId(): ?int
  79.     {
  80.         return $this->id;
  81.     }
  82.     public function getUser(): ?User
  83.     {
  84.         return $this->user;
  85.     }
  86.     public function setUser(?User $user): self
  87.     {
  88.         $this->user $user;
  89.         return $this;
  90.     }
  91.     public function getCompany(): ?Company
  92.     {
  93.         return $this->company;
  94.     }
  95.     public function setCompany(?Company $company): self
  96.     {
  97.         $this->company $company;
  98.         return $this;
  99.     }
  100.     public function getToken(): ?string
  101.     {
  102.         return $this->token;
  103.     }
  104.     public function setToken(?string $token): self
  105.     {
  106.         $this->token $token;
  107.         return $this;
  108.     }
  109.     public function getEmail(): ?string
  110.     {
  111.         return $this->email;
  112.     }
  113.     public function setEmail(?string $email): self
  114.     {
  115.         $this->email $email;
  116.         return $this;
  117.     }
  118.     public function getVerified(): ?bool
  119.     {
  120.         return $this->verified;
  121.     }
  122.     public function setVerified(bool $verified): self
  123.     {
  124.         $this->verified $verified;
  125.         return $this;
  126.     }
  127.     public function getVerifiedAt(): ?DateTimeImmutable
  128.     {
  129.         return $this->verifiedAt;
  130.     }
  131.     public function setVerifiedAt(?DateTimeImmutable $verifiedAt): self
  132.     {
  133.         $this->verifiedAt $verifiedAt;
  134.         return $this;
  135.     }
  136. }