<?php
namespace App\Entity\ExtendedApplication;
use App\Entity\User;
use App\Entity\UserUploadedFile;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity()
*
* @ORM\Table(
* name="extended_application_cv_files",
* uniqueConstraints={
*
* @ORM\UniqueConstraint(name="file_name_unique_idx", columns={"file_name"})
* },
* indexes={
*
* @ORM\Index(name="batch_id_idx", columns={"batch_id"}),
* }
* )
*
* @Vich\Uploadable
*/
class ExtendedApplicationCvFile extends UserUploadedFile
{
/**
* @var string
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ExtendedApplication\ExtendedApplication", inversedBy="extendedApplicationCvFiles", cascade={"persist"})
*
* @ORM\JoinColumn(name="extended_application_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected ExtendedApplication $extendedApplication;
/**
* @var File|null
*
* @Vich\UploadableField(mapping="extended_application_cv_file", fileNameProperty="fileName")
*/
protected $file;
/**
* @var string|null
*
* @ORM\Column(name="file_name", type="string", length=255, nullable=false)
*/
protected $fileName;
public function getFileName(): string
{
if (is_null($this->fileName)) {
return '';
}
return $this->fileName;
}
/**
* @var string
*
* @ORM\Column(name="original_file_name", type="string", length=255, nullable=false)
*/
protected $originalFileName;
/**
* @var string
*
* @ORM\Column(name="mime_type", type="string", length=255, nullable=false)
*/
protected $mimeType;
/**
* @var string
*
* @ORM\Column(name="batch_id", type="string", length=64, nullable=false)
*/
protected $batchId;
/**
* @var bool
*
* @ORM\Column(name="is_primary", type="boolean", nullable=false)
*/
protected $isPrimary;
public function setIsPrimary(bool $isPrimary): void
{
$this->isPrimary = $isPrimary;
}
/**
* @var DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
public function setExtendedApplication(ExtendedApplication $extendedApplication): void
{
$this->extendedApplication = $extendedApplication;
}
/** @throws Exception */
public function getUser(): User
{
if (is_null($this->extendedApplication)) {
$file = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['file'];
$line = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['line'];
$function = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
throw new Exception("Connected extended application is null. Called from file '$file', line '$line', function '$function.");
}
if (is_null($this->extendedApplication->getJobseekerProfile()) || is_null($this->extendedApplication->getJobseekerProfile()->getUser())) {
throw new Exception("Connected extended application {$this->extendedApplication->getId()} does not have a user or jobseekerProfile set.");
}
return $this->extendedApplication->getJobseekerProfile()->getUser();
}
}