<?php
namespace JanusHercules\JoboffererRegistration\Domain\Entity;
use App\Entity\User;
use App\Utility\DatabaseIdGenerator;
use App\Validator\Constraint as AppAssert;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\CustomIdGenerator;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Doctrine\ORM\Mapping\Table;
use InvalidArgumentException;
use Symfony\Component\Validator\Constraints as Assert;
#[Entity]
#[Table(
name: 'payment_form_databags',
)]
class PaymentFormDatabag
{
public function __construct(
User $user,
) {
$this->userId = $user;
$this->createdAt = new DateTime();
}
#[Id]
#[GeneratedValue(strategy: 'CUSTOM')]
#[CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[Column(
type : Types::GUID,
unique: true
)]
private string $id;
public function getId(): string
{
return $this->id;
}
public function setId(string $id): void
{
$this->id = $id;
}
#[Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
#[Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $updatedAt;
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTime $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
#[OneToOne(
targetEntity: User::class,
)]
#[JoinColumn(
name: 'users_id',
referencedColumnName: 'id',
nullable: false,
onDelete: 'CASCADE'
)]
public User $userId;
public function getUserId(): User
{
return $this->userId;
}
public function setUserId(User $user): void
{
$this->userId = $user;
}
#[Column(
name: 'email_for_invoice',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Email]
private ?string $emailForInvoice;
public function getEmailForInvoice(): ?string
{
return $this->emailForInvoice;
}
public function setEmailForInvoice(?string $emailForInvoice = null): void
{
$this->emailForInvoice = $emailForInvoice;
}
// form field names in form differ from database
public function setEmailAddress(?string $emailForInvoice = null): void
{
$this->emailForInvoice = $emailForInvoice;
}
#[Column(
name: 'firstname',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Length(min: 0, max: 50)]
private ?string $firstname;
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname = null): void
{
$this->firstname = $firstname;
}
#[Column(
name: 'lastname',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Length(min: 0, max: 50)]
private ?string $lastname;
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname = null): void
{
$this->lastname = $lastname;
}
#[Column(
name: 'streetname',
type: Types::STRING,
length: 128,
nullable: true)]
#[Assert\Length(
min: 5,
max: 128,
)]
private ?string $streetname;
public function getStreetname(): ?string
{
return $this->streetname;
}
public function setStreetname(?string $streetname = null): void
{
$this->streetname = $streetname;
}
// form field names in form differ from database
public function setAddressStreet(?string $streetname = null): void
{
$this->streetname = $streetname;
}
#[Column(
name: 'house_number',
type: Types::STRING,
length: 128,
nullable: true)]
#[Assert\Length(
min: 1,
max: 128,
)]
private ?string $houseNumber;
public function getHouseNumber(): ?string
{
return $this->houseNumber;
}
public function setHouseNumber(?string $houseNumber = null): void
{
$this->houseNumber = $houseNumber;
}
// form field names in form differ from database
public function setAddressHouseNumber(?string $houseNumber = null): void
{
$this->houseNumber = $houseNumber;
}
public function getStreetAndHouseNumber(): string
{
return $this->streetname . ' ' . $this->houseNumber;
}
#[Column(
name: 'zipcode',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Type('string')]
#[AppAssert\KnownZipcode(
message : 'Diese PLZ ist uns leider nicht bekannt.',
zipcodeIsAtStartOfString: true,
groups : ['step1']
)]
private ?string $zipcode = null;
public function getZipcode(): ?string
{
return $this->zipcode;
}
public function setZipcode(?string $zipcode = null): void
{
if (!is_null($zipcode)) {
$trimmedZipcode = trim($zipcode);
if (mb_strlen($trimmedZipcode) !== 5 || !is_numeric($trimmedZipcode)) {
throw new InvalidArgumentException("zipcode must either be null or a string with 5 digits, but got '$zipcode'");
}
$zipcode = $trimmedZipcode;
}
$this->zipcode = $zipcode;
}
// form field names in form differ from database
public function setAddressPostalCode(?string $zipcode = null): void
{
if (!is_null($zipcode)) {
$trimmedZipcode = trim($zipcode);
if (mb_strlen($trimmedZipcode) !== 5 || !is_numeric($trimmedZipcode)) {
throw new InvalidArgumentException("zipcode must either be null or a string with 5 digits, but got '$zipcode'");
}
$zipcode = $trimmedZipcode;
}
$this->zipcode = $zipcode;
}
#[Column(
name: 'city',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Length(
min: 2,
max: 128,
)]
private ?string $city;
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city = null): void
{
if (!is_null($city)) {
$this->city = mb_substr($city, 0, 128);
}
}
// form field names in form differ from database
public function setAddressCity(?string $city = null): void
{
if (!is_null($city)) {
$this->city = mb_substr($city, 0, 128);
}
}
#[Column(
name: 'businessName',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Length(
min: 2,
max: 100,
)]
private ?string $businessName;
public function getBusinessName(): ?string
{
return $this->businessName;
}
public function setBusinessName(?string $businessName = null): void
{
if (!is_null($businessName)) {
$this->businessName = mb_substr($businessName, 0, 128);
} else {
$this->businessName = null;
}
}
// form field names in form differ from database
public function setCompanyName(?string $businessName = null): void
{
if (!is_null($businessName)) {
$this->businessName = mb_substr($businessName, 0, 128);
} else {
$this->businessName = null;
}
}
#[Column(
name: 'mobilenumber',
type: Types::STRING,
length: 128,
nullable: true
)]
#[Assert\Length(
min: 6,
max: 30,
)]
#[Assert\Regex(pattern: "/^[ +\-\/0-9]{6,30}$/")]
private ?string $mobilenumber;
public function getMobilenumber(): ?string
{
return $this->mobilenumber;
}
public function setMobilenumber(?string $mobilenumber = null): void
{
$this->mobilenumber = $mobilenumber;
}
// form field names in form differ from database
public function setPhoneNumber(?string $mobilenumber = null): void
{
$this->mobilenumber = $mobilenumber;
}
}