<?php
namespace Aviatur\CustomerBundle\Entity;
use Aviatur\CustomerBundle\Entity\EntityValidator\CustomerValidator;
use Aviatur\CustomerBundle\Exception\ValidateException;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* Customer.
*
* @ORM\Table(name="customer", indexes={@ORM\Index(name="IDX_784FEC5F708A0E0", columns={"gender_id"}), @ORM\Index(name="IDX_784FEC5F4DA0E3EA", columns={"document_type_id"}), @ORM\Index(name="IDX_784FEC5F8C5BFD64", columns={"civil_status_id"}), @ORM\Index(name="IDX_784FEC5FF92F3E70", columns={"country_id"}), @ORM\Index(name="IDX_784FEC5F8BAC62AF", columns={"city_id"}), @ORM\Index(name="IDX_784FEC5F4C2D161B", columns={"travel_preference_id"})},
* uniqueConstraints={@ORM\UniqueConstraint(name="search_idx", columns={"firstname", "email"})})
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class Customer extends BaseUser
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var int
*
* @ORM\Column(name="aviaturClientId", type="integer", nullable=true)
*/
protected $aviaturclientid;
/**
* @var string
*
* @ORM\Column(name="documentNumber", type="string", length=100, nullable=true)
*/
protected $documentnumber;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=64, nullable=true)
*/
protected $firstname;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=64, nullable=true)
*/
protected $lastname;
/**
* @var \DateTime
*
* @ORM\Column(name="birthdate", type="date", nullable=true)
*/
protected $birthdate;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255, nullable=true)
*/
protected $address;
/**
* @var string
*
* @ORM\Column(name="cellphone", type="string", length=100, nullable=true)
*/
protected $cellphone;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=64, nullable=true)
*/
protected $phone;
/**
* @var int
*
* @ORM\Column(name="acceptInformation", type="integer", nullable=true)
*/
protected $acceptinformation;
/**
* @var int
*
* @ORM\Column(name="acceptSms", type="integer", nullable=true)
*/
protected $acceptsms;
/**
* @var int
*
* @ORM\Column(name="personType", type="integer", nullable=true)
*/
protected $persontype;
/**
* @var string
*
* @ORM\Column(name="corporateId", type="string", length=100, nullable=true)
*/
protected $corporateid;
/**
* @var string
*
* @ORM\Column(name="corporateName", type="string", length=200, nullable=true)
*/
protected $corporatename;
/**
* @var int
*
* @ORM\Column(name="frecuencySms", type="integer", nullable=true)
*/
protected $frecuencysms;
/**
* @var string
*
* @ORM\Column(name="googleId", type="string", length=255, nullable=true)
*/
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
// Getter y Setter para createdAt
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTime();
}
protected $googleId;
/**
* @var string
*
* @ORM\Column(name="facebookId", type="string", length=255, nullable=true)
*/
protected $facebookId;
/**
* @var string
*
* @ORM\Column(name="temp_email", type="string", length=255, nullable=true)
*/
protected $tempEmail;
/**
* @var string
*
* @ORM\Column(name="temp_email_token", type="string", length=255, nullable=true)
*/
protected $tempEmailToken;
/**
* @var string
*
* @ORM\Column(name="acceptconditions", type="string", length=10, nullable=true)
*/
protected $acceptConditions;
/**
* @var string
*
* @ORM\Column(name="hash", type="text", nullable=true)
*/
protected $hash;
/**
* @var \TravelPreference
*
* @ORM\ManyToOne(targetEntity="TravelPreference", inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="travel_preference_id", referencedColumnName="id")
* })
*/
protected $travelPreference;
/**
* @var \DocumentType
*
* @ORM\ManyToOne(targetEntity="DocumentType", inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="document_type_id", referencedColumnName="id")
* })
*/
protected $documentType;
/**
* @var \CivilStatus
*
* @ORM\ManyToOne(targetEntity="CivilStatus", inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="civil_status_id", referencedColumnName="id")
* })
*/
protected $civilStatus;
/**
* @var \Gender
*
* @ORM\ManyToOne(targetEntity="Gender", inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="gender_id", referencedColumnName="id")
* })
*/
protected $genderAviatur;
/**
* @var \City
*
* @ORM\ManyToOne(targetEntity="Aviatur\GeneralBundle\Entity\City", inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="city_id", referencedColumnName="id")
* })
*/
protected $city;
/**
* @var \Country
*
* @ORM\ManyToOne(targetEntity="Aviatur\GeneralBundle\Entity\Country",inversedBy="customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="country_id", referencedColumnName="id")
* })
*/
protected $country;
/**
* @ORM\OneToMany(targetEntity="Aviatur\GeneralBundle\Entity\Order", mappedBy="customer", cascade={"all"})
*/
protected $order;
/**
* @ORM\OneToMany(targetEntity="Aviatur\ContentBundle\Entity\HistoricalContent", mappedBy="customer", cascade={"all"})
*/
private $historicalContent;
/**
* @ORM\OneToMany(targetEntity="Aviatur\ContentBundle\Entity\Content", mappedBy="user", cascade={"all"})
*/
private $content;
/**
* @ORM\OneToMany(targetEntity="Aviatur\AgentBundle\Entity\Agent", mappedBy="customer", cascade={"all"})
*/
private $agent;
/**
* @var Agency
*
* @ORM\ManyToOne(targetEntity="Aviatur\AgencyBundle\Entity\Agency")
* @ORM\JoinColumn(name="agency_id", referencedColumnName="id", nullable=true)
*/
private $agency;
public function __toString()
{
$return = $this->getFirstname().' '.$this->getLastname().'('.$this->getDocumentnumber().')';
return $return;
}
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->activityLog = new \Doctrine\Common\Collections\ArrayCollection();
$this->content = new \Doctrine\Common\Collections\ArrayCollection();
$this->userAgency = new \Doctrine\Common\Collections\ArrayCollection();
$this->historicalContent = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set salt.
*
* @param string $salt
*
* @return Customer
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Set aviaturclientid.
*
* @param int $aviaturclientid
*
* @return Customer
*/
public function setAviaturclientid($aviaturclientid)
{
$this->aviaturclientid = $aviaturclientid;
return $this;
}
/**
* Get aviaturclientid.
*
* @return int
*/
public function getAviaturclientid()
{
return $this->aviaturclientid;
}
/**
* Set documentnumber.
*
* @param string $documentnumber
*
* @return Customer
*/
public function setDocumentnumber($documentnumber)
{
$this->documentnumber = $documentnumber;
return $this;
}
/**
* Get documentnumber.
*
* @return string
*/
public function getDocumentnumber()
{
return $this->documentnumber;
}
/**
* Set firstname.
*
* @param string $firstname
*
* @return Customer
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname.
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname.
*
* @param string $lastname
*
* @return Customer
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname.
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set birthdate.
*
* @param \DateTime $birthdate
*
* @return Customer
*/
public function setBirthdate($birthdate)
{
$this->birthdate = $birthdate;
return $this;
}
/**
* Get birthdate.
*
* @return \DateTime
*/
public function getBirthdate()
{
return $this->birthdate;
}
/**
* Set address.
*
* @param string $address
*
* @return Customer
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address.
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set phone.
*
* @param string $phone
*
* @return Customer
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone.
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set cellphone.
*
* @param string $cellphone
*
* @return Customer
*/
public function setCellphone($cellphone)
{
$this->cellphone = $cellphone;
return $this;
}
/**
* Get cellphone.
*
* @return string
*/
public function getCellphone()
{
return $this->cellphone;
}
/**
* 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 enabled.
*
* @param string $password
*
* @return Customer
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
return $this;
}
/**
* Get enabled.
*
* @return string
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* Set acceptinformation.
*
* @param int $acceptinformation
*
* @return Customer
*/
public function setAcceptinformation($acceptinformation)
{
$this->acceptinformation = $acceptinformation;
return $this;
}
/**
* Get acceptinformation.
*
* @return int
*/
public function getAcceptinformation()
{
return $this->acceptinformation;
}
/**
* Set acceptsms.
*
* @param int $acceptsms
*
* @return Customer
*/
public function setAcceptsms($acceptsms)
{
$this->acceptsms = $acceptsms;
return $this;
}
/**
* Get acceptsms.
*
* @return int
*/
public function getAcceptsms()
{
return $this->acceptsms;
}
/**
* Set persontype.
*
* @param int $persontype
*
* @return Customer
*/
public function setPersontype($persontype)
{
$this->persontype = $persontype;
return $this;
}
/**
* Get persontype.
*
* @return int
*/
public function getPersontype()
{
return $this->persontype;
}
/**
* Set corporateid.
*
* @param string $corporateid
*
* @return Customer
*/
public function setCorporateid($corporateid)
{
$this->corporateid = $corporateid;
return $this;
}
/**
* Get corporateid.
*
* @return string
*/
public function getCorporateid()
{
return $this->corporateid;
}
/**
* Set corporatename.
*
* @param string $corporatename
*
* @return Customer
*/
public function setCorporatename($corporatename)
{
$this->corporatename = $corporatename;
return $this;
}
/**
* Get corporatename.
*
* @return string
*/
public function getCorporatename()
{
return $this->corporatename;
}
/**
* Set frecuencysms.
*
* @param int $frecuencysms
*
* @return Customer
*/
public function setFrecuencysms($frecuencysms)
{
$this->frecuencysms = $frecuencysms;
return $this;
}
/**
* Get frecuencysms.
*
* @return int
*/
public function getFrecuencysms()
{
return $this->frecuencysms;
}
/**
* Set hash.
*
* @param string $hash
*
* @return Customer
*/
public function setHash($hash)
{
$this->hash = $hash;
return $this;
}
/**
* Get hash.
*
* @return string
*/
public function getHash()
{
return $this->hash;
}
/**
* Set googleId.
*
* @param string $googleId
*
* @return Customer
*/
public function setGoogleId($googleId)
{
$this->googleId = $googleId;
return $this;
}
/**
* Get googleId.
*
* @return string
*/
public function getGoogleId()
{
return $this->googleId;
}
/**
* Set facebookId.
*
* @param string $facebookId
*
* @return Customer
*/
public function setFacebookId($facebookId)
{
$this->facebookId = $facebookId;
return $this;
}
/**
* Get facebookId.
*
* @return string
*/
public function getFacebookId()
{
return $this->facebookId;
}
/**
* Set tempEmail.
*
* @param string $tempEmail
*
* @return Customer
*/
public function setTempEmail($tempEmail)
{
$this->tempEmail = $tempEmail;
return $this;
}
/**
* Get tempEmail.
*
* @return string
*/
public function getTempEmail()
{
return $this->tempEmail;
}
/**
* Set tempEmailToken.
*
* @param string $tempEmailToken
*
* @return Customer
*/
public function setTempEmailToken($tempEmailToken)
{
$this->tempEmailToken = $tempEmailToken;
return $this;
}
/**
* Get tempEmailToken.
*
* @return string
*/
public function getTempEmailToken()
{
return $this->tempEmailToken;
}
/**
* Set acceptConditions.
*
* @param string $acceptConditions
*
* @return Customer
*/
public function setAcceptConditions($acceptConditions)
{
$this->acceptConditions = $acceptConditions;
return $this;
}
/**
* Get acceptConditions.
*
* @return string
*/
public function getAcceptConditions()
{
return $this->acceptConditions;
}
/**
* Set travelPreference.
*
* @param \Aviatur\CustomerBundle\Entity\TravelPreference $travelPreference
*
* @return Customer
*/
public function setTravelPreference(\Aviatur\CustomerBundle\Entity\TravelPreference $travelPreference = null)
{
$this->travelPreference = $travelPreference;
return $this;
}
/**
* Get travelPreference.
*
* @return \Aviatur\CustomerBundle\Entity\TravelPreference
*/
public function getTravelPreference()
{
return $this->travelPreference;
}
/**
* Set documentType.
*
* @param \Aviatur\CustomerBundle\Entity\DocumentType $documentType
*
* @return Customer
*/
public function setDocumentType(\Aviatur\CustomerBundle\Entity\DocumentType $documentType = null)
{
$this->documentType = $documentType;
return $this;
}
/**
* Get documentType.
*
* @return \Aviatur\CustomerBundle\Entity\DocumentType
*/
public function getDocumentType()
{
return $this->documentType;
}
/**
* Set civilStatus.
*
* @param \Aviatur\CustomerBundle\Entity\CivilStatus $civilStatus
*
* @return Customer
*/
public function setCivilStatus(\Aviatur\CustomerBundle\Entity\CivilStatus $civilStatus = null)
{
$this->civilStatus = $civilStatus;
return $this;
}
/**
* Get civilStatus.
*
* @return \Aviatur\CustomerBundle\Entity\CivilStatus
*/
public function getCivilStatus()
{
return $this->civilStatus;
}
/**
* Set genderAviatur.
*
* @param \Aviatur\CustomerBundle\Entity\Gender $genderAviatur
*
* @return Customer
*/
public function setGenderAviatur(\Aviatur\CustomerBundle\Entity\Gender $genderAviatur = null)
{
$this->genderAviatur = $genderAviatur;
return $this;
}
/**
* Get genderAviatur.
*
* @return \Aviatur\CustomerBundle\Entity\Gender
*/
public function getGenderAviatur()
{
return $this->genderAviatur;
}
/**
* Set city.
*
* @param \Aviatur\GeneralBundle\Entity\City $city
*
* @return Customer
*/
public function setCity(\Aviatur\GeneralBundle\Entity\City $city = null)
{
$this->city = $city;
return $this;
}
/**
* Get city.
*
* @return \Aviatur\GeneralBundle\Entity\City
*/
public function getCity()
{
return $this->city;
}
/**
* Set country.
*
* @param \Aviatur\GeneralBundle\Entity\Country $country
*
* @return Customer
*/
public function setCountry(\Aviatur\GeneralBundle\Entity\Country $country = null)
{
$this->country = $country;
return $this;
}
/**
* Get country.
*
* @return \Aviatur\GeneralBundle\Entity\Country
*/
public function getCountry()
{
return $this->country;
}
/**
* Add order.
*
* @return Customer
*/
public function addOrder(\Aviatur\GeneralBundle\Entity\Order $order)
{
$this->order[] = $order;
return $this;
}
/**
* Remove order.
*/
public function removeOrder(\Aviatur\GeneralBundle\Entity\Order $order)
{
$this->order->removeElement($order);
}
/**
* Get order.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getOrder()
{
return $this->order;
}
/**
* Add historicalContent.
*
* @return Content
*/
public function addHistoricalContent(\Aviatur\ContentBundle\Entity\HistoricalContent $historicalContent)
{
$this->historicalContent[] = $historicalContent;
return $this;
}
/**
* Remove historicalContent.
*/
public function removeHistoricalContent(\Aviatur\ContentBundle\Entity\HistoricalContent $historicalContent)
{
$this->historicalContent->removeElement($historicalContent);
}
/**
* Get historicalContent.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getHistoricalContent()
{
return $this->historicalContent;
}
/**
* Add content.
*
* @return Content
*/
public function addContent(\Aviatur\ContentBundle\Entity\Content $content)
{
$this->content[] = $content;
return $this;
}
/**
* Remove content.
*/
public function removeContent(\Aviatur\ContentBundle\Entity\Content $content)
{
$this->content->removeElement($content);
}
/**
* Get content.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getContent()
{
return $this->content;
}
/**
* Add agency.
*
* @return Agency
*/
public function addAgency(\Aviatur\AgencyBundle\Entity\Agency $agency)
{
$this->agency[] = $agency;
return $this;
}
/**
* Remove agency.
*/
public function removeAgency(\Aviatur\AgencyBundle\Entity\Agency $agency)
{
$this->agency->removeElement($agency);
}
/**
* Get agency.
*
* @return \Aviatur\AgencyBundle\Entity\Agency
*/
public function getAgency()
{
return $this->agency;
}
/**
* Set agency.
*
* @param \Aviatur\AgencyBundle\Entity\Agency $agency
*
* @return Customer
*/
public function setAgency(\Aviatur\AgencyBundle\Entity\Agency $agency = null)
{
$this->agency = $agency;
return $this;
}
/**
* Add agent.
*
* @return Agent
*/
public function addAgent(\Aviatur\AgentBundle\Entity\Agent $agent)
{
$this->agent[] = $agent;
return $this;
}
/**
* Remove agent.
*/
public function removeAgent(\Aviatur\AgentBundle\Entity\Agent $agent)
{
$this->agent->removeElement($agent);
}
/**
* Get agent.
*
* @return \Aviatur\AgentBundle\Entity\Agent
*/
public function getAgent()
{
return $this->agent;
}
/**
* Set agent.
*
* @param \Aviatur\AgentBundle\Entity\Agent $agent
*
* @return Customer
*/
public function setAgent(\Aviatur\AgentBundle\Entity\Agent $agent = null)
{
$this->agent = $agent;
return $this;
}
/**
* @ORM\PrePersist
*/
public function validatePersist(\Doctrine\ORM\Event\LifecycleEventArgs $args)
{
$customerValidator = new CustomerValidator($this);
switch (true) {
case!$customerValidator->validateDocumenttype():
case!$customerValidator->validateDocumentnumber():
case!$customerValidator->validateFirstname():
case!$customerValidator->validateLastname():
case!$customerValidator->validateCivilstatus():
case!$customerValidator->validateAddress():
case!$customerValidator->validatePhone():
case!$customerValidator->validateEmail():
throw new ValidateException($customerValidator->getMessage());
default:
true;
}
return true;
}
/**
* @ORM\PreUpdate
*/
public function validateUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $args)
{
if (1 === count($args->getEntityChangeSet()) && 'lastLogin' === key($args->getEntityChangeSet())) {
return true;
}
$customerValidator = new CustomerValidator($this);
switch (true) {
case!$customerValidator->validateDocumenttype():
case!$customerValidator->validateDocumentnumber():
case!$customerValidator->validateFirstname():
case!$customerValidator->validateLastname():
case!$customerValidator->validateBirthdate():
case!$customerValidator->validateCivilstatus():
case!$customerValidator->validateAddress():
case!$customerValidator->validatePhone():
case!$customerValidator->validateEmail():
throw new ValidateException($customerValidator->getMessage());
default:
true;
}
return true;
}
public function completeCity($em)
{
$dataCity = $em->getRepository(\Aviatur\GeneralBundle\Entity\City::class)->findOneBy(['id' => '2164']);
$dataCountry = $em->getRepository(\Aviatur\GeneralBundle\Entity\Country::class)->findOneBy(['id' => '165']);
$this->setCity($dataCity);
$this->setCountry($dataCountry);
return true;
}
}