<?php
namespace App\RegisterBundle\Entity;
use App\Classes\Hasher;
use App\Entity\Invoice;
use App\RegisterBundle\Model;
use App\RegisterBundle\Validator\Constraints as AppAssert;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Registration
* @package App\RegisterBundle\Entity
* @ORM\Entity(repositoryClass="App\RegisterBundle\Repository\RegistrationRepository")
* @ORM\Table(name="malys_registration")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity("hashedId")
*/
class Registration
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="hashed_id", type="string", nullable=false)
*/
protected $hashedId;
/**
* @var DateTime
*
* @ORM\Column(name="createdAt", type="datetime", nullable=false)
*/
protected $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=true)
*/
protected $updatedAt;
/**
* @var DateTime
*
* @ORM\Column(name="completedAt", type="datetime", nullable=true)
*/
protected $completedAt;
/**
* @var string
*
* @ORM\Column(name="current_step", type="string", nullable=false)
* @Assert\Choice (callback={"RegisterBundle\Model\Registration", "getAvailableSteps"})
* @Assert\NotBlank(groups={"finish"})
*/
protected $currentStep;
/**
* @var string
*
* @ORM\Column(name="user_email", type="string", nullable=true)
* @Assert\Email (groups={"user", "finish"})
* @Assert\NotBlank (groups={"user", "finish"})
* @AppAssert\EmailAlreadyUsed(groups={"user", "finish"})
*/
protected $userEmail;
/**
* @var string
*
* @ORM\Column(name="user_hashed_password", type="string", nullable=true)
*/
protected $userHashedPassword;
/**
* @Assert\NotBlank (groups={"user"})
* @Assert\Length (min=8, minMessage="Votre mot de passe doit contenir au moins {{ limit }} caractères", groups={"user"})
*/
protected $userPlainPassword;
/**
* @var string
*
* @ORM\Column(name="user_first_name", type="string", nullable=true)
* @Assert\NotBlank (groups={"user", "finish"})
*/
protected $userFirstName;
/**
* @var string
*
* @ORM\Column(name="user_last_name", type="string", nullable=true)
* @Assert\NotBlank (groups={"user", "finish"})
*/
protected $userLastName;
/**
* @var string
*
* @ORM\Column(name="shop_brand_name", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopBrandName;
/**
* @var string
*
* @ORM\Column(name="shop_company_name", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopCompanyName;
/**
* @var string
*
* @ORM\Column(name="shop_address", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopAddress;
/**
* @var string
*
* @ORM\Column(name="shop_zipcode", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopZipcode;
/**
* @var string
*
* @ORM\Column(name="shop_city", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopCity;
/**
* @var string
*
* @ORM\Column(name="shop_country", type="string", nullable=true)
* @Assert\NotBlank (groups={"shop", "finish"})
*/
protected $shopCountry;
/**
* @var string
*
* @ORM\Column(name="shop_suppliers", type="json", nullable=true)
* @AppAssert\RegistrationSuppliers(groups={"suppliers", "finish"})
*/
protected $shopSuppliers;
/**
* @ORM\ManyToMany (targetEntity="App\Entity\Invoice", cascade={"persist"})
* @ORM\JoinTable (name="malys_registration_invoice")
* @Assert\Valid (groups={"invoices", "finish"})
*/
protected $invoices;
/**
* @var string
*
* @ORM\Column(name="fcm_device_id", type="string", nullable=true)
*/
protected $fcmDeviceId;
/**
* @var integer
*
* @ORM\Column(name="validation_code", type="string", nullable=false)
*/
protected $validationCode;
/**
* @var string
*
* @ORM\Column(name="verified_email", type="string", nullable=true)
*/
protected $verifiedEmail;
/**
* @var DateTime
*
* @ORM\Column(name="lastEmailSentAt", type="datetime", nullable=true)
*/
protected $lastEmailSentAt;
public function __toString()
{
return $this->shopBrandName ? $this->shopBrandName : '';
}
public function __construct()
{
$this->currentStep = Model\Registration::getDefaultStep();
$this->invoices = new ArrayCollection();
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return DateTime
*/
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
/**
* @param DateTime $createdAt
*
* @ORM\PrePersist
*/
public function setCreatedAt(): void
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
}
/**
* @return DateTime
*/
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
/**
* Set updatedAt
*
* @ORM\PreUpdate
* @throws Exception
*/
public function setUpdatedAt()
{
$this->updatedAt = new DateTime();
}
/**
* @return DateTime
*/
public function getCompletedAt(): ?DateTime
{
return $this->completedAt;
}
/**
* @param DateTime $completedAt
*/
public function setCompletedAt(DateTime $completedAt): void
{
$this->completedAt = $completedAt;
}
/**
* @return string
*/
public function getCurrentStep(): string
{
return $this->currentStep;
}
/**
* @param string $currentStep
*/
public function setCurrentStep(string $currentStep): void
{
$this->currentStep = $currentStep;
}
/**
* @return string
*/
public function getUserEmail(): ?string
{
return $this->userEmail;
}
/**
* @param string $userEmail
*/
public function setUserEmail(?string $userEmail): void
{
$this->userEmail = $userEmail;
}
/**
* @return string
*/
public function getUserHashedPassword(): ?string
{
return $this->userHashedPassword;
}
/**
* @param string $userHashedPassword
*/
public function setUserHashedPassword(string $userHashedPassword): void
{
$this->userHashedPassword = $userHashedPassword;
}
/**
* @return string
*/
public function getUserFirstName(): ?string
{
return $this->userFirstName;
}
/**
* @param string $userFirstName
*/
public function setUserFirstName(?string $userFirstName): void
{
$this->userFirstName = $userFirstName;
}
/**
* @return string
*/
public function getUserLastName(): ?string
{
return $this->userLastName;
}
/**
* @param string $userLastName
*/
public function setUserLastName(?string $userLastName): void
{
$this->userLastName = $userLastName;
}
/**
* @return string
*/
public function getShopBrandName(): ?string
{
return $this->shopBrandName;
}
/**
* @param string $shopBrandName
*/
public function setShopBrandName(string $shopBrandName): void
{
$this->shopBrandName = $shopBrandName;
}
/**
* @return string
*/
public function getShopCompanyName(): ?string
{
return $this->shopCompanyName;
}
/**
* @param string $shopCompanyName
*/
public function setShopCompanyName(string $shopCompanyName): void
{
$this->shopCompanyName = $shopCompanyName;
}
/**
* @return string
*/
public function getShopAddress(): ?string
{
return $this->shopAddress;
}
/**
* @param string $shopAddress
*/
public function setShopAddress(string $shopAddress): void
{
$this->shopAddress = $shopAddress;
}
/**
* @return string
*/
public function getShopZipcode(): ?string
{
return $this->shopZipcode;
}
/**
* @param string $shopZipcode
*/
public function setShopZipcode(string $shopZipcode): void
{
$this->shopZipcode = $shopZipcode;
}
/**
* @return string
*/
public function getShopCity(): ?string
{
return $this->shopCity;
}
/**
* @param string $shopCity
*/
public function setShopCity(string $shopCity): void
{
$this->shopCity = $shopCity;
}
/**
* @return string
*/
public function getShopCountry(): ?string
{
return $this->shopCountry;
}
/**
* @param string $shopCountry
*/
public function setShopCountry(string $shopCountry): void
{
$this->shopCountry = $shopCountry;
}
/**
* @return string
*/
public function getShopSuppliers()
{
return $this->shopSuppliers;
}
/**
* @param string $shopSuppliers
*/
public function setShopSuppliers(array $shopSuppliers): void
{
$this->shopSuppliers = $shopSuppliers;
}
/**
* @ORM\PrePersist
*/
public function installHashedId()
{
if (is_null($this->hashedId)) {
$this->hashedId = Hasher::generateHash(self::class);
}
}
/**
* @return mixed
*/
public function getHashedId(): string
{
return $this->hashedId;
}
/**
* @param mixed $hashedId
*/
public function setHashedId($hashedId): void
{
$this->hashedId = $hashedId;
}
/**
* @return mixed
*/
public function getUserPlainPassword(): ?string
{
return $this->userPlainPassword;
}
/**
* @param mixed $userPlainPassword
*/
public function setUserPlainPassword(?string $userPlainPassword): void
{
$this->userPlainPassword = $userPlainPassword;
}
/**
* @return ArrayCollection
*/
public function getInvoices()
{
return $this->invoices;
}
/**
* @param ArrayCollection $invoices
*/
public function setInvoices(ArrayCollection $invoices): void
{
$this->invoices = $invoices;
}
public function addInvoice(Invoice $invoice)
{
if (! $this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
}
}
public function removeInvoice(Invoice $invoice)
{
if ($this->invoices->contains($invoice)) {
$this->invoices->removeElement($invoice);
}
}
/**
* @return string
*/
public function getFcmDeviceId(): ?string
{
return $this->fcmDeviceId;
}
/**
* @param string|null $fcmDeviceId
*/
public function setFcmDeviceId(?string $fcmDeviceId): void
{
$this->fcmDeviceId = $fcmDeviceId;
}
/**
* @return int
*/
public function getValidationCode(): int
{
return $this->validationCode;
}
/**
* @param string|null $validationCode
*/
public function setValidationCode(?string $validationCode = null)
{
$this->validationCode = $validationCode;
}
/**
* @return string
*/
public function getVerifiedEmail(): ?string
{
return $this->verifiedEmail;
}
/**
* @param $verifiedEmail
*/
public function setVerifiedEmail($verifiedEmail)
{
$this->verifiedEmail = $verifiedEmail;
}
/**
* @return DateTime
*/
public function getLastEmailSentAt(): ?DateTime
{
return $this->lastEmailSentAt;
}
/**
* @param $lastEmailSentAt
*/
public function setLastEmailSentAt($lastEmailSentAt)
{
$this->lastEmailSentAt = $lastEmailSentAt;
}
}