src/Entity/ExpenseCategory.php line 21

  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Uid\Ulid;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\Collection;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Repository\ExpenseCategoryRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassExpenseCategoryRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks]
  15. #[ApiResource(
  16.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  17. )]
  18. class ExpenseCategory
  19. {
  20.     use Timestamps;
  21.     #[ORM\Id]
  22.     #[ORM\Column(type'ulid'uniquetrue)]
  23.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  24.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  25.     #[Groups('read:expensecategory:basic')]
  26.     private ?Ulid $id null;
  27.     #[ORM\Column(type'string'length255)]
  28.     #[Groups('read:expensecategory:basic')]
  29.     private $name;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     #[Groups('read:expensecategory:basic')]
  32.     private $description;
  33.     #[ORM\Column(type'string'length255nullabletrue)]
  34.     #[Groups('read:expensecategory:basic')]
  35.     private $color;
  36.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'expenseCategories')]
  37.     #[ORM\JoinColumn(nullablefalse)]
  38.     private $owner;
  39.     #[ORM\OneToMany(mappedBy'type'targetEntityExpense::class)]
  40.     private $expenses;
  41.     public function __construct()
  42.     {
  43.         $this->expenses = new ArrayCollection();
  44.     }
  45.     public function __toString()
  46.     {
  47.         return $this->name;
  48.     }
  49.     public function getId(): ?Ulid
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getDescription(): ?string
  63.     {
  64.         return $this->description;
  65.     }
  66.     public function setDescription(?string $description): self
  67.     {
  68.         $this->description $description;
  69.         return $this;
  70.     }
  71.     public function getColor(): ?string
  72.     {
  73.         return $this->color;
  74.     }
  75.     public function setColor(?string $color): self
  76.     {
  77.         $this->color $color;
  78.         return $this;
  79.     }
  80.     public function getOwner(): ?Company
  81.     {
  82.         return $this->owner;
  83.     }
  84.     public function setOwner(?Company $owner): self
  85.     {
  86.         $this->owner $owner;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection<int, Expense>
  91.      */
  92.     public function getExpenses(): Collection
  93.     {
  94.         return $this->expenses;
  95.     }
  96.     public function addExpense(Expense $expense): self
  97.     {
  98.         if (!$this->expenses->contains($expense)) {
  99.             $this->expenses[] = $expense;
  100.             $expense->setType($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeExpense(Expense $expense): self
  105.     {
  106.         if ($this->expenses->removeElement($expense)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($expense->getType() === $this) {
  109.                 $expense->setType(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114. }