src/Hitso/Bundle/FileManagerBundle/Entity/File.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hitso\Bundle\FileManagerBundle\Entity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Blameable\Traits\BlameableEntity;
  7. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\Identifiable;
  8. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionInterface;
  9. use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionTrait;
  10. use Hitso\Bundle\CommonBundle\Entity\EntityInterface;
  11. use Hitso\Bundle\CommonBundle\Interfaces\Timestampable;
  12. use Hitso\Bundle\CommonBundle\Traits\DeletableInterface;
  13. use Hitso\Bundle\CommonBundle\Traits\DeletableTrait;
  14. use Hitso\Bundle\CommonBundle\Traits\PendingLogInterface;
  15. use Hitso\Bundle\CommonBundle\Traits\PendingLogTrait;
  16. use Hitso\Bundle\CommonBundle\Traits\TimestampableTrait;
  17. use Hitso\Bundle\TaggingBundle\Entity\Tag;
  18. use Hitso\Extra\FileManagerBundle\Entity\FileExtraTrait;
  19. use TheCodingMachine\GraphQLite\Annotations\Field;
  20. use TheCodingMachine\GraphQLite\Annotations\Type;
  21. /**
  22.  * Class File
  23.  *
  24.  * @package Hitso\Bundle\FileManagerBundle\Entity
  25.  * @Type()
  26.  */
  27. class File implements EntityInterfaceTimestampableVersionInterfacePendingLogInterfaceDeletableInterface
  28. {
  29.     use Identifiable;
  30.     use TimestampableTrait;
  31.     use BlameableEntity;
  32.     use FileExtraTrait;
  33.     use VersionTrait;
  34.     use PendingLogTrait;
  35.     use DeletableTrait;
  36.     protected $name            '';
  37.     protected $slug            '';
  38.     protected $extension       '';
  39.     protected $mime            '';
  40.     protected $size            0;
  41.     protected $image           false;
  42.     protected $imageWidth      0;
  43.     protected $imageHeight     0;
  44.     protected $downloadCounter 0;
  45.     protected $private         false;
  46.     protected $disposable      false;
  47.     protected $title           '';
  48.     protected $altText         '';
  49.     protected $description     '';
  50.     protected $checksum        '';
  51.     /**
  52.      * @var Collection|Tag[]
  53.      */
  54.     protected $tags;
  55.     /**
  56.      * @var Directory|null
  57.      */
  58.     protected $directory null;
  59.     /**
  60.      * @var Collection|FileStat[]
  61.      */
  62.     protected $downloads;
  63.     /**
  64.      * @var Collection|FileHotspot[]
  65.      */
  66.     protected $hotspots;
  67.     public function __construct()
  68.     {
  69.         $this->downloads = new ArrayCollection();
  70.         $this->tags      = new ArrayCollection();
  71.         $this->hotspots  = new ArrayCollection();
  72.     }
  73.     /**
  74.      * @Field()
  75.      */
  76.     public function getName(): string
  77.     {
  78.         return $this->name;
  79.     }
  80.     public function setName(string $name): File
  81.     {
  82.         $this->name $name;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @Field()
  87.      */
  88.     public function getSlug(): string
  89.     {
  90.         return $this->slug;
  91.     }
  92.     public function setSlug(string $slug): File
  93.     {
  94.         $this->slug $slug;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @Field()
  99.      */
  100.     public function getExtension(): string
  101.     {
  102.         return $this->extension;
  103.     }
  104.     public function setExtension(string $extension): File
  105.     {
  106.         $this->extension $extension;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @Field(outputType="MediaUrl")
  111.      */
  112.     public function getUrls(): self
  113.     {
  114.         return $this;
  115.     }
  116.     /**
  117.      * @Field()
  118.      */
  119.     public function getMime(): string
  120.     {
  121.         return $this->mime;
  122.     }
  123.     public function setMime(string $mime): File
  124.     {
  125.         $this->mime $mime;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @Field()
  130.      */
  131.     public function getSize(): int
  132.     {
  133.         return $this->size;
  134.     }
  135.     public function setSize(int $size): File
  136.     {
  137.         $this->size $size;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @Field()
  142.      */
  143.     public function isImage(): bool
  144.     {
  145.         return $this->image;
  146.     }
  147.     /**
  148.      * @Field()
  149.      */
  150.     public function isMp4(): bool
  151.     {
  152.         return $this->extension === 'mp4';
  153.     }
  154.     public function setImage(bool $image): File
  155.     {
  156.         $this->image $image;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @Field()
  161.      */
  162.     public function getImageWidth(): int
  163.     {
  164.         return $this->imageWidth;
  165.     }
  166.     public function setImageWidth(int $imageWidth): File
  167.     {
  168.         $this->imageWidth $imageWidth;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @Field()
  173.      */
  174.     public function getImageHeight(): int
  175.     {
  176.         return $this->imageHeight;
  177.     }
  178.     public function setImageHeight(int $imageHeight): File
  179.     {
  180.         $this->imageHeight $imageHeight;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @Field()
  185.      */
  186.     public function getDownloadCounter(): int
  187.     {
  188.         return $this->downloadCounter;
  189.     }
  190.     public function setDownloadCounter(int $downloadCounter): File
  191.     {
  192.         $this->downloadCounter $downloadCounter;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @Field()
  197.      */
  198.     public function isPrivate(): bool
  199.     {
  200.         return $this->private;
  201.     }
  202.     public function setPrivate(bool $private): File
  203.     {
  204.         $this->private $private;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @Field()
  209.      */
  210.     public function getDirectory(): ?Directory
  211.     {
  212.         return $this->directory;
  213.     }
  214.     public function setDirectory(?Directory $directory): File
  215.     {
  216.         $this->directory $directory;
  217.         return $this;
  218.     }
  219.     public function getDownloads(): Collection
  220.     {
  221.         if (null === $this->downloads) {
  222.             $this->downloads = new ArrayCollection();
  223.         }
  224.         return $this->downloads;
  225.     }
  226.     public function setDownloads(Collection $downloads)
  227.     {
  228.         $this->downloads $downloads;
  229.         return $this;
  230.     }
  231.     public function calculateDownloadCounter()
  232.     {
  233.         $counter 0;
  234.         foreach ($this->downloads as $download) {
  235.             $counter += (int) $download->getCount();
  236.         }
  237.         $this->setDownloadCounter($counter);
  238.         return $this;
  239.     }
  240.     /**
  241.      * @Field()
  242.      */
  243.     public function getTitle(): string
  244.     {
  245.         return $this->title;
  246.     }
  247.     public function setTitle(string $title): void
  248.     {
  249.         $this->title $title;
  250.     }
  251.     /**
  252.      * @Field()
  253.      */
  254.     public function getAltText(): string
  255.     {
  256.         return $this->altText;
  257.     }
  258.     public function setAltText(string $altText): void
  259.     {
  260.         $this->altText $altText;
  261.     }
  262.     /**
  263.      * @Field()
  264.      */
  265.     public function getDescription(): string
  266.     {
  267.         return $this->description;
  268.     }
  269.     public function setDescription(string $description): void
  270.     {
  271.         $this->description $description;
  272.     }
  273.     public function getTags(): Collection
  274.     {
  275.         if (null === $this->tags) {
  276.             $this->tags = new ArrayCollection();
  277.         }
  278.         return $this->tags;
  279.     }
  280.     public function setTags($tags): void
  281.     {
  282.         $this->tags->map(function (Tag $tag) use ($tags) {
  283.             if (false === $tags->contains($tag)) {
  284.                 $this->tags->removeElement($tag);
  285.             }
  286.         });
  287.         $tags->map(function (Tag $file) {
  288.             $this->addTag($file);
  289.         });
  290.     }
  291.     public function addTag(Tag $tag)
  292.     {
  293.         if (!$this->tags->contains($tag)) {
  294.             $this->tags->add($tag);
  295.         }
  296.     }
  297.     /**
  298.      * @Field()
  299.      */
  300.     public function getChecksum(): string
  301.     {
  302.         return $this->checksum;
  303.     }
  304.     public function setChecksum(string $checksum): void
  305.     {
  306.         $this->checksum $checksum;
  307.     }
  308.     /**
  309.      * @Field()
  310.      */
  311.     public function isDisposable(): bool
  312.     {
  313.         return $this->disposable;
  314.     }
  315.     public function setDisposable(bool $disposable): void
  316.     {
  317.         $this->disposable $disposable;
  318.     }
  319.     /**
  320.      * @Field()
  321.      * @return FileHotspot[]
  322.      */
  323.     public function getHotspots(): Collection
  324.     {
  325.         if (null === $this->hotspots) {
  326.             $this->hotspots = new ArrayCollection();
  327.         }
  328.         return $this->hotspots;
  329.     }
  330.     public function setHotspots(Collection $hotspots null)
  331.     {
  332.         $this->hotspots $hotspots;
  333.         return $this;
  334.     }
  335.     public function __toString()
  336.     {
  337.         return (string) $this->id;
  338.     }
  339.     /**
  340.      * @Field()
  341.      */
  342.     public function isSvg(): bool
  343.     {
  344.         return $this->extension === 'svg';
  345.     }
  346.     /**
  347.      * @Field()
  348.      */
  349.     public function isPdf(): bool
  350.     {
  351.         return $this->extension === 'pdf';
  352.     }
  353. }