<?phpdeclare(strict_types=1);namespace Hitso\Bundle\FileManagerBundle\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Gedmo\Blameable\Traits\BlameableEntity;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\Identifiable;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionInterface;use Hitso\Bundle\CommonBundle\Doctrine\Behaviours\VersionTrait;use Hitso\Bundle\CommonBundle\Entity\EntityInterface;use Hitso\Bundle\CommonBundle\Interfaces\Timestampable;use Hitso\Bundle\CommonBundle\Traits\DeletableInterface;use Hitso\Bundle\CommonBundle\Traits\DeletableTrait;use Hitso\Bundle\CommonBundle\Traits\PendingLogInterface;use Hitso\Bundle\CommonBundle\Traits\PendingLogTrait;use Hitso\Bundle\CommonBundle\Traits\TimestampableTrait;use Hitso\Bundle\TaggingBundle\Entity\Tag;use Hitso\Extra\FileManagerBundle\Entity\FileExtraTrait;use TheCodingMachine\GraphQLite\Annotations\Field;use TheCodingMachine\GraphQLite\Annotations\Type;/** * Class File * * @package Hitso\Bundle\FileManagerBundle\Entity * @Type() */class File implements EntityInterface, Timestampable, VersionInterface, PendingLogInterface, DeletableInterface{ use Identifiable; use TimestampableTrait; use BlameableEntity; use FileExtraTrait; use VersionTrait; use PendingLogTrait; use DeletableTrait; protected $name = ''; protected $slug = ''; protected $extension = ''; protected $mime = ''; protected $size = 0; protected $image = false; protected $imageWidth = 0; protected $imageHeight = 0; protected $downloadCounter = 0; protected $private = false; protected $disposable = false; protected $title = ''; protected $altText = ''; protected $description = ''; protected $checksum = ''; /** * @var Collection|Tag[] */ protected $tags; /** * @var Directory|null */ protected $directory = null; /** * @var Collection|FileStat[] */ protected $downloads; /** * @var Collection|FileHotspot[] */ protected $hotspots; public function __construct() { $this->downloads = new ArrayCollection(); $this->tags = new ArrayCollection(); $this->hotspots = new ArrayCollection(); } /** * @Field() */ public function getName(): string { return $this->name; } public function setName(string $name): File { $this->name = $name; return $this; } /** * @Field() */ public function getSlug(): string { return $this->slug; } public function setSlug(string $slug): File { $this->slug = $slug; return $this; } /** * @Field() */ public function getExtension(): string { return $this->extension; } public function setExtension(string $extension): File { $this->extension = $extension; return $this; } /** * @Field(outputType="MediaUrl") */ public function getUrls(): self { return $this; } /** * @Field() */ public function getMime(): string { return $this->mime; } public function setMime(string $mime): File { $this->mime = $mime; return $this; } /** * @Field() */ public function getSize(): int { return $this->size; } public function setSize(int $size): File { $this->size = $size; return $this; } /** * @Field() */ public function isImage(): bool { return $this->image; } /** * @Field() */ public function isMp4(): bool { return $this->extension === 'mp4'; } public function setImage(bool $image): File { $this->image = $image; return $this; } /** * @Field() */ public function getImageWidth(): int { return $this->imageWidth; } public function setImageWidth(int $imageWidth): File { $this->imageWidth = $imageWidth; return $this; } /** * @Field() */ public function getImageHeight(): int { return $this->imageHeight; } public function setImageHeight(int $imageHeight): File { $this->imageHeight = $imageHeight; return $this; } /** * @Field() */ public function getDownloadCounter(): int { return $this->downloadCounter; } public function setDownloadCounter(int $downloadCounter): File { $this->downloadCounter = $downloadCounter; return $this; } /** * @Field() */ public function isPrivate(): bool { return $this->private; } public function setPrivate(bool $private): File { $this->private = $private; return $this; } /** * @Field() */ public function getDirectory(): ?Directory { return $this->directory; } public function setDirectory(?Directory $directory): File { $this->directory = $directory; return $this; } public function getDownloads(): Collection { if (null === $this->downloads) { $this->downloads = new ArrayCollection(); } return $this->downloads; } public function setDownloads(Collection $downloads) { $this->downloads = $downloads; return $this; } public function calculateDownloadCounter() { $counter = 0; foreach ($this->downloads as $download) { $counter += (int) $download->getCount(); } $this->setDownloadCounter($counter); return $this; } /** * @Field() */ public function getTitle(): string { return $this->title; } public function setTitle(string $title): void { $this->title = $title; } /** * @Field() */ public function getAltText(): string { return $this->altText; } public function setAltText(string $altText): void { $this->altText = $altText; } /** * @Field() */ public function getDescription(): string { return $this->description; } public function setDescription(string $description): void { $this->description = $description; } public function getTags(): Collection { if (null === $this->tags) { $this->tags = new ArrayCollection(); } return $this->tags; } public function setTags($tags): void { $this->tags->map(function (Tag $tag) use ($tags) { if (false === $tags->contains($tag)) { $this->tags->removeElement($tag); } }); $tags->map(function (Tag $file) { $this->addTag($file); }); } public function addTag(Tag $tag) { if (!$this->tags->contains($tag)) { $this->tags->add($tag); } } /** * @Field() */ public function getChecksum(): string { return $this->checksum; } public function setChecksum(string $checksum): void { $this->checksum = $checksum; } /** * @Field() */ public function isDisposable(): bool { return $this->disposable; } public function setDisposable(bool $disposable): void { $this->disposable = $disposable; } /** * @Field() * @return FileHotspot[] */ public function getHotspots(): Collection { if (null === $this->hotspots) { $this->hotspots = new ArrayCollection(); } return $this->hotspots; } public function setHotspots(Collection $hotspots = null) { $this->hotspots = $hotspots; return $this; } public function __toString() { return (string) $this->id; } /** * @Field() */ public function isSvg(): bool { return $this->extension === 'svg'; } /** * @Field() */ public function isPdf(): bool { return $this->extension === 'pdf'; }}