<?php
namespace App\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
* @Vich\Uploadable
*/
class Customer implements UserInterface
{
/**
* Roles customer
*/
const ROLE_CUSTOMER = "ROLE_CUSTOMER";
const ROLE_ADMIN_CLUB = "ROLE_ADMIN_CLUB";
const ROLE_CUSTOMER_DEPENDENT = "ROLE_CUSTOMER_DEPENDENT";
/** */
const TYPE_ACCOUNT_APP = "APP";
const TYPE_ACCOUNT_FACEBOOK = "FACEBOOK";
const TYPE_ACCOUNT_GOOGLE = "GOOGLE";
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=20, unique=true)
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $plainPassword;
/**
* @ORM\Column(type="boolean")
*/
private $enabled;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @ORM\Column(type="string",nullable=true)
*/
private $surname;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $celular;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
private $image;
/**
* @Vich\UploadableField(mapping="customer_images", fileNameProperty="image")
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Season", mappedBy="customer", cascade={"remove"})
*/
private $season;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Country", inversedBy="customers")
*/
private $country;
/**
*
* @ORM\Column(name="country_id", type="integer", nullable=true)
*/
public $countryId;
/**
* @ORM\Column(type="integer", nullable=true)
*/
public $seasonActive;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Suggestion", mappedBy="customer", orphanRemoval=true)
*/
private $suggestions;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $typeAccount;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isPro;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $purchase;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $purchasePlatform;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $membershipId;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CouponCustomer", mappedBy="customer", orphanRemoval=true)
* @ORM\OrderBy({"id" = "ASC"})
*/
private $customerCoupons;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $couponStatus;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=16, nullable=true)
*/
private $googleAuthCode;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $googleAuthCodeVerified;
/**
* @ORM\Column(type="datetime", length=255,nullable=true)
* @var \DateTime
*/
private $dateOfBirth;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Notification", mappedBy="customers")
* @ORM\JoinColumn(nullable=false)
*/
private $notifications;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $deletedAt;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $isDeleted;
/**
* @ORM\OneToMany(targetEntity=ExerciseQualification::class, mappedBy="customer_id")
*/
private $exerciseQualifications;
/**
* @ORM\OneToMany(targetEntity=Strategy::class, mappedBy="customer", orphanRemoval=true)
*/
private $strategies;
/**
* Customer constructor.
*/
public function __construct()
{
$this->enabled = true;
$this->roles = array();
$this->season = new ArrayCollection();
$this->suggestions = new ArrayCollection();
$this->customerCoupons = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->exerciseQualifications = new ArrayCollection();
$this->strategies = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
if (empty($this->email)) {
return $this->username;
}
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getUsername(): ?string
{
if (empty($this->username)) {
return $this->email;
}
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
//$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole($role)
{
$role = strtoupper($role);
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string)$this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
$this->plainPassword = null;
}
/**
* @return mixed
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param mixed $enabled
* @return Customer
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
return $this;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
* @return Customer
*/
public function setName(string $name)
{
$this->name = $name;
return $this;
}
/**
* @return mixed
*/
public function getSurname()
{
return $this->surname;
}
/**
* @param mixed $surname
* @return Customer
*/
public function setSurname($surname)
{
$this->surname = $surname;
return $this;
}
/**
* @return mixed
*/
public function getAddress()
{
return $this->address;
}
/**
* @param mixed $address
* @return Customer
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* @return mixed
*/
public function getCelular()
{
return $this->celular;
}
/**
* @param mixed $celular
* @return Customer
*/
public function setCelular($celular)
{
$this->celular = $celular;
return $this;
}
/**
* @param File|null $image
* @return Customer
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param $image
* @return Customer
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @return string
*/
public function getNameTeam()
{
$name = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$name = $s->getTeam()->getName();
return $name;
}
/**
* @return ?string
*/
public function getStadiumName()
{
$name = null;
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$name = $s->getTeam()->getStadiumName();
return $name;
}
public function getMonthlyCostTeam()
{
$name = null;
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$name = $s->getTeam()->getMonthlyCost();
return $name;
}
public function getKitPaymentCostTeam()
{
$name = null;
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$name = $s->getTeam()->getKitPaymentCost();
return $name;
}
public function getOtherPaymentCostTeam()
{
$name = null;
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$name = $s->getTeam()->getOtherPaymentCost();
return $name;
}
public function setNameTeam($name)
{
$this->nameTeam = $name;
return $this;
}
public function setCategoryTeam($name)
{
$this->categoryTeam = $name;
return $this;
}
/**
* @return string
*/
public function getCategoryTeam()
{
$category = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$category = $s->getTeam()->getCategory();
return $category;
}
/**
* @return string
*/
public function getTypeSoccerTeamId()
{
$typeSoccerTeamId = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam())) {
$typeSoccerTeamId = $s->getTeam()->getTypeSoccer();
if ($typeSoccerTeamId) {
$typeSoccerTeamId = $typeSoccerTeamId->getId();
}
}
return $this->typeSoccerTeamId = $typeSoccerTeamId;
}
/**
* @return string
*/
public function getTypeSoccerTeamName()
{
$typeSoccerTeamName = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam())) {
$typeSoccerTeamName = $s->getTeam()->getTypeSoccer();
if ($typeSoccerTeamName) {
$typeSoccerTeamName = $typeSoccerTeamName->getName();
}
}
return $this->typeSoccerTeamName = $typeSoccerTeamName;
}
public function setTypeSoccerTeamId(int $typeId)
{
$this->typeSoccerTeamId = $typeId;
return $this;
}
public function getTypeSoccer()
{
$typeSoccerName = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$typeSoccerName = $s->getTeam()->getTypeSoccer();
return $typeSoccerName;
}
/**
* @return Tactic
*/
public function getAlignmentDefaultU7()
{
$typeSoccerName = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam())) {
$aligment = $s->getTeam()->getAlignmentDefaultU7();
return $aligment;
}
return $typeSoccerName;
}
/**
* @return Tactic
*/
public function getAlignmentDefaultU8()
{
$typeSoccerName = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam())) {
return $s->getTeam()->getAlignmentDefaultU8();
}
return $typeSoccerName;
}
/**
* @return Tactic
*/
public function getAlignmentDefaultU11()
{
$typeSoccerName = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam())) {
return $s->getTeam()->getAlignmentDefaultU11();
}
return $typeSoccerName;
}
/**
* @return string
*/
public function getImageTeam()
{
$img = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$img = $s->getTeam()->getImage();
return $img;
}
public function getImageTrainerTeam()
{
$img = "";
/** @var Season $s */
$s = $this->getSeasonActive();
if ($s && !empty($s->getTeam()))
$img = $s->getTeam()->getImageTrainer();
return $img;
}
public function getNumberClubesLeague()
{
$numberClubesLeague = 0;
/** @var Season $s */
$season = $this->getSeasonActive();
if ($season && !empty($season->getTeam()))
$numberClubesLeague = $season->getTeam()->getNumberClubesLeague();
return $numberClubesLeague;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
* @return Customer
*/
public function setUpdatedAt(\DateTime $updatedAt): Customer
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
* @return Customer
*/
public function setCreatedAt(\DateTime $createdAt): Customer
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|Season[]
*/
public function getSeason(): Collection
{
return $this->season;
}
public function addSeason(Season $season): self
{
if (!$this->season->contains($season)) {
$this->season[] = $season;
$season->setCustomer($this);
}
return $this;
}
public function removeSeason(Season $season): self
{
if ($this->season->contains($season)) {
$this->season->removeElement($season);
// set the owning side to null (unless already changed)
if ($season->getCustomer() === $this) {
$season->setCustomer(null);
}
}
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getCountryId(): ?int
{
return $this->countryId;
}
public function getSeasonYear(): ?int
{
$s = $this->getSeasonActive();
return $s ? $s->getYear() : null;
}
public function setSeasonYear($name)
{
$this->yearSeason = $name;
return $this;
}
public function setCountryId(?int $countryId): self
{
$this->countryId = $countryId;
return $this;
}
/**
* @return Season
*/
public function getSeasonActive()
{
if (!empty($this->seasonActive)) {
/** @var Season $season */
foreach ($this->getSeason() as $season) {
if ($this->seasonActive == $season->getId()) {
return $season;
}
}
} else {
if (!empty($this->getSeason())) {
return $this->getSeason()->last();
}
}
return null;
}
public function setSeasonActive(?Season $seasonActive): self
{
$this->seasonActive = $seasonActive->getId();
return $this;
}
/**
* @return Season|string
*/
public function getSeasonActiveText()
{
$s = $this->getSeasonActive();
return $s ? $s->getYear() . " / " . ($s->getYear() + 1) : "";
}
/**
* @return Collection|Suggestion[]
*/
public function getSuggestions(): Collection
{
return $this->suggestions;
}
public function addSuggestion(Suggestion $suggestion): self
{
if (!$this->suggestions->contains($suggestion)) {
$this->suggestions[] = $suggestion;
$suggestion->setCustomer($this);
}
return $this;
}
public function removeSuggestion(Suggestion $suggestion): self
{
if ($this->suggestions->contains($suggestion)) {
$this->suggestions->removeElement($suggestion);
// set the owning side to null (unless already changed)
if ($suggestion->getCustomer() === $this) {
$suggestion->setCustomer(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function __toString()
{
return self::getEmail();
}
public function getTypeAccount(): ?string
{
return $this->typeAccount;
}
public function setTypeAccount(?string $typeAccount): self
{
$this->typeAccount = $typeAccount;
return $this;
}
public function getIsPro(): ?bool
{
return $this->isPro;
}
public function setIsPro(?bool $isPro): self
{
$this->isPro = $isPro;
return $this;
}
public function getPurchase(): ?string
{
return $this->purchase;
}
public function setPurchase(?string $purchase): self
{
$this->purchase = $purchase;
return $this;
}
public function getPurchasePlatform(): ?string
{
return $this->purchasePlatform;
}
public function setPurchasePlatform(?string $platformPurchase): self
{
$this->purchasePlatform = $platformPurchase;
return $this;
}
public function getMembershipId(): ?string
{
return $this->membershipId;
}
public function setMembershipId(?string $membershipId): self
{
$this->membershipId = $membershipId;
return $this;
}
public function getDateOfBirth(): ?DateTime
{
return $this->dateOfBirth;
}
public function setDateOfBirth(?DateTime $dateOfBirth): self
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getGoogleAuthCode(): ?string
{
return $this->googleAuthCode;
}
public function setGoogleAuthCode(?string $googleAuthCode): self
{
$this->googleAuthCode = $googleAuthCode;
return $this;
}
public function getGoogleAuthCodeVerified(): ?string
{
return $this->googleAuthCodeVerified;
}
public function setGoogleAuthCodeVerified(?string $googleAuthCodeVerified): self
{
$this->googleAuthCodeVerified = $googleAuthCodeVerified;
return $this;
}
/**
* @return Collection|CouponCustomer[]
*/
public function getCustomerCoupons(): Collection
{
return $this->customerCoupons;
}
public function getCouponStatus(): ?bool
{
/**
* Get last coupon used, notice relation is ordered by id asc
*/
$lastCouponCustomer = $this->getCustomerCoupons()->last();
if (!empty($lastCouponCustomer)) {
/**
* Valida la fecha de expiracion del cupon de membresia premium
*/
$now = new \DateTime('now');
$expiredAtCoupon = $lastCouponCustomer->getCoupon()->getExpiresAt();
return $now <= $expiredAtCoupon;
}
return false;
}
// public function setCouponStatus(?bool $couponStatus): self
// {
// $this->couponStatus = $couponStatus;
// return $this;
// }
public function __call($method, $arguments)
{
$method = ('get' === substr($method, 0, 3) || 'set' === substr($method, 0, 3)) ? $method : 'get' . ucfirst($method);
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
/**
* @return Collection|Notification[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setCustomer($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->contains($notification)) {
$this->notifications->removeElement($notification);
// set the owning side to null (unless already changed)
if ($notification->getNotification() === $this) {
$notification->removeCustomer($this);
}
}
return $this;
}
/**
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* @param \DateTime $createdAt
* @return Customer
*/
public function setDeletedAt(?\DateTime $deletedAt): Customer
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getIsDeleted(): ?int
{
return $this->isDeleted;
}
public function setIsDeleted(?int $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
/**
* @return Collection|ExerciseQualification[]
*/
public function getExerciseQualifications(): Collection
{
return $this->exerciseQualifications;
}
public function addExerciseQualification(ExerciseQualification $exerciseQualification): self
{
if (!$this->exerciseQualifications->contains($exerciseQualification)) {
$this->exerciseQualifications[] = $exerciseQualification;
$exerciseQualification->setCustomerId($this);
}
return $this;
}
public function removeExerciseQualification(ExerciseQualification $exerciseQualification): self
{
if ($this->exerciseQualifications->contains($exerciseQualification)) {
$this->exerciseQualifications->removeElement($exerciseQualification);
// set the owning side to null (unless already changed)
if ($exerciseQualification->getCustomerId() === $this) {
$exerciseQualification->setCustomerId(null);
}
}
return $this;
}
public function CountryName()
{
return $this->getCountry() ? $this->getCountry()->getName() : null;
}
public function __toArray()
{
$result = [
'id' => $this->getId(),
'name' => $this->getName(),
'surname' => $this->getSurname(),
'email' => $this->getEmail(),
'phone' => $this->getPhone(),
'address' => $this->getAddress(),
'city' => $this->getCity(),
'zip' => $this->getZip(),
'country' => $this->getCountry() ? $this->getCountry()->getName() : "",
"phone" => $this->getPhone(),
"dateOfBirth" => $this->getDateOfBirth() ? $this->getDateOfBirth()->format('Y-m-d') : null,
];
return $result;
}
/**
* @return Collection<int, Strategy>
*/
public function getStrategies(): Collection
{
return $this->strategies;
}
public function addStrategy(Strategy $strategy): self
{
if (!$this->strategies->contains($strategy)) {
$this->strategies[] = $strategy;
$strategy->setCustomer($this);
}
return $this;
}
public function removeStrategy(Strategy $strategy): self
{
if ($this->strategies->removeElement($strategy)) {
// set the owning side to null (unless already changed)
if ($strategy->getCustomer() === $this) {
$strategy->setCustomer(null);
}
}
return $this;
}
}