<?php
namespace App\Entity\Core\Worksheet;
use App\Entity\Core\SolutionFile;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Exception;
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('worksheet_solution_file')]
#[ORM\Entity]
class WorksheetSolutionFile extends SolutionFile
{
/**
* @var WorksheetSolution
*/
#[ORM\ManyToOne(targetEntity: WorksheetSolution::class, inversedBy: 'worksheetSolutionFiles')]
private $worksheetSolution;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*/
#[Vich\UploadableField(mapping: 'worksheet_solution_file', fileNameProperty: 'fileName', originalName: 'originalName', size: 'fileSize', mimeType: 'mimeType')]
private ?File $file = null;
public function getWorksheetSolution(): WorksheetSolution
{
return $this->worksheetSolution;
}
public function setWorksheetSolution(WorksheetSolution $worksheetSolution)
{
$this->worksheetSolution = $worksheetSolution;
}
/**
* @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;
}
}