<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Repository\AccountRepository;
/**
* Account
*
* @ORM\Table(name="accounts", uniqueConstraints={@ORM\UniqueConstraint(name="email", columns={"email"})}, indexes={@ORM\Index(name="accountsPlans", columns={"planid"})})
* @ORM\Entity(repositoryClass=AccountRepository::class)
* @UniqueEntity(fields={"email"}, message="We are unable to create your account with that information.")
*/
class Account implements UserInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=false)
*/
private $firstname;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=false)
*/
private $lastname;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var bool|null
*
* @ORM\Column(name="exempt", type="boolean", nullable=true)
*/
private $exempt;
/**
* @var bool|null
*
* @ORM\Column(name="active", type="boolean", nullable=true)
*/
private $active;
/**
* @var \DateTime|null
*
* @ORM\Column(name="lastlogin", type="datetime", nullable=true)
*/
private $lastlogin;
/**
* @var \DateTime|null
*
* @ORM\Column(name="created", type="datetime", nullable=true)
*/
private $created;
/**
* @var \DateTime|null
*
* @ORM\Column(name="modified", type="datetime", nullable=true)
*/
private $modified;
/**
* @var Plan|null
*
* @ORM\ManyToOne(targetEntity="Plan")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="planid", referencedColumnName="id")
* })
*/
private $plan;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = true;
/**
* @var Plan
*
* @ORM\ManyToOne(targetEntity="Plan")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="desired_plan", referencedColumnName="id")
* })
*/
private $desiredPlan;
/**
* @var Service[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Service", mappedBy="accounts")
*/
private $services;
/**
* @var Payment[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Payment", mappedBy="account")
* @ORM\OrderBy({"created" = "DESC"})
*/
private $payments;
/**
* @var ApiKey[]
*
* @ORM\OneToMany(targetEntity="App\Entity\ApiKey", mappedBy="account")
*/
private $apiKeys;
/**
* Account constructor.
*/
public function __construct()
{
$this->created = new \DateTime();
$this->modified = new \DateTime();
$this->services = new ArrayCollection();
// Give everyone a ROLE_USER
$this->roles = ['ROLE_USER'];
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getUsername(): string
{
return (string)$this->email;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(?string $password): self
{
$this->password = $password;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function setLastlogin(\DateTime $lastlogin): self
{
$this->lastlogin = $lastlogin;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function getModified(): ?\DateTimeInterface
{
return $this->modified;
}
public function getPlan()
{
return $this->plan;
}
public function setPlan(Plan $plan): self
{
$this->plan = $plan;
return $this;
}
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function getSalt()
{
return null;
}
public function eraseCredentials()
{
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Plan
*/
public function getDesiredPlan(): Plan
{
return $this->desiredPlan;
}
/**
* @param Plan $desiredPlan
* @return $this
*/
public function setDesiredPlan(Plan $desiredPlan): self
{
$this->desiredPlan = $desiredPlan;
return $this;
}
/**
* @return Service[]
*/
public function getServices()
{
return $this->services;
}
/**
* @param Service $service
* @return $this
*/
public function addService(Service $service) : self
{
if (!$this->services->contains($service)) {
$this->services[] = $service;
$service->addAccount($this);
}
return $this;
}
/**
* @param Service $service
*/
public function removeService(Service $service)
{
if ($this->services->contains($service)) {
$this->services->removeElement($service);
$service->removeAccount($this);
}
}
/**
* @return Payment[]
*/
public function getPayments()
{
return $this->payments;
}
/**
* @return ApiKey[]
*/
public function getApiKeys()
{
return $this->apiKeys;
}
/**
* @param \DateTime|null $modified
*/
public function setModified(?\DateTime $modified): void
{
$this->modified = $modified;
}
}