src/Entity/Service.php line 21
<?php
namespace App\Entity;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ServiceRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ServiceRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
)]
class Service
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:service:basic'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:service:basic'])]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:service:basic'])]
private $description;
#[ORM\Column(type: 'float')]
#[Groups(['read:service:basic'])]
private $price = 0;
#[ORM\Column(type: 'integer')]
#[Groups(['read:service:basic'])]
private $duration = 1;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'services')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\OneToMany(mappedBy: 'service', targetEntity: Subscription::class, orphanRemoval: true)]
private $subscriptions;
public function __construct()
{
$this->subscriptions = new ArrayCollection();
}
public function __toString()
{
return $this->name . ' (' . $this->price . ' ' . $this->owner->getCurrencie() . ')';
}
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 getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setService($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getService() === $this) {
$subscription->setService(null);
}
}
return $this;
}
}