<?php
/**
* @author Leo BANNHOLTZER (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\DoctrineExtensions\IsDefaultEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\TaxRuleRepository;
use Gedmo\Mapping\Annotation as Gedmo;
use App\DoctrineExtensions\IsActiveEntity;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
use App\EventListener\TaxRuleSaveListener;
/**
* @ApiResource(
* formats={"json"},
* security="is_granted('ROLE_USER')",
* normalizationContext= {"groups"= {"get"}},
* denormalizationContext={"groups"={"write"}},
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_READ_ONLY')"
* },
* "post"={
* "security"="is_granted('ROLE_SUPER_ADMIN')"
* }
* },
* itemOperations={
* "get",
* "put"={
* "security"="is_granted('ROLE_SUPER_ADMIN')"
* },
* "patch"={
* "security"="is_granted('ROLE_SUPER_ADMIN')"
* },
* "delete"={
* "security"="is_granted('ROLE_SUPER_ADMIN')"
* }
* }
* )
* @ORM\Entity(repositoryClass=TaxRuleRepository::class)
* @Gedmo\TranslationEntity(class="App\Entity\TaxRuleTranslation")
* @ORM\Table(name="tax_rule", indexes={
* @ORM\Index(name="name", columns={"name"}),
* @ORM\Index(name="is_default", columns={"is_default"}),
* @ORM\Index(name="is_active", columns={"is_active"}),
* @ORM\Index(name="deleted_at", columns={"deleted_at"}),
* @ORM\Index(name="created_at", columns={"created_at"}),
* @ORM\Index(name="updated_at", columns={"updated_at"})
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
* @ORM\EntityListeners({TaxRuleSaveListener::class})
*/
class TaxRule
{
use UserTimestampableEntity;
use UserSoftDeleteableEntity;
use IsActiveEntity;
use IsDefaultEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @Groups({"get", "write"})
*/
private ?Uuid $id = null;
/**
* @ORM\Column(type="string", length=50)
* @Gedmo\Translatable
* @Groups({"get", "write"})
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity=TaxRuleCountry::class, mappedBy="tax_rule", cascade={"remove"}, fetch="EXTRA_LAZY")
*/
private Collection $taxRuleCountries;
/**
* @ORM\OneToMany(
* targetEntity="TaxRuleTranslation",
* mappedBy="object",
* cascade={"persist", "remove"},
* fetch="EXTRA_LAZY"
* )
*/
private Collection $translations;
public function __construct()
{
$this->taxRuleCountries = new ArrayCollection();
$this->translations = new ArrayCollection();
}
/**
* @return Uuid|null
*/
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|TaxRuleCountry[]
*/
public function getTaxRuleCountries(): Collection
{
return $this->taxRuleCountries;
}
/**
* @return Collection|TaxRuleTranslation[]
*/
public function getTranslations()
{
return $this->translations;
}
/**
* @param TaxRuleTranslation $t
* @return $this
*/
public function addTranslation(TaxRuleTranslation $t): self
{
if (!$this->translations->contains($t)) {
$this->translations[] = $t;
$t->setObject($this);
}
return $this;
}
}