'partial', ])] class ResourceFile { use TimestampableEntity; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) * @ORM\Id * @ORM\Column(type="bigint") * @ORM\GeneratedValue */ protected ?int $id = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read"}) * * @ORM\Column(type="string", length=255) */ #[Assert\NotBlank] protected ?string $name = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) * @ORM\Column(type="text", nullable=true) */ protected ?string $mimeType = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) * @ORM\Column(type="text", nullable=true) */ protected ?string $originalName = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read"}) * @ORM\Column(type="simple_array", nullable=true) */ protected ?array $dimensions; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) * * @ORM\Column(type="integer") */ protected ?int $size = 0; /** * @Vich\UploadableField( * mapping="resources", * fileNameProperty="name", * size="size", * mimeType="mimeType", * originalName="originalName", * dimensions="dimensions" * ) */ // #[Vich\UploadableField( // mapping: 'resources', // fileNameProperty: 'name', // size: 'size', // mimeType: 'mimeType', // originalName: 'originalName', // dimensions: 'dimensions' // )] protected ?File $file = null; /** * @ORM\Column(name="crop", type="string", length=255, nullable=true) */ protected ?string $crop = null; /** * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", mappedBy="resourceFile") */ protected ResourceNode $resourceNode; /** * @var string[] * * @ORM\Column(type="array", nullable=true) */ protected ?array $metadata = []; #[Groups(['message:read'])] protected ?bool $audio = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) */ protected ?bool $image = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) */ protected ?bool $video = null; /** * @Groups({"resource_file:read", "resource_node:read", "document:read", "message:read"}) */ protected ?bool $text = null; /** * @ORM\Column(name="description", type="text", nullable=true) */ protected ?string $description = null; /** * @var DateTime|DateTimeImmutable * @Gedmo\Timestampable(on="update") * @ORM\Column(type="datetime") */ protected $updatedAt; public function __construct() { $this->size = 0; $this->metadata = []; $this->dimensions = []; } public function __toString(): string { return $this->getOriginalName(); } public function isText(): bool { $mimeType = $this->getMimeType(); return str_contains($mimeType, 'text'); } public function isImage(): bool { $mimeType = $this->getMimeType(); return str_contains($mimeType, 'image'); } public function isVideo(): bool { $mimeType = $this->getMimeType(); return str_contains($mimeType, 'video'); } public function isAudio(): bool { $mimeType = $this->getMimeType(); return str_contains($mimeType, 'audio'); } public function getName(): ?string { return $this->name; } public function setName(?string $name): self { $this->name = $name; return $this; } /** * @return string */ public function getCrop() { return $this->crop; } /** * $crop example: 100,100,100,100 = width,height,x,y. */ public function setCrop(string $crop): self { $this->crop = $crop; return $this; } public function getSize(): ?int { return $this->size; } public function setSize(?int $size): self { $this->size = $size; return $this; } public function getResourceNode(): ResourceNode { return $this->resourceNode; } public function setResourceNode(ResourceNode $resourceNode): self { $this->resourceNode = $resourceNode; return $this; } /*public function isEnabled(): bool { return $this->enabled; } public function setEnabled(bool $enabled): self { $this->enabled = $enabled; return $this; }*/ /** * @return int */ public function getId() { return $this->id; } /*public function getDescription(): string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; }*/ public function getMimeType(): ?string { return $this->mimeType; } public function setMimeType(?string $mimeType): self { $this->mimeType = $mimeType; return $this; } public function getOriginalName(): string { return $this->originalName; } public function setOriginalName(?string $originalName): self { $this->originalName = $originalName; return $this; } public function getDimensions(): array { return $this->dimensions; } public function setDimensions(?array $dimensions): self { $this->dimensions = $dimensions; return $this; } public function getWidth(): int { $data = $this->getDimensions(); if ([] !== $data) { //$data = explode(',', $data); return (int) $data[0]; } return 0; } public function getHeight(): int { $data = $this->getDimensions(); if ([] !== $data) { //$data = explode(',', $data); return (int) $data[1]; } return 0; } public function getMetadata(): array { return $this->metadata; } public function setMetadata(array $metadata): self { $this->metadata = $metadata; return $this; } public function getDescription(): string { return $this->description; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function getFile(): ?File { return $this->file; } /** * @param File|UploadedFile|null $file */ public function setFile(?File $file = null): self { $this->file = $file; if (null !== $file) { // It is required that at least one field changes if you are using doctrine // otherwise the event listeners won't be called and the file is lost $this->updatedAt = new DateTimeImmutable(); } return $this; } }