<?php
namespace App\Entity;
use DateTime;
use DateTimeZone;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Exception\ComplianceException;
use Symfony\Component\Serializer\Annotation\Groups;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;
/**
* Users
*
* @ORM\Table(name="users", indexes={
* @ORM\Index(name="username", columns={"username"}),
* @ORM\Index(name="active", columns={"active"}),
* @ORM\Index(name="removed", columns={"removed"}),
* @ORM\Index(name="update_email_sent", columns={"update_email_sent"}),
* })
* @ORM\Entity(repositoryClass="App\Repository\UsersRepository")
*/
class Users implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups("data_export")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="email_address", type="string", length=255)
* @Groups("data_export")
*/
private $emailAddress;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $firstname = "";
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $lastname = "";
/**
* @var string
*
* @ORM\Column(name="fullname", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $fullname;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
* @Groups("data_export")
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="mobile_phone", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $mobilePhone;
/**
* @var string
*
* @ORM\Column(name="profile_image", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $profileImage;
/**
* @var string
*
* @ORM\Column(name="register_source", type="string", length=255, nullable=true)
* @Groups("data_export")
*/
private $registerSource;
/**
* @var DateTime
*
* @ORM\Column(name="created_at", type="datetime")
* @Groups("data_export")
*/
private $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
* @Groups("data_export")
*/
private $updatedAt;
/**
* @var DateTime
*
* @ORM\Column(name="tos_consent_at", type="datetime", nullable=true)
* @Groups("data_export")
*/
private $tosConsentAt;
/**
* @var DateTime
*
* @ORM\Column(name="gdpr_consent_at", type="datetime", nullable=true)
* @Groups("data_export")
*/
private $gdprConsentAt;
/**
* @var string
*
* @ORM\Column(name="lang", type="string", length=2, options={"default" : "ro"})
* @Groups("data_export")
*/
private $lang;
/**
* @var bool
*
* @ORM\Column(name="active", type="boolean", options={"default" : true})
* @Groups("data_export")
*/
private $active;
/**
* @var bool
*
* @ORM\Column(name="email_verified", type="boolean", options={"default": false})
* @Groups("data_export")
*/
private $emailVerified;
/**
* @var bool
*
* @ORM\Column(name="update_email_sent", type="boolean", options={"default": false})
*/
private $updateEmailSent = false;
/**
* @var bool
*
* @ORM\Column(name="do_not_email", type="boolean", options={"default": false})
* @Groups("data_export")
*/
private $doNotEmail = false;
/**
* @var bool
*
* @ORM\Column(name="removed", type="boolean", options={"default" : true})
* @Groups("data_export")
*/
private $removed;
/**
* @var DateTime
*
* @ORM\Column(name="last_notification", type="date", nullable=true)
* @Groups("data_export")
*/
private $lastNotification;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ApiToken", mappedBy="user")
*/
private $apiTokens;
/**
* @ORM\Column(type="integer", options={"default" : true})
* @Groups("data_export")
*/
private $unit_measure;
/**
* @ORM\Column(type="integer")
* @Groups("data_export")
*/
private $user_points;
/**
* @ORM\Column(type="integer")
*/
private $healthy_minutes;
/**
* @ORM\OneToMany(targetEntity=UserVouchers::class, mappedBy="user")
*/
private $userVouchers;
/**
* @ORM\OneToMany(targetEntity=UserPointsHistory::class, mappedBy="user")
*/
#[OA\Property(type: "array",
items: new OA\Items(ref: new Model(type: UserPointsHistory::class)))]
private $userPointsHistories;
/**
* @ORM\OneToMany(targetEntity=Feedbacks::class, mappedBy="user")
*/
#[OA\Property(type: "array",
items: new OA\Items(ref: new Model(type: Feedbacks::class)))]
private $feedbacks;
/**
* @ORM\OneToOne(targetEntity="UserSubscriptions")
* @ORM\JoinColumn(name="latest_subscription_id", onDelete="SET NULL", options={"unsigned"=true})
*/
private ?UserSubscriptions $latestSubscription = null;
public function __construct()
{
$this->apiTokens = new ArrayCollection();
$this->userVouchers = new ArrayCollection();
$this->userPointsHistories = new ArrayCollection();
$this->feedbacks = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set emailAddress
*
* @param string $emailAddress
*
* @return Users
*/
public function setEmailAddress($emailAddress)
{
$this->emailAddress = $emailAddress;
return $this;
}
/**
* Get emailAddress
*
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}
/**
* Set updateEmailSent
*
* @param string $updateEmailSent
*
* @return Users
*/
public function setUpdateEmailSent($updateEmailSent)
{
$this->updateEmailSent = $updateEmailSent;
return $this;
}
/**
* Get updateEmailSent
*
* @return bool
*/
public function getUpdateEmailSent()
{
return $this->updateEmailSent;
}
/**
* Set updateEmailSent
*
* @param string $doNotEmail
*
* @return Users
*/
public function setDoNotEmail($doNotEmail)
{
$this->doNotEmail = $doNotEmail;
return $this;
}
/**
* Get doNotEmail
*
* @return bool
*/
public function getDoNotEmail()
{
return $this->doNotEmail;
}
/**
* Set firstname
*
* @param string $firstname
*
* @return Users
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
*
* @return Users
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set fullname
*
* @param string $fullname
*
* @return Users
*/
public function setFullname($fullname)
{
if (ctype_space($fullname)) $this->fullname = "";
else $this->fullname = $fullname;
return $this;
}
/**
* Get fullname
*
* @return string
*/
public function getFullname()
{
return $this->fullname;
}
/**
* Set username
*
* @param string $username
*
* @return Users
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* @param string $password
*
* @return Users
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* Set mobilePhone
*
* @param string $mobilePhone
*
* @return Users
*/
public function setMobilePhone($mobilePhone)
{
$this->mobilePhone = $mobilePhone;
return $this;
}
/**
* Get mobilePhone
*
* @return string
*/
public function getMobilePhone()
{
return $this->mobilePhone;
}
/**
* Set profileImage
*
* @param string $profileImage
*
* @return Users
*/
public function setProfileImage($profileImage)
{
$this->profileImage = $profileImage;
return $this;
}
/**
* Get profileImage
*
* @return string
*/
public function getProfileImage()
{
return $this->profileImage;
}
/**
* Set registerSource
*
* @param string $registerSource
*
* @return Users
*/
public function setRegisterSource($registerSource)
{
$this->registerSource = $registerSource;
return $this;
}
/**
* Get registerSource
*
* @return string
*/
public function getRegisterSource()
{
return $this->registerSource;
}
/**
* Set createdAt
*
* @param DateTime $createdAt
*
* @return Users
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param DateTime $updatedAt
*
* @return Users
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set tosConsentAt
*
* @param DateTime $tosConsentAt
*
* @return Users
*/
public function setTosConsentAt($tosConsentAt)
{
$this->tosConsentAt = $tosConsentAt;
return $this;
}
/**
* Get tosConsentAt
*
* @return DateTime
*/
public function getTosConsentAt()
{
return $this->tosConsentAt;
}
/**
* Set gdprConsentAt
*
* @param DateTime $gdprConsentAt
*
* @return Users
*/
public function setGdprConsentAt($gdprConsentAt)
{
$this->gdprConsentAt = $gdprConsentAt;
return $this;
}
/**
* Get gdprConsentAt
*
* @return DateTime
*/
public function getGdprConsentAt()
{
return $this->gdprConsentAt;
}
/**
* @return string
*/
public function getLang()
{
return $this->lang;
}
/**
* @param string $lang
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* Set email verified
*
* @param boolean $emailVerified
*
* @return Users
*/
public function setEmailVerified($emailVerified)
{
$this->emailVerified = $emailVerified;
return $this;
}
/**
* Get email verified
*
* @return bool
*/
public function getEmailVerified()
{
return $this->emailVerified;
}
/**
* Set active
*
* @param boolean $active
*
* @return Users
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* @return bool
*/
public function getActive()
{
return $this->active;
}
/**
* Set removed
*
* @param boolean $removed
*
* @return Users
*/
public function setRemoved($removed)
{
$this->removed = $removed;
return $this;
}
/**
* @return DateTime
*/
public function getLastNotification()
{
return $this->lastNotification;
}
/**
* @param DateTime $lastNotification
*/
public function setLastNotification($lastNotification)
{
$this->lastNotification = $lastNotification;
}
/**
* Get removed
*
* @return bool
*/
public function getRemoved()
{
return $this->removed;
}
public function getRoles(): array
{
return [];
}
#[OA\Property(type: "string")]
private $salt; // TODO: unused, req by docs
public function getSalt()
{
return 'asda9s0d08kjadh'; // TODO: random salt?
}
public function eraseCredentials()
{
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getApiTokens(): Collection
{
return $this->apiTokens;
}
public function getUserIdentifier(): string
{
return $this->username;
}
public function getUnitMeasure(): ?int
{
return $this->unit_measure;
}
public function setUnitMeasure(int $unit_measure): self
{
$this->unit_measure = $unit_measure;
return $this;
}
public function getUserPoints(): ?int
{
return $this->user_points;
}
public function setUserPoints(int $user_points): self
{
$this->user_points = $user_points;
return $this;
}
public function addUserPoints(int $user_points): self
{
$this->user_points += $user_points;
return $this;
}
public function getHealthyMinutes(): ?int
{
return $this->healthy_minutes;
}
public function setHealthyMinutes(int $healthy_minutes): self
{
$this->healthy_minutes = $healthy_minutes;
return $this;
}
public function addHealthyMinutes(int $healthy_minutes): self
{
$this->healthy_minutes += $healthy_minutes;
return $this;
}
/**
* @return Collection<int, UserVouchers>
*/
public function getUserVouchers(): Collection
{
return $this->userVouchers;
}
public function addUserVoucher(UserVouchers $userVoucher): self
{
if (!$this->userVouchers->contains($userVoucher)) {
$this->userVouchers[] = $userVoucher;
$userVoucher->setUser($this);
}
return $this;
}
public function removeUserVoucher(UserVouchers $userVoucher): self
{
if ($this->userVouchers->removeElement($userVoucher)) {
// set the owning side to null (unless already changed)
if ($userVoucher->getUser() === $this) {
$userVoucher->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserPointsHistory>
*/
public function getUserPointsHistories(): Collection
{
return $this->userPointsHistories;
}
public function addUserPointsHistory(UserPointsHistory $userPointsHistory): self
{
if (!$this->userPointsHistories->contains($userPointsHistory)) {
$this->userPointsHistories[] = $userPointsHistory;
$userPointsHistory->setUser($this);
}
return $this;
}
public function removeUserPointsHistory(UserPointsHistory $userPointsHistory): self
{
if ($this->userPointsHistories->removeElement($userPointsHistory)) {
// set the owning side to null (unless already changed)
if ($userPointsHistory->getUser() === $this) {
$userPointsHistory->setUser(null);
}
}
return $this;
}
public function hasValidSubscription()
{
$now = (new DateTime('now', new DateTimeZone('UTC')));
if (!$this->latestSubscription)
return false;
$start = $this->latestSubscription->getStartSubscription();
$end = $this->latestSubscription->getEndSubscription();
$start = new DateTime($start->format('Y-m-d H:i:s'), new DateTimeZone('UTC'));
$end = new DateTime($end->format('Y-m-d H:i:s'), new DateTimeZone('UTC'));
return $start && $end && $start <= $now && $end >= $now;
}
/**
* @return Collection<int, Feedbacks>
*/
public function getFeedbacks(): Collection
{
return $this->feedbacks;
}
public function addFeedback(Feedbacks $feedback): self
{
if (!$this->feedbacks->contains($feedback)) {
$this->feedbacks[] = $feedback;
$feedback->setUser($this);
}
return $this;
}
public function removeFeedback(Feedbacks $feedback): self
{
if ($this->feedbacks->removeElement($feedback)) {
// set the owning side to null (unless already changed)
if ($feedback->getUser() === $this) {
$feedback->setUser(null);
}
}
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function isRemoved(): ?bool
{
return $this->removed;
}
public function addApiToken(ApiToken $apiToken): static
{
if (!$this->apiTokens->contains($apiToken)) {
$this->apiTokens->add($apiToken);
$apiToken->setUser($this);
}
return $this;
}
public function removeApiToken(ApiToken $apiToken): static
{
if ($this->apiTokens->removeElement($apiToken)) {
// set the owning side to null (unless already changed)
if ($apiToken->getUser() === $this) {
$apiToken->setUser(null);
}
}
return $this;
}
public function checkCompliance(DateTime $tosConsentAt, DateTime $gdprConsentAt) {
$tosCheckFailed = !$this->tosConsentAt || $this->tosConsentAt < $tosConsentAt;
$gdprCheckFailed = !$this->gdprConsentAt || $this->gdprConsentAt < $gdprConsentAt;
if ($tosCheckFailed || $gdprCheckFailed) {
$errors = [];
if ($tosCheckFailed) {
$errors[] = "tos";
}
if ($gdprCheckFailed) {
$errors[] = "gdpr";
}
throw new ComplianceException(implode(",", $errors));
}
}
/**
* Get the value of latestSubscription
*
* @return ?UserSubscriptions
*/
public function getLatestSubscription(): ?UserSubscriptions
{
return $this->latestSubscription;
}
/**
* Set the value of latestSubscription
*
* @param ?UserSubscriptions $latestSubscription
*
* @return self
*/
public function setLatestSubscription(?UserSubscriptions $latestSubscription): self
{
$this->latestSubscription = $latestSubscription;
return $this;
}
}