src/AppBundle/Entity/Customer.php line 23

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Entity;
  3. use AppBundle\Entity\Traits\TimestampableTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JMS\Serializer\Annotation\Type;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\EquatableInterface;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * Customer.
  14.  *
  15.  * @ORM\Table(name="customer")
  16.  * @ORM\HasLifecycleCallbacks
  17.  * @ORM\Entity(repositoryClass="AppBundle\Repository\CustomerRepository")
  18.  */
  19. #[UniqueEntity(fields'email'message'customer.email.unique')]
  20. class Customer implements UserInterfacePasswordAuthenticatedUserInterfaceEquatableInterface
  21. {
  22.     use TimestampableTrait;
  23.     /**
  24.      * @var int
  25.      *
  26.      * @ORM\Column(name="id", type="integer")
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity="Address", mappedBy="customer", fetch="LAZY")
  33.      * @ORM\OrderBy({"company" = "ASC", "name" = "ASC"})
  34.      */
  35.     private $addresses;
  36.     /**
  37.      * @ORM\OneToMany(targetEntity="Booking", mappedBy="customer", fetch="LAZY")
  38.      */
  39.     private $bookings;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="email", type="string", length=255, unique=true)
  44.      */
  45.     #[Assert\NotBlank(message'customer.email.not_blank')]
  46.     #[Assert\Email(message'customer.email.valid')]
  47.     private $email;
  48.     /**
  49.      * If the customer wants to change his email, he has to validate it.
  50.      *
  51.      * @var string
  52.      *
  53.      * @ORM\Column(name="change_email", type="string", length=255, nullable=true)
  54.      */
  55.     private $changeEmail;
  56.     /**
  57.      * @var string
  58.      *
  59.      * @ORM\Column(name="change_email_token", type="string", length=255, nullable=true)
  60.      */
  61.     private $changeEmailToken;
  62.     /**
  63.      * @var string
  64.      *
  65.      * @ORM\Column(name="password", type="string", length=255)
  66.      */
  67.     private $password;
  68.     /**
  69.      * @var string
  70.      * @Type("string")
  71.      */
  72.     private $plainPassword;
  73.     /**
  74.      * @var string
  75.      *
  76.      * @ORM\Column(name="name", type="string", length=255, nullable=true)
  77.      */
  78.     private $name;
  79.     /**
  80.      * @var string
  81.      *
  82.      * @ORM\Column(name="company", type="string", length=255, nullable=true)
  83.      */
  84.     private $company;
  85.     /**
  86.      * @var string
  87.      *
  88.      * @ORM\Column(name="street", type="string", length=255)
  89.      */
  90.     #[Assert\NotBlank(message'customer.street.not_blank')]
  91.     private $street;
  92.     /**
  93.      * @var string
  94.      *
  95.      * @ORM\Column(name="zip", type="string", length=255)
  96.      */
  97.     #[Assert\NotBlank(message'customer.zip.not_blank')]
  98.     private $zip;
  99.     /**
  100.      * @var string
  101.      *
  102.      * @ORM\Column(name="city", type="string", length=255)
  103.      */
  104.     #[Assert\NotBlank(message'customer.city.not_blank')]
  105.     private $city;
  106.     /**
  107.      * @var string
  108.      *
  109.      * @ORM\Column(name="country", type="string", length=255)
  110.      */
  111.     #[Assert\NotBlank(message'customer.country.not_blank')]
  112.     private $country 'Deutschland';
  113.     /**
  114.      * @var string
  115.      *
  116.      * @ORM\Column(name="contact_person", type="text", nullable=true)
  117.      */
  118.     private $contactPerson;
  119.     /**
  120.      * @var string
  121.      *
  122.      * @ORM\Column(name="fon", type="string", length=255, nullable=true)
  123.      */
  124.     private $fon;
  125.     /**
  126.      * @var string
  127.      *
  128.      * @ORM\Column(name="fax", type="string", length=255, nullable=true)
  129.      */
  130.     private $fax;
  131.     /**
  132.      * @var bool
  133.      *
  134.      * @ORM\Column(name="active", type="boolean")
  135.      */
  136.     private $active;
  137.     /**
  138.      * @var bool
  139.      *
  140.      * @ORM\Column(name="confirmed", type="boolean")
  141.      */
  142.     private $confirmed;
  143.     /**
  144.      * @var string
  145.      *
  146.      * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
  147.      */
  148.     private $confirmationToken;
  149.     /**
  150.      * @var string
  151.      *
  152.      * @ORM\Column(name="password_reset_token", type="string", length=255, nullable=true)
  153.      */
  154.     private $passwordResetToken;
  155.     /**
  156.      * @var string
  157.      *
  158.      * @ORM\Column(name="password_reset_token_valid_date", type="datetime", nullable=true)
  159.      */
  160.     private $passwordResetTokenValidDate;
  161.     /**
  162.      * @var \DateTime
  163.      *
  164.      * @ORM\Column(name="last_login", type="datetime", nullable=true)
  165.      */
  166.     private $lastLogin;
  167.     /**
  168.      * @var string
  169.      *
  170.      * @ORM\Column(name="roles", type="string", length=255, nullable=true)
  171.      */
  172.     private $roles;
  173.     /**
  174.      * Constructor.
  175.      */
  176.     public function __construct()
  177.     {
  178.         $this->addresses = new \Doctrine\Common\Collections\ArrayCollection();
  179.         $this->bookings = new ArrayCollection();
  180.     }
  181.     /***********************************************************************************************************************************************
  182.                SPECIAL IMPLEMENTATIONS
  183.        ************************************************************************************************************************************************/
  184.     /**
  185.      * Implement the AdvancedUserInterface.
  186.      */
  187.     public function getUserIdentifier()
  188.     {
  189.         return $this->email;
  190.     }
  191.     public function getUsername()
  192.     {
  193.         return $this->getUserIdentifier();
  194.     }
  195.     public function getSalt()
  196.     {
  197.         return null;
  198.     }
  199.     // public function getPassword(){return $this->password;} // -> already implemented
  200.     public function getRoles()
  201.     {
  202.         $roles = ['ROLE_USER'];
  203.         if ($this->roles) {
  204.             $roles explode(','str_replace(' '''$this->roles));
  205.         }
  206.         return $roles;
  207.     }
  208.     public function eraseCredentials()
  209.     {
  210.     }
  211.     public function isAccountNonExpired()
  212.     {
  213.         return $this->confirmed;
  214.     }
  215.     public function isAccountNonLocked()
  216.     {
  217.         return true;
  218.     }
  219.     public function isCredentialsNonExpired()
  220.     {
  221.         return true;
  222.     }
  223.     public function isEnabled()
  224.     {
  225.         return $this->active;
  226.     }
  227.     /**
  228.      * Implement the \Serializable Interface.
  229.      */
  230.     public function __serialize()
  231.     {
  232.         return [
  233.             $this->id,
  234.             $this->active,
  235.             $this->confirmed,
  236.             $this->password,
  237.         ];
  238.     }
  239.     public function __unserialize(array $serialized)
  240.     {
  241.         [
  242.             $this->id,
  243.             $this->active,
  244.             $this->confirmed,
  245.             $this->password
  246.         ] = $serialized;
  247.     }
  248.     public function isEqualTo(UserInterface $customer)
  249.     {
  250.         return true;
  251.     }
  252.     /**
  253.      * Set password.
  254.      *
  255.      * @param string $password
  256.      *
  257.      * @return Customer
  258.      */
  259.     public function setPassword($password)
  260.     {
  261.         $this->password $password;
  262.         return $this;
  263.     }
  264.     /**
  265.      * Get password.
  266.      *
  267.      * @return string
  268.      */
  269.     public function getPassword(): ?string
  270.     {
  271.         return $this->password;
  272.     }
  273.     /**
  274.      * Set plainPassword.
  275.      *
  276.      * @param string $plainPassword
  277.      *
  278.      * @return Customer
  279.      */
  280.     public function setPlainPassword($plainPassword)
  281.     {
  282.         $this->plainPassword $plainPassword;
  283.         return $this;
  284.     }
  285.     /**
  286.      * Get plainPassword.
  287.      *
  288.      * @return string
  289.      */
  290.     public function getPlainPassword()
  291.     {
  292.         return $this->plainPassword;
  293.     }
  294.     /***********************************************************************************************************************************************
  295.                GENERIC GETTERS AND SETTERS
  296.        ************************************************************************************************************************************************/
  297.     /**
  298.      * Get id.
  299.      *
  300.      * @return int
  301.      */
  302.     public function getId()
  303.     {
  304.         return $this->id;
  305.     }
  306.     /**
  307.      * Set email.
  308.      *
  309.      * @param string $email
  310.      *
  311.      * @return Customer
  312.      */
  313.     public function setEmail($email)
  314.     {
  315.         $this->email $email;
  316.         return $this;
  317.     }
  318.     /**
  319.      * Get email.
  320.      *
  321.      * @return string
  322.      */
  323.     public function getEmail()
  324.     {
  325.         return $this->email;
  326.     }
  327.     /**
  328.      * Set changeEmail.
  329.      *
  330.      * @param string $changeEmail
  331.      *
  332.      * @return Customer
  333.      */
  334.     public function setChangeEmail($changeEmail)
  335.     {
  336.         $this->changeEmail $changeEmail;
  337.         return $this;
  338.     }
  339.     /**
  340.      * Get changeEmail.
  341.      *
  342.      * @return string
  343.      */
  344.     public function getChangeEmail()
  345.     {
  346.         return $this->changeEmail;
  347.     }
  348.     /**
  349.      * Set changeEmailToken.
  350.      *
  351.      * @param string $changeEmailToken
  352.      *
  353.      * @return Customer
  354.      */
  355.     public function setChangeEmailToken($changeEmailToken)
  356.     {
  357.         $this->changeEmailToken $changeEmailToken;
  358.         return $this;
  359.     }
  360.     /**
  361.      * Get changeEmailToken.
  362.      *
  363.      * @return string
  364.      */
  365.     public function getChangeEmailToken()
  366.     {
  367.         return $this->changeEmailToken;
  368.     }
  369.     /**
  370.      * Set name.
  371.      *
  372.      * @param string $name
  373.      *
  374.      * @return Customer
  375.      */
  376.     public function setName($name)
  377.     {
  378.         $this->name $name;
  379.         return $this;
  380.     }
  381.     /**
  382.      * Get name.
  383.      *
  384.      * @return string
  385.      */
  386.     public function getName()
  387.     {
  388.         return $this->name;
  389.     }
  390.     /**
  391.      * Set company.
  392.      *
  393.      * @param string $company
  394.      *
  395.      * @return Customer
  396.      */
  397.     public function setCompany($company)
  398.     {
  399.         $this->company $company;
  400.         return $this;
  401.     }
  402.     /**
  403.      * Get company.
  404.      *
  405.      * @return string
  406.      */
  407.     public function getCompany()
  408.     {
  409.         return $this->company;
  410.     }
  411.     /**
  412.      * Set street.
  413.      *
  414.      * @param string $street
  415.      *
  416.      * @return Customer
  417.      */
  418.     public function setStreet($street)
  419.     {
  420.         $this->street $street;
  421.         return $this;
  422.     }
  423.     /**
  424.      * Get street.
  425.      *
  426.      * @return string
  427.      */
  428.     public function getStreet()
  429.     {
  430.         return $this->street;
  431.     }
  432.     /**
  433.      * Set zip.
  434.      *
  435.      * @param string $zip
  436.      *
  437.      * @return Customer
  438.      */
  439.     public function setZip($zip)
  440.     {
  441.         $this->zip $zip;
  442.         return $this;
  443.     }
  444.     /**
  445.      * Get zip.
  446.      *
  447.      * @return string
  448.      */
  449.     public function getZip()
  450.     {
  451.         return $this->zip;
  452.     }
  453.     /**
  454.      * Set city.
  455.      *
  456.      * @param string $city
  457.      *
  458.      * @return Customer
  459.      */
  460.     public function setCity($city)
  461.     {
  462.         $this->city $city;
  463.         return $this;
  464.     }
  465.     /**
  466.      * Get city.
  467.      *
  468.      * @return string
  469.      */
  470.     public function getCity()
  471.     {
  472.         return $this->city;
  473.     }
  474.     /**
  475.      * Set country.
  476.      *
  477.      * @param string $country
  478.      *
  479.      * @return Customer
  480.      */
  481.     public function setCountry($country)
  482.     {
  483.         $this->country $country;
  484.         return $this;
  485.     }
  486.     /**
  487.      * Get country.
  488.      *
  489.      * @return string
  490.      */
  491.     public function getCountry()
  492.     {
  493.         return $this->country;
  494.     }
  495.     /**
  496.      * Set contactPerson.
  497.      *
  498.      * @param string $contactPerson
  499.      *
  500.      * @return Customer
  501.      */
  502.     public function setContactPerson($contactPerson)
  503.     {
  504.         $this->contactPerson $contactPerson;
  505.         return $this;
  506.     }
  507.     /**
  508.      * Get contactPerson.
  509.      *
  510.      * @return string
  511.      */
  512.     public function getContactPerson()
  513.     {
  514.         return $this->contactPerson;
  515.     }
  516.     /**
  517.      * Set fon.
  518.      *
  519.      * @param string $fon
  520.      *
  521.      * @return Customer
  522.      */
  523.     public function setFon($fon)
  524.     {
  525.         $this->fon $fon;
  526.         return $this;
  527.     }
  528.     /**
  529.      * Get fon.
  530.      *
  531.      * @return string
  532.      */
  533.     public function getFon()
  534.     {
  535.         return $this->fon;
  536.     }
  537.     /**
  538.      * Set fax.
  539.      *
  540.      * @param string $fax
  541.      *
  542.      * @return Customer
  543.      */
  544.     public function setFax($fax)
  545.     {
  546.         $this->fax $fax;
  547.         return $this;
  548.     }
  549.     /**
  550.      * Get fax.
  551.      *
  552.      * @return string
  553.      */
  554.     public function getFax()
  555.     {
  556.         return $this->fax;
  557.     }
  558.     /**
  559.      * Set active.
  560.      *
  561.      * @param bool $active
  562.      *
  563.      * @return Customer
  564.      */
  565.     public function setActive($active)
  566.     {
  567.         $this->active $active;
  568.         return $this;
  569.     }
  570.     /**
  571.      * Get active.
  572.      *
  573.      * @return bool
  574.      */
  575.     public function getActive()
  576.     {
  577.         return $this->active;
  578.     }
  579.     /**
  580.      * Set confirmed.
  581.      *
  582.      * @param bool $confirmed
  583.      *
  584.      * @return Customer
  585.      */
  586.     public function setConfirmed($confirmed)
  587.     {
  588.         $this->confirmed $confirmed;
  589.         return $this;
  590.     }
  591.     /**
  592.      * Get confirmed.
  593.      *
  594.      * @return bool
  595.      */
  596.     public function getConfirmed()
  597.     {
  598.         return $this->confirmed;
  599.     }
  600.     /**
  601.      * Set confirmationToken.
  602.      *
  603.      * @param string $confirmationToken
  604.      *
  605.      * @return Customer
  606.      */
  607.     public function setConfirmationToken($confirmationToken)
  608.     {
  609.         $this->confirmationToken $confirmationToken;
  610.         return $this;
  611.     }
  612.     /**
  613.      * Get confirmationToken.
  614.      *
  615.      * @return string
  616.      */
  617.     public function getConfirmationToken()
  618.     {
  619.         return $this->confirmationToken;
  620.     }
  621.     /**
  622.      * Set passwordResetToken.
  623.      *
  624.      * @param string $passwordResetToken
  625.      *
  626.      * @return Customer
  627.      */
  628.     public function setPasswordResetToken($passwordResetToken)
  629.     {
  630.         $this->passwordResetToken $passwordResetToken;
  631.         return $this;
  632.     }
  633.     /**
  634.      * Get passwordResetToken.
  635.      *
  636.      * @return string
  637.      */
  638.     public function getPasswordResetToken()
  639.     {
  640.         return $this->passwordResetToken;
  641.     }
  642.     /**
  643.      * Set passwordResetTokenValidDate.
  644.      *
  645.      * @param \DateTime $passwordResetTokenValidDate
  646.      *
  647.      * @return Customer
  648.      */
  649.     public function setPasswordResetTokenValidDate($passwordResetTokenValidDate)
  650.     {
  651.         $this->passwordResetTokenValidDate $passwordResetTokenValidDate;
  652.         return $this;
  653.     }
  654.     /**
  655.      * Get passwordResetTokenValidDate.
  656.      *
  657.      * @return \DateTime
  658.      */
  659.     public function getPasswordResetTokenValidDate()
  660.     {
  661.         return $this->passwordResetTokenValidDate;
  662.     }
  663.     /**
  664.      * Set lastLogin.
  665.      *
  666.      * @param \DateTime $lastLogin
  667.      *
  668.      * @return Customer
  669.      */
  670.     public function setLastLogin($lastLogin)
  671.     {
  672.         $this->lastLogin $lastLogin;
  673.         return $this;
  674.     }
  675.     /**
  676.      * Get lastLogin.
  677.      *
  678.      * @return \DateTime
  679.      */
  680.     public function getLastLogin()
  681.     {
  682.         return $this->lastLogin;
  683.     }
  684.     /**
  685.      * Add address.
  686.      *
  687.      * @param \AppBundle\Entity\Address $address
  688.      *
  689.      * @return Customer
  690.      */
  691.     public function addAddress(Address $address)
  692.     {
  693.         $this->addresses[] = $address;
  694.         return $this;
  695.     }
  696.     /**
  697.      * Remove address.
  698.      *
  699.      * @param \AppBundle\Entity\Address $address
  700.      */
  701.     public function removeAddress(Address $address)
  702.     {
  703.         $this->addresses->removeElement($address);
  704.     }
  705.     /**
  706.      * Get addresses.
  707.      *
  708.      * @return \Doctrine\Common\Collections\Collection
  709.      */
  710.     public function getAddresses()
  711.     {
  712.         return $this->addresses;
  713.     }
  714.     /**
  715.      * Add booking.
  716.      *
  717.      * @param \AppBundle\Entity\Booking $booking
  718.      *
  719.      * @return Customer
  720.      */
  721.     public function addBooking(Booking $booking)
  722.     {
  723.         $this->bookings[] = $booking;
  724.         return $this;
  725.     }
  726.     /**
  727.      * Remove booking.
  728.      *
  729.      * @param \AppBundle\Entity\Booking $booking
  730.      */
  731.     public function removeBooking(Booking $booking)
  732.     {
  733.         $this->bookings->removeElement($booking);
  734.     }
  735.     /**
  736.      * Get bookings.
  737.      *
  738.      * @return \Doctrine\Common\Collections\Collection
  739.      */
  740.     public function getBookings()
  741.     {
  742.         return $this->bookings;
  743.     }
  744.     /**
  745.      * Set roles.
  746.      *
  747.      * @param string|null $roles
  748.      *
  749.      * @return Customer
  750.      */
  751.     public function setRoles($roles null)
  752.     {
  753.         $this->roles $roles;
  754.         return $this;
  755.     }
  756. }