src/Entity/Customer/Customer.php line 35
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\Entity\Customer;use App\Entity\Device\Device;use App\Entity\Geographical\Address;use App\Entity\Order\Order;use App\Entity\User\AppUser;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Monofony\Contracts\Core\Model\Customer\CustomerInterface;use Monofony\Contracts\Core\Model\User\AppUserInterface;use Sylius\Component\Customer\Model\Customer as BaseCustomer;use Sylius\Component\User\Model\UserInterface;use Symfony\Component\Validator\Constraints\Length;use Symfony\Component\Validator\Constraints\NotBlank;use Symfony\Component\Validator\Constraints\PositiveOrZero;use Symfony\Component\Validator\Constraints\Valid;use Webmozart\Assert\Assert;#[ORM\Entity]#[ORM\Table(name: 'sylius_customer')]class Customer extends BaseCustomer implements CustomerInterface{#[ORM\OneToOne(mappedBy: 'customer', targetEntity: AppUser::class, cascade: ['persist'])]#[Valid]private ?UserInterface $user = null;#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Address::class, cascade: ['persist'], orphanRemoval: true)]#[Valid]private Collection $addresses;#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Order::class, orphanRemoval: true)]private Collection $orders;#[ORM\Column(type: 'integer')]#[NotBlank(groups: ['sylius']), PositiveOrZero(groups: ['sylius'])]private ?int $credits = 0;#[ORM\Column(type: 'string', nullable: true)]private ?string $street = null;#[ORM\Column(type: 'string', nullable: true)]private ?string $street2 = null;#[ORM\Column(type: 'string', nullable: true)]private ?string $city = null;#[ORM\Column(type: 'string', nullable: true)]private ?string $state = null;#[ORM\Column(type: 'string', length: 20, nullable: true)]private ?string $postcode = null;#[ORM\Column(type: 'string', length: 100, nullable: true)]private ?string $country = null;#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Device::class)]private Collection $devices;public function __construct(){$this->addresses = new ArrayCollection();$this->orders = new ArrayCollection();$this->devices = new ArrayCollection();parent::__construct();}public function getUser(): ?UserInterface{return $this->user;}public function setUser(?UserInterface $user): void{if ($this->user === $user) {return;}Assert::nullOrIsInstanceOf($user, AppUserInterface::class);$previousUser = $this->user;$this->user = $user;if ($previousUser instanceof AppUserInterface) {$previousUser->setCustomer(null);}if ($user instanceof AppUserInterface) {$user->setCustomer($this);}}public function setEnabled(?bool $enabled): void{if (null !== $this->user) {$this->user->setEnabled($enabled);}}public function getAddresses(): ?Collection{return $this->addresses;}public function hasAddress(Address $address): bool{return $this->addresses->contains($address);}public function addAddress(Address $address): void{if (!$this->hasAddress($address)) {$this->addresses->add($address);$address->setCustomer($this);}}public function removeAddress(Address $address): void{$this->addresses->removeElement($address);$address->setCustomer(null);}public function getOrders(): ?Collection{return $this->orders;}public function hasOrder(Order $order): bool{return $this->orders->contains($order);}public function addOrder(Order $order): void{if (!$this->hasOrder($order)) {$this->orders->add($order);$order->setCustomer($this);}}public function removeOrder(Order $order): void{$this->orders->removeElement($order);$order->setCustomer(null);}/*** Get the value of credits.** @return ?int*/public function getCredits(): ?int{return $this->credits;}/*** Set the value of credits.*/public function setCredits(?int $credits): self{$this->credits = $credits;return $this;}/*** Get the value of street.** @return ?string*/public function getStreet(): ?string{return $this->street;}/*** Set the value of street.*/public function setStreet(?string $street): self{$this->street = $street;return $this;}/*** Get the value of street2.** @return ?string*/public function getStreet2(): ?string{return $this->street2;}/*** Set the value of street2.*/public function setStreet2(?string $street2): self{$this->street2 = $street2;return $this;}/*** Get the value of city.** @return ?string*/public function getCity(): ?string{return $this->city;}/*** Set the value of city.*/public function setCity(?string $city): self{$this->city = $city;return $this;}/*** Get the value of postcode.** @return ?string*/public function getPostcode(): ?string{return $this->postcode;}/*** Set the value of postcode.*/public function setPostcode(?string $postcode): self{$this->postcode = $postcode;return $this;}/*** @return string|null*/public function getState(): ?string{return $this->state;}/*** @param string|null $state*/public function setState(?string $state): void{$this->state = $state;}/*** Get the value of country.** @return ?string*/public function getCountry(): ?string{return $this->country;}/*** Set the value of country.*/public function setCountry(?string $country): self{$this->country = $country;return $this;}public function getDevices(): Collection{return $this->devices;}public function hasDevice(Device $device): bool{return $this->devices->contains($device);}public function addDevice(Device $device): void{if (!$this->hasDevice($device)) {$this->devices->add($device);}}public function removeDevice(Device $device): void{$this->devices->removeElement($device);}public function removeDeviceWithToken(string $token): void{$device = $this->devices->filter(function (Device $device) use ($token) {return $device->getToken() === $token;})->first();if ($device) {$this->devices->removeElement($device);}}public function getBillingAddress(): ?string{return sprintf('%s %s %s %s %s %s',$this->getFullName(),$this->getStreet(),$this->getStreet2(),$this->getPostcode(),$this->getCity(),$this->getCountry(),);}}