vendor/crea/media-bundle/src/Entity/MediaFile.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Crea\MediaBundle\Entity;
  4. use Crea\MediaBundle\Entity\Enum\MediaFileUploadModeEnum;
  5. use Crea\MediaBundle\Repository\MediaFileRepository;
  6. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Stringable;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. /**
  14. * @ORM\Entity(repositoryClass=MediaFileRepository::class)
  15. *
  16. * @ORM\Table(name="media_file")
  17. */
  18. class MediaFile implements Stringable, FileConstraintInterface
  19. {
  20. use LifecycleUserIdentifierTrait;
  21. /**
  22. * @ORM\Id
  23. *
  24. * @ORM\GeneratedValue
  25. *
  26. * @ORM\Column(type="integer")
  27. *
  28. * @Groups({"media_list"})
  29. */
  30. private ?int $id = null;
  31. /**
  32. * @ORM\Column(type="string", length=64, nullable=true)
  33. *
  34. * @Groups({"media_list"})
  35. */
  36. private ?string $extension = null;
  37. /**
  38. * @ORM\Column(type="string", length=255, nullable=true)
  39. *
  40. * @Groups({"media_list"})
  41. */
  42. private ?string $mimeType = null;
  43. /**
  44. * @ORM\Column(type="string", length=255, nullable=true)
  45. *
  46. * @Groups({"media_list"})
  47. */
  48. private ?string $dir = null;
  49. /**
  50. * @ORM\Column(type="string", length=255, nullable=true)
  51. *
  52. * @Groups({"media_list"})
  53. */
  54. private ?string $filename = null;
  55. /**
  56. * @ORM\Column(type="string", length=255, nullable=true)
  57. *
  58. * @Groups({"media_list"})
  59. */
  60. private ?string $originalFilename = null;
  61. /**
  62. * @ORM\Column(type="string", length=255, nullable=true)
  63. *
  64. * @Groups({"media_list"})
  65. */
  66. private ?string $customFilename = null;
  67. /**
  68. * folder + name + extension.
  69. *
  70. * @ORM\Column(type="string", nullable=false, unique=true)
  71. *
  72. * @Groups({"media_list"})
  73. */
  74. private ?string $path = null;
  75. /**
  76. * domain + folder + name + extension.
  77. *
  78. * @ORM\Column(type="string", nullable=false, unique=true)
  79. *
  80. * @Groups({"media_list"})
  81. */
  82. private ?string $url = null;
  83. /**
  84. * Non mappé, rempli uniquement à la volée lorsque le CDN est configuré.
  85. */
  86. private ?string $cdnUrl = null;
  87. /**
  88. * folder + name + extension.
  89. *
  90. * @ORM\Column(type="string", nullable=true)
  91. *
  92. * @Groups({"media_list"})
  93. */
  94. private ?string $thumbnailPath = null;
  95. /**
  96. * folder + name + extension.
  97. *
  98. * @ORM\Column(type="string", nullable=true)
  99. *
  100. * @Groups({"media_list"})
  101. */
  102. private ?string $thumbnailUrl = null;
  103. /**
  104. * Unpersisted property.
  105. */
  106. private ?File $uploadedFile = null;
  107. /**
  108. * Unit : Octet.
  109. *
  110. * @ORM\Column(type="integer", nullable=true)
  111. *
  112. * @Groups({"media_list"})
  113. */
  114. private ?int $size = null;
  115. /**
  116. * Unit : pixel.
  117. *
  118. * @ORM\Column(type="integer", nullable=true)
  119. *
  120. * @Groups({"media_list"})
  121. */
  122. private ?int $height = null;
  123. /**
  124. * Unit : pixel.
  125. *
  126. * @ORM\Column(type="integer", nullable=true)
  127. *
  128. * @Groups({"media_list"})
  129. */
  130. private ?int $width = null;
  131. /**
  132. * Unit : seconds.
  133. *
  134. * @ORM\Column(type="integer", nullable=true)
  135. *
  136. * @Groups({"media_list"})
  137. */
  138. private ?int $duration = null;
  139. /**
  140. * @ORM\ManyToOne(targetEntity=MediaType::class, inversedBy="mediaFiles")
  141. */
  142. private ?MediaType $mediaType = null;
  143. /**
  144. * @var Collection<int, MediaTag>
  145. *
  146. * @ORM\ManyToMany(targetEntity=MediaTag::class, mappedBy="mediaFiles", cascade={"persist"})
  147. */
  148. private Collection $mediaTags;
  149. /**
  150. * @ORM\Column(type="string", enumType=MediaFileUploadModeEnum::class, options={"default": "MANUAL_UPLOAD"})
  151. */
  152. private MediaFileUploadModeEnum $uploadMode = MediaFileUploadModeEnum::MANUAL_UPLOAD;
  153. public function __construct()
  154. {
  155. $this->mediaTags = new ArrayCollection();
  156. }
  157. public function __toString(): string
  158. {
  159. return $this->filename ?? '';
  160. }
  161. public function getId(): ?int
  162. {
  163. return $this->id;
  164. }
  165. public function setId(?int $id): MediaFile
  166. {
  167. $this->id = $id;
  168. return $this;
  169. }
  170. public function getExtension(): ?string
  171. {
  172. return $this->extension;
  173. }
  174. public function setExtension(?string $extension): MediaFile
  175. {
  176. $this->extension = $extension;
  177. return $this;
  178. }
  179. public function getMimeType(): ?string
  180. {
  181. return $this->mimeType;
  182. }
  183. public function setMimeType(?string $mimeType): MediaFile
  184. {
  185. $this->mimeType = $mimeType;
  186. return $this;
  187. }
  188. public function getDir(): ?string
  189. {
  190. return $this->dir;
  191. }
  192. public function setDir(?string $dir): MediaFile
  193. {
  194. $this->dir = $dir;
  195. return $this;
  196. }
  197. public function getFilename(): ?string
  198. {
  199. return $this->filename;
  200. }
  201. public function setFilename(?string $filename): MediaFile
  202. {
  203. $this->filename = $filename;
  204. return $this;
  205. }
  206. public function getFullName(): ?string
  207. {
  208. return implode('.', array_filter([$this->getFilename(), $this->getExtension()]));
  209. }
  210. public function getOriginalFilename(): ?string
  211. {
  212. return $this->originalFilename;
  213. }
  214. public function setOriginalFilename(?string $originalFilename): MediaFile
  215. {
  216. $this->originalFilename = $originalFilename;
  217. return $this;
  218. }
  219. public function getCustomFilename(): ?string
  220. {
  221. return $this->customFilename;
  222. }
  223. public function getDisplayName(): ?string
  224. {
  225. return $this->getCustomFilename() ? $this->getCustomFilename().'.'.$this->getExtension() : $this->getOriginalFilename() ?? $this->getFullName();
  226. }
  227. public function setCustomFilename(?string $customFilename): MediaFile
  228. {
  229. $this->customFilename = $customFilename;
  230. return $this;
  231. }
  232. public function getPath(): ?string
  233. {
  234. return $this->path;
  235. }
  236. public function setPath(?string $path): MediaFile
  237. {
  238. $this->path = $path;
  239. return $this;
  240. }
  241. public function getUrl(): ?string
  242. {
  243. return $this->url;
  244. }
  245. public function setUrl(?string $url): MediaFile
  246. {
  247. $this->url = $url;
  248. return $this;
  249. }
  250. public function getCdnUrl(): ?string
  251. {
  252. return $this->cdnUrl;
  253. }
  254. public function setCdnUrl(?string $cdnUrl): MediaFile
  255. {
  256. $this->cdnUrl = $cdnUrl;
  257. return $this;
  258. }
  259. public function getDisplayUrl(): ?string
  260. {
  261. return $this->getCdnUrl() ?? $this->getUrl();
  262. }
  263. public function getUploadedFile(): ?File
  264. {
  265. return $this->uploadedFile;
  266. }
  267. public function setUploadedFile(?File $uploadedFile): MediaFile
  268. {
  269. $this->uploadedFile = $uploadedFile;
  270. return $this;
  271. }
  272. public function getSize(): ?int
  273. {
  274. return $this->size;
  275. }
  276. public function setSize(?int $size): MediaFile
  277. {
  278. $this->size = $size;
  279. return $this;
  280. }
  281. public function getHeight(): ?int
  282. {
  283. return $this->height;
  284. }
  285. public function setHeight(?int $height): MediaFile
  286. {
  287. $this->height = $height;
  288. return $this;
  289. }
  290. public function getWidth(): ?int
  291. {
  292. return $this->width;
  293. }
  294. public function setWidth(?int $width): MediaFile
  295. {
  296. $this->width = $width;
  297. return $this;
  298. }
  299. public function getDuration(): ?int
  300. {
  301. return $this->duration;
  302. }
  303. public function setDuration(?int $duration): MediaFile
  304. {
  305. $this->duration = $duration;
  306. return $this;
  307. }
  308. public function getThumbnailPath(): ?string
  309. {
  310. return $this->thumbnailPath;
  311. }
  312. public function setThumbnailPath(?string $thumbnailPath): MediaFile
  313. {
  314. $this->thumbnailPath = $thumbnailPath;
  315. return $this;
  316. }
  317. public function getThumbnailUrl(): ?string
  318. {
  319. return $this->thumbnailUrl;
  320. }
  321. public function setThumbnailUrl(?string $thumbnailUrl): MediaFile
  322. {
  323. $this->thumbnailUrl = $thumbnailUrl;
  324. return $this;
  325. }
  326. public function getMediaType(): ?MediaType
  327. {
  328. return $this->mediaType;
  329. }
  330. public function setMediaType(?MediaType $mediaType): MediaFile
  331. {
  332. $this->mediaType = $mediaType;
  333. return $this;
  334. }
  335. /**
  336. * @return Collection<int, MediaTag>
  337. */
  338. public function getMediaTags(): Collection
  339. {
  340. return $this->mediaTags;
  341. }
  342. public function addMediaTag(MediaTag $mediaTag): self
  343. {
  344. if (!$this->mediaTags->contains($mediaTag)) {
  345. $this->mediaTags[] = $mediaTag;
  346. $mediaTag->addMediaFile($this);
  347. }
  348. return $this;
  349. }
  350. public function removeMediaTag(MediaTag $mediaTag): self
  351. {
  352. if ($this->mediaTags->removeElement($mediaTag)) {
  353. $mediaTag->removeMediaFile($this);
  354. }
  355. return $this;
  356. }
  357. public function getUploadMode(): MediaFileUploadModeEnum
  358. {
  359. return $this->uploadMode;
  360. }
  361. public function setUploadMode(MediaFileUploadModeEnum $uploadMode): MediaFile
  362. {
  363. $this->uploadMode = $uploadMode;
  364. return $this;
  365. }
  366. }