<?php
namespace App\Entity\ExtendedApplication;
use App\Entity\PlatformSite;
use App\Entity\Profile\JobseekerProfile;
use App\Entity\RecurrentJob;
use App\Service\ConversionEventService;
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 Exception;
use InvalidArgumentException;
use JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling;
use JanusHercules\ExternallyIncomingApplications\Domain\Entity\ExternallyIncomingApplication;
use JanusHercules\Shared\Infrastructure\Service\PhoneNumberFormationInfrastructureService;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity()
*
* @ORM\Table(
* name="extended_applications",
* indexes={
*
* @ORM\Index(name="email_idx", columns={"email"}),
* @ORM\Index(name="jobseeker_profiles_id_recurrent_jobs_id_x", columns={"jobseeker_profiles_id", "recurrent_jobs_id"})
* }
* )
*/
class ExtendedApplication
{
/** @throws Exception */
public function __construct()
{
$this->firstname = '';
$this->lastname = '';
$this->email = '';
$this->phone = '';
$this->jobseekerProfile = null;
$this->applicationText = null;
$this->extendedApplicationCvFiles = new ArrayCollection([]);
$this->createdAt = DateTimeUtility::createDateTimeUtc();
$this->recurrentJobSearchterm = '';
$this->recurrentJobBusinessName = '';
$this->recurrentJobCustomerInternalId = null;
$this->recurrentJobZipcode = null;
$this->createdViaPlatformSiteId = PlatformSite::PLATFORM_SITE_ID_JOBOO;
$this->createdViaCampaignId = null;
$this->isReadByJobofferer = false;
$this->extendedApplicationQuestionAnswers = new ArrayCollection();
$this->externallyIncomingApplication = null;
$this->applicationAppointmentScheduling = null;
}
/**
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
private string $id;
public function getId(): string
{
return $this->id;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Profile\JobseekerProfile", cascade={"persist"})
*
* @ORM\JoinColumn(name="jobseeker_profiles_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private ?JobseekerProfile $jobseekerProfile;
public function setJobseekerProfile(?JobseekerProfile $jobseekerProfile): void
{
$this->jobseekerProfile = $jobseekerProfile;
}
public function getJobseekerProfile(): ?JobseekerProfile
{
return $this->jobseekerProfile;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\RecurrentJob", cascade={"persist"}, inversedBy="extendedApplications")
*
* @ORM\JoinColumn(name="recurrent_jobs_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private ?RecurrentJob $recurrentJob;
public function setRecurrentJob(RecurrentJob $recurrentJob): void
{
$this->recurrentJob = $recurrentJob;
$this->recurrentJobBusinessName = $recurrentJob->getBusinessName();
$this->recurrentJobSearchterm = $recurrentJob->getOccupationalFieldSearchtermForDisplay();
$this->recurrentJobCustomerInternalId = $recurrentJob->getIntegratedExternalPartnerCustomer()?->getInternalId();
$this->recurrentJobZipcode = $recurrentJob->getZipcode();
}
public function getRecurrentJob(): ?RecurrentJob
{
return $this->recurrentJob;
}
/**
* @ORM\Column(name="firstname", type="string", length=255, nullable=false)
*
* @Assert\NotBlank()
*
* @Assert\Length(
* min = 2,
* max = 50,
* )
*/
private string $firstname;
public function getFirstname(): string
{
return $this->firstname;
}
public function setFirstname(string $firstname): void
{
$this->firstname = $firstname;
}
/**
* @ORM\Column(name="application_text", type="text", length=16384, nullable=true)
*/
private ?string $applicationText;
public function getApplicationText(): ?string
{
return $this->applicationText;
}
public function setApplicationText(?string $applicationText): void
{
$this->applicationText = $applicationText;
}
/**
* @ORM\Column(name="lastname", type="string", length=255, nullable=false)
*
* @Assert\NotBlank()
*/
private string $lastname;
public function getLastname(): string
{
return $this->lastname;
}
public function setLastname(string $lastname): void
{
$this->lastname = $lastname;
}
/**
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*
* @Assert\Email(mode="strict")
*
* @Assert\NotBlank()
*/
private string $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;
}
/**
* @ORM\Column(name="phone", type="string", length=255, nullable=true)
*/
private ?string $phone;
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): void
{
if (!is_null($phone)) {
$phone = trim($phone);
} else {
$this->phone = null;
}
if (is_null(PhoneNumberFormationInfrastructureService::formatPhonenumberE164($phone))) {
throw new InvalidArgumentException("Phone number $phone is not valid.");
}
$this->phone = $phone;
}
/**
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @var ExtendedApplicationCvFile[]|Collection
*
* @ORM\OneToMany(targetEntity="\App\Entity\ExtendedApplication\ExtendedApplicationCvFile", mappedBy="extendedApplication", cascade={"persist", "remove"})
*/
private Collection $extendedApplicationCvFiles;
public function getPrimaryCvFile(): ?ExtendedApplicationCvFile
{
return $this->extendedApplicationCvFiles->get(0);
}
public function setPrimaryCvFile(ExtendedApplicationCvFile $file): void
{
$this->extendedApplicationCvFiles[0] = $file;
}
public function getSecondaryCvFile(): ?ExtendedApplicationCvFile
{
return $this->extendedApplicationCvFiles->get(1);
}
public function setSecondaryCvFile(ExtendedApplicationCvFile $file): void
{
$this->extendedApplicationCvFiles[1] = $file;
}
public function getTertiaryCvFile(): ?ExtendedApplicationCvFile
{
return $this->extendedApplicationCvFiles->get(2);
}
public function setTertiaryCvFile(ExtendedApplicationCvFile $file): void
{
$this->extendedApplicationCvFiles[2] = $file;
}
public function removePrimaryFile(): void
{
$this->extendedApplicationCvFiles->remove(0);
}
public function removeSecondaryFile(): void
{
$this->extendedApplicationCvFiles->remove(1);
}
public function removeTertiaryFile(): void
{
$this->extendedApplicationCvFiles->remove(2);
}
/**
* @ORM\Column(name="recurrent_job_searchterm", type="string", length=255, nullable=false)
*/
private string $recurrentJobSearchterm;
/**
* @ORM\Column(name="recurrent_job_business_name", type="string", length=255, nullable=false)
*/
private string $recurrentJobBusinessName;
/**
* @ORM\Column(name="recurrent_job_customer_internal_id", type="string", length=255, nullable=true)
*/
private ?string $recurrentJobCustomerInternalId;
/**
* @ORM\Column(name="recurrent_job_zipcode", type="string", length=255, nullable=true)
*/
private ?string $recurrentJobZipcode;
public function getRecurrentJobSearchterm(): string
{
return $this->recurrentJobSearchterm;
}
public function getRecurrentJobBusinessName(): string
{
return $this->recurrentJobBusinessName;
}
public function getRecurrentJobCustomerInternalId(): ?string
{
return $this->recurrentJobCustomerInternalId;
}
public function getRecurrentJobZipcode(): ?string
{
return $this->recurrentJobZipcode;
}
/**
* @ORM\Column(name="created_via_platform_site_id", type="integer", nullable=true)
*/
private ?int $createdViaPlatformSiteId;
public function getCreatedViaPlatformSiteId(): ?int
{
return $this->createdViaPlatformSiteId;
}
/**
* @throws Exception
*/
public function setCreatedViaPlatformSiteId(?int $createdViaPlatformSiteId): void
{
if (!is_null($createdViaPlatformSiteId) && !ReflectionHelper::hasConstWithValue(PlatformSite::class, 'PLATFORM_', $createdViaPlatformSiteId)) {
throw new Exception("Not a valid value for createdVia: '$createdViaPlatformSiteId'.");
}
$this->createdViaPlatformSiteId = $createdViaPlatformSiteId;
}
/**
* @ORM\Column(name="created_via_campaign_id", type="integer", nullable=true)
*/
private ?int $createdViaCampaignId;
public function getCreatedViaCampaignId(): ?int
{
return $this->createdViaCampaignId;
}
/**
* @throws Exception
*/
public function setCreatedViaCampaignId(?int $createdViaCampaignId): void
{
if (!is_null($createdViaCampaignId) && !in_array($createdViaCampaignId, ConversionEventService::AVAILABLE_CAMPAIGN_IDS_FOR_INCOMING_TRAFFIC)) {
throw new Exception("Not a valid value for createdVia: '$createdViaCampaignId'.");
}
$this->createdViaCampaignId = $createdViaCampaignId;
}
/**
* @ORM\Column(name="is_read_by_jobofferer", type="boolean", nullable=false)
*/
private bool $isReadByJobofferer;
public function isReadByJobofferer(): bool
{
return $this->isReadByJobofferer;
}
public function setIsReadByJobofferer(bool $isReadByJobofferer): void
{
$this->isReadByJobofferer = $isReadByJobofferer;
}
/**
* @ORM\OneToMany(targetEntity="JanusHercules\ExtendedApplicationQuestionnaire\Domain\Entity\ExtendedApplicationQuestionAnswer", mappedBy="extendedApplication", cascade={"persist", "remove"})
*/
private Collection $extendedApplicationQuestionAnswers;
public function getExtendedApplicationQuestionAnswers(): Collection
{
return $this->extendedApplicationQuestionAnswers;
}
public function setExtendedApplicationQuestionAnswers(Collection $answers): void
{
$this->extendedApplicationQuestionAnswers = $answers;
}
/**
* @ORM\OneToOne(targetEntity="JanusHercules\ExternallyIncomingApplications\Domain\Entity\ExternallyIncomingApplication", cascade={"persist"})
*
* @ORM\JoinColumn(name="externally_incoming_applications_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
private ?ExternallyIncomingApplication $externallyIncomingApplication;
public function getExternallyIncomingApplication(): ?ExternallyIncomingApplication
{
return $this->externallyIncomingApplication;
}
public function setExternallyIncomingApplication(?ExternallyIncomingApplication $externallyIncomingApplication): void
{
$this->externallyIncomingApplication = $externallyIncomingApplication;
}
/**
* @ORM\OneToOne(targetEntity="JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling", mappedBy="extendedApplication", cascade={"persist", "remove"})
*/
private ?ApplicationAppointmentScheduling $applicationAppointmentScheduling;
public function getApplicationAppointmentScheduling(): ?ApplicationAppointmentScheduling
{
return $this->applicationAppointmentScheduling;
}
}