src/Entity/TaxRule.php line 68

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Leo BANNHOLTZER (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace App\Entity;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\DoctrineExtensions\IsDefaultEntity;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Uid\Uuid;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use App\Repository\TaxRuleRepository;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use App\DoctrineExtensions\IsActiveEntity;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  20. use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
  21. use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
  22. use App\EventListener\TaxRuleSaveListener;
  23. /**
  24.  * @ApiResource(
  25.  *   formats={"json"},
  26.  *   security="is_granted('ROLE_USER')",
  27.  *   normalizationContext= {"groups"= {"get"}},
  28.  *   denormalizationContext={"groups"={"write"}},
  29.  *   collectionOperations={
  30.  *       "get"={
  31.  *           "security"="is_granted('ROLE_READ_ONLY')"
  32.  *       },
  33.  *       "post"={
  34.  *           "security"="is_granted('ROLE_SUPER_ADMIN')"
  35.  *       }
  36.  *   },
  37.  *   itemOperations={
  38.  *       "get",
  39.  *       "put"={
  40.  *           "security"="is_granted('ROLE_SUPER_ADMIN')"
  41.  *       },
  42.  *       "patch"={
  43.  *           "security"="is_granted('ROLE_SUPER_ADMIN')"
  44.  *       },
  45.  *       "delete"={
  46.  *           "security"="is_granted('ROLE_SUPER_ADMIN')"
  47.  *       }
  48.  *   }
  49.  *  )
  50.  * @ORM\Entity(repositoryClass=TaxRuleRepository::class)
  51.  * @Gedmo\TranslationEntity(class="App\Entity\TaxRuleTranslation")
  52.  * @ORM\Table(name="tax_rule", indexes={
  53.  *  @ORM\Index(name="name", columns={"name"}),
  54.  *  @ORM\Index(name="is_default", columns={"is_default"}),
  55.  *  @ORM\Index(name="is_active", columns={"is_active"}),
  56.  *  @ORM\Index(name="deleted_at", columns={"deleted_at"}),
  57.  *  @ORM\Index(name="created_at", columns={"created_at"}),
  58.  *  @ORM\Index(name="updated_at", columns={"updated_at"})
  59.  * })
  60.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
  61.  * @ORM\EntityListeners({TaxRuleSaveListener::class})
  62.  */
  63. class TaxRule
  64. {
  65.     use UserTimestampableEntity;
  66.     use UserSoftDeleteableEntity;
  67.     use IsActiveEntity;
  68.     use IsDefaultEntity;
  69.     /**
  70.      * @ORM\Id
  71.      * @ORM\Column(type="uuid")
  72.      * @ORM\GeneratedValue(strategy="CUSTOM")
  73.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  74.      * @Groups({"get", "write"})
  75.      */
  76.     private ?Uuid $id null;
  77.     /**
  78.      * @ORM\Column(type="string", length=50)
  79.      * @Gedmo\Translatable
  80.      * @Groups({"get", "write"})
  81.      */
  82.     private string $name;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity=TaxRuleCountry::class, mappedBy="tax_rule", cascade={"remove"}, fetch="EXTRA_LAZY")
  85.      */
  86.     private Collection $taxRuleCountries;
  87.     /**
  88.      * @ORM\OneToMany(
  89.      *   targetEntity="TaxRuleTranslation",
  90.      *   mappedBy="object",
  91.      *   cascade={"persist", "remove"},
  92.      *   fetch="EXTRA_LAZY"
  93.      * )
  94.      */
  95.     private Collection $translations;
  96.     public function __construct()
  97.     {
  98.         $this->taxRuleCountries = new ArrayCollection();
  99.         $this->translations = new ArrayCollection();
  100.     }
  101.     /**
  102.      * @return Uuid|null
  103.      */
  104.     public function getId(): ?Uuid
  105.     {
  106.         return $this->id;
  107.     }
  108.     /**
  109.      * @return string
  110.      */
  111.     public function getName(): string
  112.     {
  113.         return $this->name;
  114.     }
  115.     /**
  116.      * @param string $name
  117.      * @return $this
  118.      */
  119.     public function setName(string $name): self
  120.     {
  121.         $this->name $name;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return Collection|TaxRuleCountry[]
  126.      */
  127.     public function getTaxRuleCountries(): Collection
  128.     {
  129.         return $this->taxRuleCountries;
  130.     }
  131.     /**
  132.      * @return Collection|TaxRuleTranslation[]
  133.      */
  134.     public function getTranslations()
  135.     {
  136.         return $this->translations;
  137.     }
  138.     /**
  139.      * @param TaxRuleTranslation $t
  140.      * @return $this
  141.      */
  142.     public function addTranslation(TaxRuleTranslation $t): self
  143.     {
  144.         if (!$this->translations->contains($t)) {
  145.             $this->translations[] = $t;
  146.             $t->setObject($this);
  147.         }
  148.         return $this;
  149.     }
  150. }