src/Entity/Reference/ReferenceFinancingMode.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Transaction;
  5. use App\Repository\Reference\ReferenceFinancingModeRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. /**
  11.  * @ApiResource(
  12.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  13.  *     normalizationContext={"groups"={"reference-financing-mode:read"}, "swagger_definition_name"="Read"},
  14.  *     denormalizationContext={"groups"={"reference-financing-mode:write"}, "swagger_definition_name"="Write"},
  15.  *     itemOperations={
  16.  *          "get"
  17.  *     },
  18.  *     collectionOperations={
  19.  *           "get",
  20.  *
  21.  *     },
  22.  *     attributes={
  23.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  24.  *     }
  25.  * )
  26.  * @ORM\Entity(repositoryClass=ReferenceFinancingModeRepository::class)
  27.  */
  28. class ReferenceFinancingMode
  29. {
  30.     public const TRANSLATION_DOMAIN 'reference_financing_mode';
  31.     public const REFERENCE_FINANCING_MODE_CREDIT 'reference.financing.mode.CREDIT';
  32.     public const REFERENCE_FINANCING_MODE_CASH 'reference.financing.mode.CASH';
  33.     public const REFERENCE_CODE_FINANCING_MODE_CREDIT 'CREDIT';
  34.     public const REFERENCE_CODE_FINANCING_MODE_CASH 'CASH';
  35.     public const ALL_FINANCING_MODE = [
  36.         self::REFERENCE_FINANCING_MODE_CREDIT,
  37.         self::REFERENCE_FINANCING_MODE_CASH
  38.     ];
  39.     public const ALL_CODE_FINANCING_MODE = [
  40.         self::REFERENCE_CODE_FINANCING_MODE_CREDIT,
  41.         self::REFERENCE_CODE_FINANCING_MODE_CASH
  42.     ];
  43.     /**
  44.      * @ORM\Id
  45.      * @ORM\GeneratedValue
  46.      * @ORM\Column(type="integer")
  47.      *
  48.      * @Groups({
  49.      *    "transaction-item:read",
  50.      *    "reference-financing-mode:read",
  51.      *     "business-indication:item:read"
  52.      * })
  53.      */
  54.     private $id;
  55.     /**
  56.      * @ORM\Column(type="string", length=255)
  57.      *
  58.      * @Groups({
  59.      *   "transaction-item:read",
  60.      *   "reference-financing-mode:read",
  61.      *   "business-indication:item:read"
  62.      * })
  63.      */
  64.     private ?string $name;
  65.     /**
  66.      * @ORM\Column(type="string", length=255)
  67.      *
  68.      * @Groups({
  69.      *   "transaction-item:read",
  70.      *   "reference-financing-mode:read",
  71.      *   "business-indication:item:read"
  72.      * })
  73.      */
  74.     private ?string $code;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="referenceFinancingMode")
  77.      */
  78.     private $transactions;
  79.     public function __construct()
  80.     {
  81.         $this->transactions = new ArrayCollection();
  82.     }
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getName(): ?string
  88.     {
  89.         return $this->name;
  90.     }
  91.     public function setName(string $name): self
  92.     {
  93.         $this->name $name;
  94.         return $this;
  95.     }
  96.     public function getCode(): ?string
  97.     {
  98.         return $this->code;
  99.     }
  100.     public function setCode(string $code): self
  101.     {
  102.         $this->code $code;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, Transaction>
  107.      */
  108.     public function getTransactions(): Collection
  109.     {
  110.         return $this->transactions;
  111.     }
  112.     public function addTransaction(Transaction $transaction): self
  113.     {
  114.         if (!$this->transactions->contains($transaction)) {
  115.             $this->transactions[] = $transaction;
  116.             $transaction->setReferenceFinancingMode($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeTransaction(Transaction $transaction): self
  121.     {
  122.         if ($this->transactions->removeElement($transaction)) {
  123.             // set the owning side to null (unless already changed)
  124.             if ($transaction->getReferenceFinancingMode() === $this) {
  125.                 $transaction->setReferenceFinancingMode(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130. }