src/Entity/ExpenseCategory.php line 21
<?php
namespace App\Entity;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ExpenseCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ExpenseCategoryRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
)]
class ExpenseCategory
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups('read:expensecategory:basic')]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups('read:expensecategory:basic')]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups('read:expensecategory:basic')]
private $description;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups('read:expensecategory:basic')]
private $color;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'expenseCategories')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\OneToMany(mappedBy: 'type', targetEntity: Expense::class)]
private $expenses;
public function __construct()
{
$this->expenses = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Expense>
*/
public function getExpenses(): Collection
{
return $this->expenses;
}
public function addExpense(Expense $expense): self
{
if (!$this->expenses->contains($expense)) {
$this->expenses[] = $expense;
$expense->setType($this);
}
return $this;
}
public function removeExpense(Expense $expense): self
{
if ($this->expenses->removeElement($expense)) {
// set the owning side to null (unless already changed)
if ($expense->getType() === $this) {
$expense->setType(null);
}
}
return $this;
}
}