<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
*/
class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text")
*/
private $token;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $fullname;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=200, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $company;
/**
* @ORM\Column(type="integer", options={"default" : 0}))
*/
private $balance = 0;
/**
* @ORM\Column(type="integer", options={"default" : 0}))
*/
private $credit = 0;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="datetime"))
*/
private $created_at;
/**
* @ORM\Column(type="datetime"))
*/
private $updated_at;
/**
* @ORM\OneToMany(targetEntity=Campaign::class, mappedBy="created_by")
*/
private $campaigns;
/**
* @ORM\OneToMany(targetEntity=Media::class, mappedBy="created_by")
*/
private $media;
/**
* @ORM\OneToMany(targetEntity=Notif::class, mappedBy="recepient")
*/
private $notifs;
/**
* @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="linked")
*/
private $transactions;
/**
* @ORM\OneToMany(targetEntity=Payment::class, mappedBy="created_by")
*/
private $payments;
public function __construct()
{
$this->campaigns = new ArrayCollection();
$this->media = new ArrayCollection();
$this->notifs = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->payments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->phone;
}
/**
* @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;
}
/**
* This method is not needed for apps that do not check user passwords.
*
* @see UserInterface
*/
public function getPassword(): ?string
{
return null;
}
/**
* This method is not needed for apps that do not check user passwords.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}
public function getFullname(): ?string
{
return $this->fullname;
}
public function setFullname(?string $fullname): self
{
$this->fullname = $fullname;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): self
{
$this->company = $company;
return $this;
}
public function getCredit(): ?int
{
return $this->credit;
}
public function setCredit(int $credit): self
{
$this->credit = $credit;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
/**
* @return Collection|Campaign[]
*/
public function getCampaigns(): Collection
{
return $this->campaigns;
}
public function addCampaign(Campaign $campaign): self
{
if (!$this->campaigns->contains($campaign)) {
$this->campaigns[] = $campaign;
$campaign->setCreatedBy($this);
}
return $this;
}
public function removeCampaign(Campaign $campaign): self
{
if ($this->campaigns->removeElement($campaign)) {
// set the owning side to null (unless already changed)
if ($campaign->getCreatedBy() === $this) {
$campaign->setCreatedBy(null);
}
}
return $this;
}
public function getBalance(): ?int
{
return $this->balance;
}
public function setBalance(int $balance): self
{
$this->balance = $balance;
return $this;
}
/**
* @return Collection|Media[]
*/
public function getMedia(): Collection
{
return $this->media;
}
public function addMedium(Media $medium): self
{
if (!$this->media->contains($medium)) {
$this->media[] = $medium;
$medium->setCreatedBy($this);
}
return $this;
}
public function removeMedium(Media $medium): self
{
if ($this->media->removeElement($medium)) {
// set the owning side to null (unless already changed)
if ($medium->getCreatedBy() === $this) {
$medium->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection|Notif[]
*/
public function getNotifs(): Collection
{
return $this->notifs;
}
public function addNotif(Notif $notif): self
{
if (!$this->notifs->contains($notif)) {
$this->notifs[] = $notif;
$notif->setRecepient($this);
}
return $this;
}
public function removeNotif(Notif $notif): self
{
if ($this->notifs->removeElement($notif)) {
// set the owning side to null (unless already changed)
if ($notif->getRecepient() === $this) {
$notif->setRecepient(null);
}
}
return $this;
}
/**
* @return Collection|Transaction[]
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): self
{
if (!$this->transactions->contains($transaction)) {
$this->transactions[] = $transaction;
$transaction->setLinked($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): self
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getLinked() === $this) {
$transaction->setLinked(null);
}
}
return $this;
}
/**
* @return string
*/
public function getUserIdentifier()
{
return $this->getPhone();
}
/**
* @return Collection|Payment[]
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->setCreatedBy($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getCreatedBy() === $this) {
$payment->setCreatedBy(null);
}
}
return $this;
}
}