<?php
namespace App\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Vich\UploaderBundle\Entity\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity()
*
* @ORM\Table(
* name="recurrent_job_profile_photos",
* uniqueConstraints={
*
* @ORM\UniqueConstraint(name="file_name_unique_idx", columns={"file_name"})
* },
* indexes={
*
* @ORM\Index(name="batch_id_idx", columns={"batch_id"}),
* }
* )
*
* @Vich\Uploadable
*/
class RecurrentJobProfilePhoto 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\User", cascade={"persist"})
*
* @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected User $user;
/**
* @var File|null
*
* @Vich\UploadableField(mapping="recurrent_job_profile_photo", fileNameProperty="fileName")
*/
protected $file;
/**
* @var string
*
* @ORM\Column(name="file_name", type="string", length=255, nullable=false)
*/
protected $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 DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt;
/**
* At the beginning of a recurrentJobProfilePhoto lifecycle, it is not necessarily attached to any
* recurrent job yet. That's because at least in some cases, the file is uploaded by the user while the user
* creates a new recurrent job, which is only created once the recurrent job form is submitted.
*
* @ORM\OneToOne(targetEntity="App\Entity\RecurrentJob", inversedBy="profilePhoto", cascade={"persist"})
*
* @ORM\JoinColumn(name="recurrent_jobs_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
protected ?RecurrentJob $recurrentJob;
public function setRecurrentJob(?RecurrentJob $recurrentJob): void
{
if (!is_null($this->user) && !is_null($recurrentJob)) {
if ($this->user->getId() !== $recurrentJob->getJoboffererProfile()->getUser()->getId()) {
throw new InvalidArgumentException("Recurrent job belongs to user '{$recurrentJob->getJoboffererProfile()->getUser()->getId()}', but file belongs to user '{$this->getUser()->getId()}'.");
}
}
$this->recurrentJob = $recurrentJob;
}
public function getRecurrentJob(): ?RecurrentJob
{
return $this->recurrentJob;
}
}