src/Entity/Customer.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=CustomerRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  */
  15. class Customer  implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $firstname;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $lastname;
  31.     /**
  32.      * @ORM\Column(type="string", length=255,nullable=true)
  33.      */
  34.     private $city;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $email;
  39.     /**
  40.      * @ORM\Column(type="string", length=255,nullable=true)
  41.      */
  42.     private $gender;
  43.     /**
  44.      * @ORM\Column(type="string", length=255,nullable=true)
  45.      */
  46.     private $mobile;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $password;
  51.     /**
  52.      * @ORM\Column(type="boolean",nullable=true)
  53.      */
  54.     private $active;
  55.     /**
  56.      * @ORM\Column(type="datetime", nullable=true)
  57.      */
  58.     private $createdAt;
  59.     private $roles;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="customer")
  62.      */
  63.     private $transactions;
  64.     /**
  65.      * @ORM\Column(type="string", length=255)
  66.      */
  67.     private $customer_number;
  68.     public function __construct()
  69.     {
  70.         $this->transactions = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getFirstname(): ?string
  77.     {
  78.         return $this->firstname;
  79.     }
  80.     public function setFirstname(string $firstname): self
  81.     {
  82.         $this->firstname $firstname;
  83.         return $this;
  84.     }
  85.     public function getLastname(): ?string
  86.     {
  87.         return $this->lastname;
  88.     }
  89.     public function setLastname(string $lastname): self
  90.     {
  91.         $this->lastname $lastname;
  92.         return $this;
  93.     }
  94.     public function getCity(): ?string
  95.     {
  96.         return $this->city;
  97.     }
  98.     public function setCity(string $city): self
  99.     {
  100.         $this->city $city;
  101.         return $this;
  102.     }
  103.     public function getEmail(): ?string
  104.     {
  105.         return $this->email;
  106.     }
  107.     public function setEmail(string $email): self
  108.     {
  109.         $this->email $email;
  110.         return $this;
  111.     }
  112.     public function getGender(): ?string
  113.     {
  114.         return $this->gender;
  115.     }
  116.     public function setGender(string $gender): self
  117.     {
  118.         $this->gender $gender;
  119.         return $this;
  120.     }
  121.     public function getMobile(): ?string
  122.     {
  123.         return $this->mobile;
  124.     }
  125.     public function setMobile(string $mobile): self
  126.     {
  127.         $this->mobile $mobile;
  128.         return $this;
  129.     }
  130.     public function getPassword(): ?string
  131.     {
  132.         return $this->password;
  133.     }
  134.     public function setPassword(string $password): self
  135.     {
  136.         $this->password $password;
  137.         return $this;
  138.     }
  139.     public function getActive(): ?bool
  140.     {
  141.         return $this->active;
  142.     }
  143.     public function setActive(bool $active): self
  144.     {
  145.         $this->active $active;
  146.         return $this;
  147.     }
  148.     public function getRoles(): array
  149.     {
  150.         $roles $this->roles;
  151.         // guarantee every user at least has ROLE_USER
  152.         $roles[] = 'ROLE_CUSTOMER';
  153.         return array_unique($roles);
  154.     }
  155.     /**
  156.      * Returning a salt is only needed, if you are not using a modern
  157.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  158.      *
  159.      * @see UserInterface
  160.      */
  161.     public function getSalt(): ?string
  162.     {
  163.         return null;
  164.     }
  165.     /**
  166.      * @see UserInterface
  167.      */
  168.     public function eraseCredentials()
  169.     {
  170.         // If you store any temporary, sensitive data on the user, clear it here
  171.         // $this->plainPassword = null;
  172.     }
  173.     /**
  174.      * A visual identifier that represents this user.
  175.      *
  176.      * @see UserInterface
  177.      */
  178.     public function getUserIdentifier(): string
  179.     {
  180.         return (string) $this->email;
  181.     }
  182.     /**
  183.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  184.      */
  185.     public function getUsername(): string
  186.     {
  187.         return (string) $this->email;
  188.     }
  189.     public function getCreatedAt(): ?\DateTimeInterface
  190.     {
  191.         return $this->createdAt;
  192.     }
  193.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  194.     {
  195.         $this->createdAt $createdAt;
  196.         if (!$this->createdAt) {
  197.             $this->createdAt = new \DateTime();
  198.         }
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Collection|Transaction[]
  203.      */
  204.     public function getTransactions(): Collection
  205.     {
  206.         return $this->transactions;
  207.     }
  208.     public function addTransaction(Transaction $transaction): self
  209.     {
  210.         if (!$this->transactions->contains($transaction)) {
  211.             $this->transactions[] = $transaction;
  212.             $transaction->setCustomer($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function removeTransaction(Transaction $transaction): self
  217.     {
  218.         if ($this->transactions->removeElement($transaction)) {
  219.             // set the owning side to null (unless already changed)
  220.             if ($transaction->getCustomer() === $this) {
  221.                 $transaction->setCustomer(null);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226.     public function getCustomerNumber(): ?string
  227.     {
  228.         return $this->customer_number;
  229.     }
  230.     public function setCustomerNumber(string $customer_number): self
  231.     {
  232.         $this->customer_number $customer_number;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection|Business[]
  237.      */
  238.     public function getBusinesses(): Collection
  239.     {
  240.         $business = new ArrayCollection();
  241.         foreach ($this->transactions as $transaction) {
  242.             if (!$business->contains($transaction->getBusiness())) {
  243.                 $business[] = $transaction->getBusiness();
  244.             }
  245.         }
  246.         return $business;
  247.     }
  248.     public function __toString()
  249.     {
  250.         return $this->email;
  251.     }
  252. }