<?php
namespace AppBundle\Entity;
use AppBundle\Entity\Traits\TimestampableTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Type;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Customer.
*
* @ORM\Table(name="customer")
* @ORM\HasLifecycleCallbacks
* @ORM\Entity(repositoryClass="AppBundle\Repository\CustomerRepository")
*/
#[UniqueEntity(fields: 'email', message: 'customer.email.unique')]
class Customer implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
{
use TimestampableTrait;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="Address", mappedBy="customer", fetch="LAZY")
* @ORM\OrderBy({"company" = "ASC", "name" = "ASC"})
*/
private $addresses;
/**
* @ORM\OneToMany(targetEntity="Booking", mappedBy="customer", fetch="LAZY")
*/
private $bookings;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, unique=true)
*/
#[Assert\NotBlank(message: 'customer.email.not_blank')]
#[Assert\Email(message: 'customer.email.valid')]
private $email;
/**
* If the customer wants to change his email, he has to validate it.
*
* @var string
*
* @ORM\Column(name="change_email", type="string", length=255, nullable=true)
*/
private $changeEmail;
/**
* @var string
*
* @ORM\Column(name="change_email_token", type="string", length=255, nullable=true)
*/
private $changeEmailToken;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
* @Type("string")
*/
private $plainPassword;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="company", type="string", length=255, nullable=true)
*/
private $company;
/**
* @var string
*
* @ORM\Column(name="street", type="string", length=255)
*/
#[Assert\NotBlank(message: 'customer.street.not_blank')]
private $street;
/**
* @var string
*
* @ORM\Column(name="zip", type="string", length=255)
*/
#[Assert\NotBlank(message: 'customer.zip.not_blank')]
private $zip;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255)
*/
#[Assert\NotBlank(message: 'customer.city.not_blank')]
private $city;
/**
* @var string
*
* @ORM\Column(name="country", type="string", length=255)
*/
#[Assert\NotBlank(message: 'customer.country.not_blank')]
private $country = 'Deutschland';
/**
* @var string
*
* @ORM\Column(name="contact_person", type="text", nullable=true)
*/
private $contactPerson;
/**
* @var string
*
* @ORM\Column(name="fon", type="string", length=255, nullable=true)
*/
private $fon;
/**
* @var string
*
* @ORM\Column(name="fax", type="string", length=255, nullable=true)
*/
private $fax;
/**
* @var bool
*
* @ORM\Column(name="active", type="boolean")
*/
private $active;
/**
* @var bool
*
* @ORM\Column(name="confirmed", type="boolean")
*/
private $confirmed;
/**
* @var string
*
* @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
*/
private $confirmationToken;
/**
* @var string
*
* @ORM\Column(name="password_reset_token", type="string", length=255, nullable=true)
*/
private $passwordResetToken;
/**
* @var string
*
* @ORM\Column(name="password_reset_token_valid_date", type="datetime", nullable=true)
*/
private $passwordResetTokenValidDate;
/**
* @var \DateTime
*
* @ORM\Column(name="last_login", type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @var string
*
* @ORM\Column(name="roles", type="string", length=255, nullable=true)
*/
private $roles;
/**
* Constructor.
*/
public function __construct()
{
$this->addresses = new \Doctrine\Common\Collections\ArrayCollection();
$this->bookings = new ArrayCollection();
}
/***********************************************************************************************************************************************
SPECIAL IMPLEMENTATIONS
************************************************************************************************************************************************/
/**
* Implement the AdvancedUserInterface.
*/
public function getUserIdentifier()
{
return $this->email;
}
public function getUsername()
{
return $this->getUserIdentifier();
}
public function getSalt()
{
return null;
}
// public function getPassword(){return $this->password;} // -> already implemented
public function getRoles()
{
$roles = ['ROLE_USER'];
if ($this->roles) {
$roles = explode(',', str_replace(' ', '', $this->roles));
}
return $roles;
}
public function eraseCredentials()
{
}
public function isAccountNonExpired()
{
return $this->confirmed;
}
public function isAccountNonLocked()
{
return true;
}
public function isCredentialsNonExpired()
{
return true;
}
public function isEnabled()
{
return $this->active;
}
/**
* Implement the \Serializable Interface.
*/
public function __serialize()
{
return [
$this->id,
$this->active,
$this->confirmed,
$this->password,
];
}
public function __unserialize(array $serialized)
{
[
$this->id,
$this->active,
$this->confirmed,
$this->password
] = $serialized;
}
public function isEqualTo(UserInterface $customer)
{
return true;
}
/**
* Set password.
*
* @param string $password
*
* @return Customer
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password.
*
* @return string
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* Set plainPassword.
*
* @param string $plainPassword
*
* @return Customer
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* Get plainPassword.
*
* @return string
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/***********************************************************************************************************************************************
GENERIC GETTERS AND SETTERS
************************************************************************************************************************************************/
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set email.
*
* @param string $email
*
* @return Customer
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set changeEmail.
*
* @param string $changeEmail
*
* @return Customer
*/
public function setChangeEmail($changeEmail)
{
$this->changeEmail = $changeEmail;
return $this;
}
/**
* Get changeEmail.
*
* @return string
*/
public function getChangeEmail()
{
return $this->changeEmail;
}
/**
* Set changeEmailToken.
*
* @param string $changeEmailToken
*
* @return Customer
*/
public function setChangeEmailToken($changeEmailToken)
{
$this->changeEmailToken = $changeEmailToken;
return $this;
}
/**
* Get changeEmailToken.
*
* @return string
*/
public function getChangeEmailToken()
{
return $this->changeEmailToken;
}
/**
* Set name.
*
* @param string $name
*
* @return Customer
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set company.
*
* @param string $company
*
* @return Customer
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* Get company.
*
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* Set street.
*
* @param string $street
*
* @return Customer
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* Get street.
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set zip.
*
* @param string $zip
*
* @return Customer
*/
public function setZip($zip)
{
$this->zip = $zip;
return $this;
}
/**
* Get zip.
*
* @return string
*/
public function getZip()
{
return $this->zip;
}
/**
* Set city.
*
* @param string $city
*
* @return Customer
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city.
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set country.
*
* @param string $country
*
* @return Customer
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country.
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set contactPerson.
*
* @param string $contactPerson
*
* @return Customer
*/
public function setContactPerson($contactPerson)
{
$this->contactPerson = $contactPerson;
return $this;
}
/**
* Get contactPerson.
*
* @return string
*/
public function getContactPerson()
{
return $this->contactPerson;
}
/**
* Set fon.
*
* @param string $fon
*
* @return Customer
*/
public function setFon($fon)
{
$this->fon = $fon;
return $this;
}
/**
* Get fon.
*
* @return string
*/
public function getFon()
{
return $this->fon;
}
/**
* Set fax.
*
* @param string $fax
*
* @return Customer
*/
public function setFax($fax)
{
$this->fax = $fax;
return $this;
}
/**
* Get fax.
*
* @return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set active.
*
* @param bool $active
*
* @return Customer
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active.
*
* @return bool
*/
public function getActive()
{
return $this->active;
}
/**
* Set confirmed.
*
* @param bool $confirmed
*
* @return Customer
*/
public function setConfirmed($confirmed)
{
$this->confirmed = $confirmed;
return $this;
}
/**
* Get confirmed.
*
* @return bool
*/
public function getConfirmed()
{
return $this->confirmed;
}
/**
* Set confirmationToken.
*
* @param string $confirmationToken
*
* @return Customer
*/
public function setConfirmationToken($confirmationToken)
{
$this->confirmationToken = $confirmationToken;
return $this;
}
/**
* Get confirmationToken.
*
* @return string
*/
public function getConfirmationToken()
{
return $this->confirmationToken;
}
/**
* Set passwordResetToken.
*
* @param string $passwordResetToken
*
* @return Customer
*/
public function setPasswordResetToken($passwordResetToken)
{
$this->passwordResetToken = $passwordResetToken;
return $this;
}
/**
* Get passwordResetToken.
*
* @return string
*/
public function getPasswordResetToken()
{
return $this->passwordResetToken;
}
/**
* Set passwordResetTokenValidDate.
*
* @param \DateTime $passwordResetTokenValidDate
*
* @return Customer
*/
public function setPasswordResetTokenValidDate($passwordResetTokenValidDate)
{
$this->passwordResetTokenValidDate = $passwordResetTokenValidDate;
return $this;
}
/**
* Get passwordResetTokenValidDate.
*
* @return \DateTime
*/
public function getPasswordResetTokenValidDate()
{
return $this->passwordResetTokenValidDate;
}
/**
* Set lastLogin.
*
* @param \DateTime $lastLogin
*
* @return Customer
*/
public function setLastLogin($lastLogin)
{
$this->lastLogin = $lastLogin;
return $this;
}
/**
* Get lastLogin.
*
* @return \DateTime
*/
public function getLastLogin()
{
return $this->lastLogin;
}
/**
* Add address.
*
* @param \AppBundle\Entity\Address $address
*
* @return Customer
*/
public function addAddress(Address $address)
{
$this->addresses[] = $address;
return $this;
}
/**
* Remove address.
*
* @param \AppBundle\Entity\Address $address
*/
public function removeAddress(Address $address)
{
$this->addresses->removeElement($address);
}
/**
* Get addresses.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAddresses()
{
return $this->addresses;
}
/**
* Add booking.
*
* @param \AppBundle\Entity\Booking $booking
*
* @return Customer
*/
public function addBooking(Booking $booking)
{
$this->bookings[] = $booking;
return $this;
}
/**
* Remove booking.
*
* @param \AppBundle\Entity\Booking $booking
*/
public function removeBooking(Booking $booking)
{
$this->bookings->removeElement($booking);
}
/**
* Get bookings.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getBookings()
{
return $this->bookings;
}
/**
* Set roles.
*
* @param string|null $roles
*
* @return Customer
*/
public function setRoles($roles = null)
{
$this->roles = $roles;
return $this;
}
}