<?php
namespace App\Entity\ImmediateApplication;
use App\Entity\RecurrentJob;
use App\Entity\User;
use App\Service\MailService;
use App\Utility\DateTimeUtility;
use App\Utility\ReflectionHelper;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity()
*
* @ORM\Table(
* name="immediate_application_contact_messages",
* indexes={
*
* @ORM\Index(name="email_idx", columns={"email"}),
* }
* )
*/
class ContactMessage
{
public const CREATED_VIA_RECRUIT_DL = 0;
public function __construct()
{
$this->firstname = '';
$this->lastname = '';
$this->email = '';
$this->phone = '';
$this->user = null;
$this->contactMessageCvFiles = new ArrayCollection([]);
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->createdVia = null;
}
/**
* @var string
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
private $id;
public function getId(): string
{
return $this->id;
}
/**
* @var User|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
*
* @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $user;
public function setUser(User $user): void
{
$this->user = $user;
}
public function getUser(): ?User
{
return $this->user;
}
/**
* @var RecurrentJob|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\RecurrentJob", cascade={"persist"})
*
* @ORM\JoinColumn(name="recurrent_jobs_id", referencedColumnName="id", nullable=false, onDelete="SET NULL")
*/
private $recurrentJob;
public function setRecurrentJob(RecurrentJob $recurrentJob): void
{
$this->recurrentJob = $recurrentJob;
}
public function getRecurrentJob(): ?RecurrentJob
{
return $this->recurrentJob;
}
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=false)
*
* @Assert\NotBlank()
*
* @Assert\Length(
* min = 2,
* max = 50,
* )
*/
private $firstname;
public function getFirstname(): string
{
return $this->firstname;
}
public function setFirstname(string $firstname): void
{
$this->firstname = $firstname;
}
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=false)
*
* @Assert\NotBlank()
*/
private $lastname;
public function getLastname(): string
{
return $this->lastname;
}
public function setLastname(string $lastname): void
{
$this->lastname = $lastname;
}
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*
* @Assert\Email(mode="strict")
*
* @Assert\NotBlank()
*/
private $email;
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
if (!MailService::emailAddressIsValidForMailer($email)) {
throw new InvalidArgumentException("E-mail '$email' is not valid.");
}
$this->email = $email;
}
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=255, nullable=false)
*
* @Assert\NotBlank()
*
* @Assert\Regex(pattern="/^[ +\-\/0-9]{6,30}$/")
*/
private $phone;
public function getPhone(): string
{
return $this->phone;
}
public function setPhone(string $phone): void
{
$this->phone = $phone;
}
/**
* @var DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @var ContactMessageCvFile[]|Collection
*
* @ORM\OneToMany(targetEntity="\App\Entity\ImmediateApplication\ContactMessageCvFile", mappedBy="contactMessage", cascade={"persist", "remove"})
*/
private $contactMessageCvFiles;
public function getPrimaryCvFile(): ?ContactMessageCvFile
{
return $this->contactMessageCvFiles->get(0);
}
public function setPrimaryCvFile(ContactMessageCvFile $file): void
{
$this->contactMessageCvFiles[0] = $file;
}
public function getSecondaryCvFile(): ?ContactMessageCvFile
{
return $this->contactMessageCvFiles->get(1);
}
public function setSecondaryCvFile(ContactMessageCvFile $file): void
{
$this->contactMessageCvFiles[1] = $file;
}
/**
* @var ?int
*
* @ORM\Column(name="created_via", type="integer", nullable=true)
*/
private $createdVia;
public function getCreatedVia(): ?int
{
return $this->createdVia;
}
/**
* @throws Exception
*/
public function setCreatedVia(?int $createdVia): void
{
if (!is_null($createdVia) && !ReflectionHelper::hasConstWithValue(self::class, 'CREATED_VIA_', $createdVia)) {
throw new Exception("Not a valid value for createdVia: '{$createdVia}'.");
}
$this->createdVia = $createdVia;
}
}