src/CoreBundle/Entity/Company.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of SolidInvoice project.
  5.  *
  6.  * (c) Pierre du Plessis <[email protected]>
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace SolidInvoice\CoreBundle\Entity;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\DBAL\Types\Types;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator;
  17. use Ramsey\Uuid\UuidInterface;
  18. use SolidInvoice\CoreBundle\Repository\CompanyRepository;
  19. use SolidInvoice\UserBundle\Entity\User;
  20. use Stringable;
  21. #[ORM\Table(nameCompany::TABLE_NAME)]
  22. #[ORM\Entity(repositoryClassCompanyRepository::class)]
  23. class Company implements Stringable
  24. {
  25.     final public const TABLE_NAME 'companies';
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  28.     #[ORM\CustomIdGenerator(class: UuidOrderedTimeGenerator::class)]
  29.     #[ORM\Column(type'uuid_binary_ordered_time'uniquetrue)]
  30.     private UuidInterface $id;
  31.     #[ORM\Column(typeTypes::STRINGlength255)]
  32.     private string $name;
  33.     /**
  34.      * @var Collection<int, User>
  35.      */
  36.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'companies')]
  37.     private Collection $users;
  38.     public function __construct()
  39.     {
  40.         $this->users = new ArrayCollection();
  41.     }
  42.     public function getId(): UuidInterface
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function __toString(): string
  56.     {
  57.         return $this->name;
  58.     }
  59.     /**
  60.      * @return Collection<int, User>
  61.      */
  62.     public function getUsers(): Collection
  63.     {
  64.         return $this->users;
  65.     }
  66.     public function addUser(User $user): self
  67.     {
  68.         if (! $this->users->contains($user)) {
  69.             $this->users[] = $user;
  70.             $user->addCompany($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeUser(User $user): self
  75.     {
  76.         if ($this->users->removeElement($user)) {
  77.             $user->removeCompany($this);
  78.         }
  79.         return $this;
  80.     }
  81. }