vendor/crosiersource/crosierlib-radx/src/Entity/Estoque/ProdutoImagem.php line 61

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibRadxBundle\Entity\Estoque;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\EntityHandler;
  9. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\NotUppercase;
  10. use CrosierSource\CrosierLibBaseBundle\Entity\EntityId;
  11. use CrosierSource\CrosierLibBaseBundle\Entity\EntityIdTrait;
  12. use DateTime;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Exception;
  15. use Symfony\Component\HttpFoundation\File\File;
  16. use Symfony\Component\HttpFoundation\File\UploadedFile;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  19. /**
  20.  * @ApiResource(
  21.  *     normalizationContext={"groups"={"produtoImagem","entityId"},"enable_max_depth"=true},
  22.  *     denormalizationContext={"groups"={"produtoImagem"},"enable_max_depth"=true},
  23.  *
  24.  *     itemOperations={
  25.  *          "get"={"path"="/est/produtoImagem/{id}", "security"="is_granted('ROLE_ESTOQUE')"},
  26.  *          "put"={"path"="/est/produtoImagem/{id}", "security"="is_granted('ROLE_ESTOQUE')"},
  27.  *          "delete"={"path"="/est/produtoImagem/{id}", "security"="is_granted('ROLE_ADMIN')"}
  28.  *     },
  29.  *     collectionOperations={
  30.  *          "get"={"path"="/est/produtoImagem", "security"="is_granted('ROLE_ESTOQUE')"},
  31.  *          "post"={"path"="/est/produtoImagem", "security"="is_granted('ROLE_ESTOQUE')"}
  32.  *     },
  33.  *
  34.  *     attributes={
  35.  *          "pagination_items_per_page"=10,
  36.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  37.  *     }
  38.  * )
  39.  * @ApiFilter(PropertyFilter::class)
  40.  *
  41.  * @ApiFilter(SearchFilter::class, properties={
  42.  *     "nome": "partial", 
  43.  *     "documento": "exact", 
  44.  *     "id": "exact",
  45.  *     "produto.id": "exact",
  46.  *     "produto.codigo": "exact"
  47.  * })
  48.  * @ApiFilter(OrderFilter::class, properties={"id", "documento", "nome", "updated"}, arguments={"orderParameterName"="order"})
  49.  *
  50.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibRadxBundle\EntityHandler\Estoque\ProdutoImagemEntityHandler")
  51.  *
  52.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibRadxBundle\Repository\Estoque\ProdutoImagemRepository")
  53.  * @ORM\Table(name="est_produto_imagem")
  54.  * @Vich\Uploadable
  55.  *
  56.  * @author Carlos Eduardo Pauluk
  57.  */
  58. class ProdutoImagem implements EntityId
  59. {
  60.     use EntityIdTrait;
  61.     /**
  62.      *
  63.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Estoque\Produto")
  64.      * @ORM\JoinColumn(name="produto_id", nullable=false)
  65.      *
  66.      * @var null|Produto
  67.      */
  68.     public ?Produto $produto null;
  69.     /**
  70.      * @Vich\UploadableField(mapping="produto_imagem", fileNameProperty="imageName")
  71.      * @var null|File
  72.      */
  73.     public ?File $imageFile null;
  74.     /**
  75.      * @ORM\Column(name="image_name", type="string")
  76.      * @Groups("produtoImagem")
  77.      * @NotUppercase()
  78.      * @var null|string
  79.      */
  80.     public ?string $imageName null;
  81.     /**
  82.      *
  83.      * @ORM\Column(name="ordem", type="integer", nullable=true)
  84.      * @Groups("produtoImagem")
  85.      * @var null|integer
  86.      */
  87.     public ?int $ordem null;
  88.     /**
  89.      *
  90.      * @ORM\Column(name="descricao", type="string", nullable=false)
  91.      * @NotUppercase()
  92.      * @Groups("produtoImagem")
  93.      * @var null|string
  94.      */
  95.     public ?string $descricao null;
  96.     /**
  97.      * @return Produto|null
  98.      */
  99.     public function getProduto(): ?Produto
  100.     {
  101.         return $this->produto;
  102.     }
  103.     /**
  104.      * @param Produto|null $produto
  105.      * @return ProdutoImagem
  106.      */
  107.     public function setProduto(?Produto $produto): ProdutoImagem
  108.     {
  109.         $this->produto $produto;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return File|null
  114.      */
  115.     public function getImageFile(): ?File
  116.     {
  117.         return $this->imageFile;
  118.     }
  119.     /**
  120.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  121.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  122.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  123.      * must be able to accept an instance of 'File' as the bundle will inject one here
  124.      * during Doctrine hydration.
  125.      *
  126.      * @param File|UploadedFile|null $imageFile
  127.      * @return ProdutoImagem
  128.      * @throws Exception
  129.      */
  130.     public function setImageFile(?File $imageFile null): ProdutoImagem
  131.     {
  132.         $this->imageFile $imageFile;
  133.         if (null !== $imageFile) {
  134.             // It is required that at least one field changes if you are using doctrine
  135.             // otherwise the event listeners won't be called and the file is lost
  136.             $this->updated = new DateTime();
  137.         }
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return null|string
  142.      */
  143.     public function getImageName(): ?string
  144.     {
  145.         return $this->imageName;
  146.     }
  147.     /**
  148.      * @param null|string $imageName
  149.      * @return ProdutoImagem
  150.      */
  151.     public function setImageName(?string $imageName): ProdutoImagem
  152.     {
  153.         $this->imageName $imageName;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @return int|null
  158.      */
  159.     public function getOrdem(): ?int
  160.     {
  161.         return $this->ordem;
  162.     }
  163.     /**
  164.      * @param int|null $ordem
  165.      * @return ProdutoImagem
  166.      */
  167.     public function setOrdem(?int $ordem): ProdutoImagem
  168.     {
  169.         $this->ordem $ordem;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return string|null
  174.      */
  175.     public function getDescricao(): ?string
  176.     {
  177.         return $this->descricao;
  178.     }
  179.     /**
  180.      * @param string|null $descricao
  181.      * @return ProdutoImagem
  182.      */
  183.     public function setDescricao(?string $descricao): ProdutoImagem
  184.     {
  185.         $this->descricao $descricao;
  186.         return $this;
  187.     }
  188.     /**
  189.      * @Groups("produtoImagem")
  190.      */
  191.     public function getUrl(): ?string
  192.     {
  193.         try {
  194.             return ($_SERVER['CROSIERAPPRADX_URL'] ?? 'radx_url_not_found') .
  195.                 '/images/produtos/' .
  196.                 $this->produto->depto->getId() . '/' .
  197.                 $this->produto->grupo->getId() . '/' .
  198.                 $this->produto->subgrupo->getId() . '/' .
  199.                 $this->imageName;
  200.         } catch (\Exception $e) {
  201.             return null;
  202.         }
  203.     }
  204. }