<?php
namespace CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Symfony\Component\HttpFoundation\File\File as File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @ORM\Table("peer_solution_file")
* @Vich\Uploadable
*/
class PeerSolutionFile extends SolutionFile implements JsonSerializable
{
/**
* @var PeerSolution
*
* @ORM\ManyToOne(targetEntity="PeerSolution", inversedBy="peerSolutionFiles")
*/
private $peerSolution;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="peer_solution_file", fileNameProperty="fileName", originalName="originalName", size="fileSize", mimeType="mimeType")
*
* @var File
*/
private $file;
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,
];
}
}