<?php
namespace App\Entity\Core\Peer;
use App\Entity\Core\SolutionFile;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use JsonSerializable;
use Symfony\Component\HttpFoundation\File\File as File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Attribute as Vich;
#[Vich\Uploadable]
#[ORM\Table('peer_solution_file')]
#[ORM\Entity]
class PeerSolutionFile extends SolutionFile implements JsonSerializable
{
/**
* @var PeerSolution
*/
#[ORM\ManyToOne(targetEntity: PeerSolution::class, inversedBy: 'peerSolutionFiles')]
private $peerSolution;
#[Vich\UploadableField(mapping: 'peer_solution_file', fileNameProperty: 'fileName', originalName: 'originalName', size: 'fileSize', mimeType: 'mimeType')]
private ?File $file = null;
public function getPeerSolution(): PeerSolution
{
return $this->peerSolution;
}
public function setPeerSolution(PeerSolution $peerSolution)
{
$this->peerSolution = $peerSolution;
}
/**
* @param File|UploadedFile $file
* @throws Exception
*/
public function setFile(?File $file = null): void
{
$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();
}
}
public function getFile(): ?File
{
return $this->file;
}
public function jsonSerialize(): mixed
{
return [
"fileName" => $this->fileName,
"originalName" => $this->originalName,
"fileSize" => $this->fileSize,
"mimeType" => $this->mimeType,
];
}
}