src/Entity/Coleccion.php line 22

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\ApiToken;
  4. use App\Repository\ColeccionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Metadata\ApiResource;
  10. use ApiPlatform\Metadata\Get;
  11. use ApiPlatform\Metadata\GetCollection;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use ApiPlatform\Metadata\ApiFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[ORM\Entity(repositoryClassColeccionRepository::class)]
  18. #[ApiResource(
  19.     description'Colecciones de Herdasa',
  20.     shortName'colecciones',
  21.     //Fichero para ver posibles opciones vendor/api-platform/core/src/Metadata/ApiResource.php
  22.     operations:[
  23.         new Get(security'is_granted("' ApiToken::SCOPE_USER_READ '")'),
  24.         new GetCollection(security'is_granted("' ApiToken::SCOPE_USER_READ '")'),
  25.     ],
  26.     normalizationContext:[
  27.         'groups' => ['colecciones:read']
  28.     ]
  29. )]
  30. #[ORM\Index(name"coleccion_idx"columns: ["id"])]
  31. #[ORM\Index(name"coleccion_in_modelos_idx"columns: ["id""nombre"])]
  32. #[ORM\Index(name"idx_coleccion_nombre"columns: ["nombre"])]
  33. #[ORM\Index(name"idx_coleccion_descripcion"columns: ["descripcion"], options: ["lengths" => [255]])]
  34. #[ApiFilter(DateFilter::class, properties: ['updatedAt'])]
  35. class Coleccion
  36. {
  37.     #[ORM\IdORM\Column]
  38.     #[ApiFilter(SearchFilter::class, strategy"exact")]
  39.     #[Groups(['programa:read''colecciones:read''modelo:read''composicion:read'])]
  40.     #[Assert\NotBlank(message"El id es requerido.")]
  41.     private ?string $id null;
  42.     #[ORM\Column(length255)]
  43.     #[Groups(['programa:read''colecciones:read''modelo:read''composicion:read'])]
  44.     #[Assert\NotBlank(message"El nombre es requerido.")]
  45.     private ?string $nombre null;
  46.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  47.     #[Groups([ 'colecciones:read''modelo:read'])]
  48.     private ?string $descripcion null;
  49.     #[ORM\Column]
  50.     private ?\DateTimeImmutable $createdAt null;
  51.     #[ORM\Column]
  52.     private ?\DateTimeImmutable $updatedAt null;
  53.     #[ORM\ManyToOne(targetEntity:Programa::class, inversedBy'colecciones')]
  54.     #[Groups([ 'colecciones:read''modelo:read''composicion:read'])]
  55.     private ?Programa $programa null;
  56.     #[ORM\ManyToOne(targetEntityImagen::class)]
  57.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  58.     #[Groups(['colecciones:read''programa:read'])]
  59.     private ?Imagen $imagen_primaria null;
  60.     #[ORM\ManyToOne(targetEntityImagen::class)]
  61.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  62.     #[Groups(['colecciones:read'])]
  63.     private ?Imagen $imagen_secundaria null;
  64.     #[ORM\ManyToOne(targetEntityImagen::class)]
  65.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  66.     #[Groups(['colecciones:read''modelo:read'])]
  67.     private ?Imagen $icono null;
  68.     #[ORM\ManyToMany(targetEntityImagen::class)]
  69.     #[ORM\JoinTable(name"coleccion_repositorio_imagenes")]
  70.     private Collection $repositorio_imagenes;
  71.     #[ORM\ManyToMany(targetEntityImagen::class)]
  72.     #[ORM\JoinTable(name"coleccion_imagenes_web")]
  73.     #[Groups(['colecciones:read'])]
  74.     private Collection $imagenes_web;
  75.     #[ORM\OneToMany(mappedBy'coleccion'targetEntityModelo::class)]
  76.     #[Groups(['colecciones:read'])]
  77.     private Collection $modelos;
  78.     public function __construct()
  79.     {
  80.         $this->modelos              = new ArrayCollection();
  81.         $this->repositorio_imagenes = new ArrayCollection();
  82.         $this->imagenes_web         = new ArrayCollection();
  83.     }
  84.     public function __toString(){
  85.         return $this->nombre//or anything else
  86.     }
  87.     public function getId(): ?string
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function setId(?string $id): self
  92.     {
  93.         $this->id $id;
  94.     
  95.         return $this;
  96.     }
  97.     public function getNombre(): ?string
  98.     {
  99.         return $this->nombre;
  100.     }
  101.     public function setNombre(string $nombre): self
  102.     {
  103.         $this->nombre $nombre;
  104.         return $this;
  105.     }
  106.     public function getDescripcion(): ?string
  107.     {
  108.         return $this->descripcion;
  109.     }
  110.     public function setDescripcion(?string $descripcion): self
  111.     {
  112.         $this->descripcion $descripcion;
  113.         return $this;
  114.     }
  115.     public function getCreatedAt(): ?\DateTimeImmutable
  116.     {
  117.         return $this->createdAt;
  118.     }
  119.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  120.     {
  121.         $this->createdAt $createdAt;
  122.         return $this;
  123.     }
  124.     public function getUpdatedAt(): ?\DateTimeImmutable
  125.     {
  126.         return $this->updatedAt;
  127.     }
  128.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  129.     {
  130.         $this->updatedAt $updatedAt;
  131.         return $this;
  132.     }
  133.     public function getPrograma(): ?Programa
  134.     {
  135.         return $this->programa;
  136.     }
  137.     public function setPrograma(?Programa $programa): static
  138.     {
  139.         $this->programa $programa;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return Collection<int, Modelo>
  144.      */
  145.     public function getModelos(): Collection
  146.     {
  147.         return $this->modelos;
  148.     }
  149.     public function addModelo(Modelo $modelo): static
  150.     {
  151.         if (!$this->modelos->contains($modelo)) {
  152.             $this->modelos->add($modelo);
  153.             $modelo->setColeccion($this);
  154.         }
  155.         return $this;
  156.     }
  157.     public function removeModelo(Modelo $modelo): static
  158.     {
  159.         if ($this->modelos->removeElement($modelo)) {
  160.             // set the owning side to null (unless already changed)
  161.             if ($modelo->getColeccion() === $this) {
  162.                 $modelo->setColeccion(null);
  163.             }
  164.         }
  165.         return $this;
  166.     }
  167.     #[Groups('colecciones:read')]
  168.     public function getModificado(): ?\DateTimeImmutable
  169.     {
  170.         return $this->updatedAt;
  171.     }
  172.     public function getImagenPrimaria(): ?Imagen
  173.     {
  174.         return $this->imagen_primaria;
  175.     }
  176.     public function setImagenPrimaria(?Imagen $imagen_primaria): static
  177.     {
  178.         $this->imagen_primaria $imagen_primaria;
  179.         return $this;
  180.     }
  181.     public function getImagenSecundaria(): ?Imagen
  182.     {
  183.         return $this->imagen_secundaria;
  184.     }
  185.     public function setImagenSecundaria(?Imagen $imagen_secundaria): static
  186.     {
  187.         $this->imagen_secundaria $imagen_secundaria;
  188.         return $this;
  189.     }
  190.     public function setIcono(?Imagen $icono): static
  191.     {
  192.         $this->icono $icono;
  193.         return $this;
  194.     }
  195.     public function getIcono(): ?Imagen
  196.     {
  197.         return $this->icono;
  198.     }
  199.     /**
  200.      * @return Collection<int, Imagen>
  201.      */
  202.     public function getRepositorioImagenes(): Collection
  203.     {
  204.         return $this->repositorio_imagenes;
  205.     }
  206.     public function addRepositorioImagenes(Imagen $repositorioImagene): static
  207.     {
  208.         if (!$this->repositorio_imagenes->contains($repositorioImagene)) {
  209.             $this->repositorio_imagenes->add($repositorioImagene);
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeRepositorioImagenes(Imagen $repositorioImagenes): static
  214.     {
  215.         $this->repositorio_imagenes->removeElement($repositorioImagenes);
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection<int, Imagen>
  220.      */
  221.     public function getImagenesWeb(): Collection
  222.     {
  223.         return $this->imagenes_web;
  224.     }
  225.     public function addImagenesWeb(Imagen $imagenesWeb): static
  226.     {
  227.         if (!$this->imagenes_web->contains($imagenesWeb)) {
  228.             $this->imagenes_web->add($imagenesWeb);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeImagenesWeb(Imagen $imagenesWeb): static
  233.     {
  234.         $this->imagenes_web->removeElement($imagenesWeb);
  235.         return $this;
  236.     }
  237.     public function getRepositorio_imagenes(): ?array
  238.     {
  239.         return $this->getRepositorioImagenes();
  240.     }
  241.     public function setRepositorio_imagenes(?array $repositorio_imagenes): self
  242.     {
  243.         return $this->setRepositorioImagenes($repositorio_imagenes);
  244.     }
  245.     public function removeImageRepositorio_imagenes($imageName): self
  246.     {
  247.         if ($key array_search($imageName$this->repositorio_imagenes)) {
  248.             unset($this->repositorio_imagenes[$key]);
  249.         }
  250.         return $this;
  251.     }
  252.     public function getImagen_primaria(): ?string
  253.     {
  254.         return $this->getImagenPrimaria();
  255.     }
  256.     public function getImagen_secundaria(): ?string
  257.     {
  258.         return $this->getImagenSecundaria();
  259.     }
  260.     public function getImagenes_web(): ?array
  261.     {
  262.         return $this->getImagenesWeb();
  263.     }
  264.     public function setImagenes_web(?array $imagenes_web): self
  265.     {
  266.         return $this->setImagenesWeb($imagenes_web);
  267.     }
  268.     // #[ApiProperty(readable: true, serialized_name: 'imagen_primaria')]
  269.     // #[Groups(['colecciones:read'])]
  270.     // public function getImagenPrimariaRute(): ?string
  271.     // {
  272.     //     return $this->imagen_primaria ? $this->imagen_primaria->getRute() : null;
  273.     // }
  274.     // #[ApiProperty(readable: true, serialized_name: 'imagen_secundaria')]
  275.     // #[Groups(['colecciones:read'])]
  276.     // public function getImagenSecundariaRute(): ?string
  277.     // {
  278.     //     return $this->imagen_secundaria ? $this->imagen_secundaria->getRute() : null;
  279.     // }
  280.     // #[ApiProperty(readable: true, serialized_name: 'imagenes_web')]
  281.     // #[Groups(['colecciones:read'])]
  282.     // public function getImagenesWebRutes(): array
  283.     // {
  284.     //     return $this->imagenes_web->map(function (Imagen $imagen) {
  285.     //         return $imagen->getRute();
  286.     //     })->toArray();
  287.     // }
  288.     // #[ApiProperty(readable: true, serialized_name: 'icono')]
  289.     // #[Groups(['colecciones:read'])]
  290.     // public function getIconoRoute(): array
  291.     // {
  292.     //     return $this->icono ? $this->icono->getRute() : null;
  293.     // }
  294. }