src/Entity/User.php line 19
<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\String\Slugger\SluggerInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[UniqueEntity(fields: ['username'], message: 'fos_user.username.already_used')]
#[UniqueEntity(fields: ['email'], message: 'fos_user.email.already_used')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const SPEAKOS_RATIO = 850;
const LEVEL_BEGINNER = 1;
const LEVEL_MEDIUM = 2;
const LEVEL_ADVANCED = 3;
const SUB_BOTH = "both";
const SUB_LEARN = "learn";
const SUB_NONE = "none";
const HELP_LEARN = "learn";
const HELP_MOTHER = "mother";
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_NOGIFT = 'ROLE_NOGIFT'; //user inscrit sans la période gratuite
const ROLE_POPIN = 'ROLE_POPIN'; //user inscrit avec affichage popin
const ROLE_PARENT = 'ROLE_PARENT'; //user inscrit avec le form parent
const ROLE_SCHOOL = 'ROLE_SCHOOL'; //ecole inscrite avec 2 mois gratuits
const ROLE_SCHOOLGIFT = 'ROLE_SCHOOLGIFT'; //ecole inscrite avec code cadeau mailing
const ROLE_GIFT = 'ROLE_GIFT'; //user inscrit avec code cadeau
const ROLE_DIRECT = 'ROLE_DIRECT';
const ROLE_GROUP = 'ROLE_GROUP';
const ROLE_PGP = 'ROLE_PGP';
const ROLE_DEMO = 'ROLE_DEMO';
const ROLE_404 = 'ROLE_404'; //can access to payment stats via /restricted/stats.html
const ROLE_DEV = 'ROLE_DEV';
const ROLE_SCHOOLCONTEST = 'ROLE_SCHOOLCONTEST';
const ROLE_AMAZON = 'ROLE_AMAZON';
const ROLE_GOOGLE = 'ROLE_GOOGLE';
const ROLE_APPLE = 'ROLE_APPLE';
const ROLE_BIBLIO = 'ROLE_BIBLIO';
const ROLE_ARCHIMED = 'ROLE_ARCHIMED';
const ROLE_CVS = 'ROLE_CVS';
const ROLE_CAS = 'ROLE_CAS'; //utilisé actuellement pour le portail soane et loire de C3RB
const ROLE_BIBLIO_ADM = 'ROLE_BIBLIO_ADM'; //user pouvant créer des comptes pour les bibliotheque, lié a un biblioInfo
const ROLE_USERNAME = 'ROLE_USERNAME';
const ROLE_ACCESS = 'ROLE_ACCESS'; //inscription avec confirmation et acces gratuit
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Assert\NotBlank(groups: ['registration'])]
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $username;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[Assert\NotBlank(groups: ['registration'])]
#[Assert\Email(groups: ['registration'])]
#[ORM\Column(type: 'string', length: 255, unique: true)]
private $email;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $firstName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $lastName;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $birthDate;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $lastBirthday;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $lastAppLogin;
#[ORM\Column(type: 'boolean')]
private $male;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $schoolName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $address;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $zipCode;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $city;
#[ORM\Column(type: 'string', length: 25, nullable: true)]
private $locale;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $facebookId;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $subscriptionExpireAt;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $unsetcardExpireAt;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $subscriptionDate;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isSubscriber;
#[ORM\Column(type: 'string', length: 10, nullable: true)]
private $subscriptionConfirmed;
#[ORM\Column(type: 'boolean', nullable: true)]
private $isRegistrationConfirmed;
#[ORM\Column(type: 'text', nullable: true)]
private $presentation;
#[ORM\Column(type: 'text', nullable: true)]
private $newPresentation;
#[ORM\Column(type: 'boolean', nullable: true)]
private $incorrectPresentation;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $theme;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $biblioId;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $lastPartBoughtAt;
#[ORM\Column(type: 'datetime_immutable')]
private $createdAt;
#[ORM\Column(type: 'datetime_immutable')]
private $updatedAt;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $mailConfirmedAt;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $salt;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $legacyPassword;
#[ORM\Column(type: 'boolean')]
private $newsletter;
#[ORM\Column(type: 'integer')]
private $reminderIndex;
#[ORM\Column(type: 'text')]
private $serializedTags;
#[ORM\Column(type: 'integer')]
private $speakos;
#[ORM\Column(type: 'integer')]
private $totalSpeakos;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $appToken;
#[ORM\ManyToOne(targetEntity: Country::class, inversedBy: 'users')]
#[ORM\JoinColumn(nullable: false)]
private $eCountry;
#[ORM\ManyToOne(targetEntity: Library::class, inversedBy: 'users')]
private $library;
#[ORM\OneToOne(targetEntity: Speaky::class, cascade: ['persist', 'remove'])]
private $avatar;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserGameConfig::class, orphanRemoval: true)]
private $gameConfigs;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserSubscribeActivity::class, orphanRemoval: true)]
private $subscribeActivities;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: GameComment::class, orphanRemoval: true)]
private $gameComments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: GameVote::class, orphanRemoval: true)]
private $gameVotes;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: GamePlay::class, orphanRemoval: true)]
private $gamePlays;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserOverallProgress::class, orphanRemoval: true)]
private $userProgress;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserWordProgress::class, orphanRemoval: true)]
private $userWordProgress;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserPayment::class)]
private $userPayments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserGiftPayment::class)]
private $userGiftPayments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserLogin::class, orphanRemoval: true)]
private $userLogins;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserSentence::class, orphanRemoval: true, cascade: ['persist', 'remove'])]
private $sentences;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserSpeakyPart::class, orphanRemoval: true, cascade: ['persist', 'remove'])]
private $parts;
#[ORM\ManyToMany(targetEntity: GiftCode::class, inversedBy: 'users')]
private $giftCodes;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[Assert\NotBlank(groups: ['registration'])]
private ?string $plainPassword = null;
#[Assert\NotBlank(groups: ['giftCode'])]
private ?string $code = null;
//permet de stocker les sentences dans l'ordre
protected $orderedSentences;
#[ORM\Column(type: 'string', length: 255)]
private $usernameCanonical;
public function setValue($field, $value)
{
$methodName = 'set'.ucfirst($field);
try {
$this->$methodName($value);
} catch (\Exception $e) {
dump("Method ". $methodName . " doesnt work !");
}
return $this;
}
public function getValue($field)
{
$value = null;
$methodName = 'get'.ucfirst($field);
try {
$value = $this->$methodName();
} catch (\Exception $e) {
dump("Method ". $methodName . " doesnt work !");
}
return $value;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $password): void
{
$this->plainPassword = $password;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): void
{
$this->code = $code;
}
public function getCountry()
{
if (!$this->eCountry)
return 'France métropolitaine';
return $this->eCountry->getName();
}
public function getCountryCode()
{
if (!$this->eCountry)
return 'FR';
$code = $this->eCountry->getIsoCode();
if(is_int($code))
return 'FR';
return $code;
}
public function needsQuote() {
$firstLetter = strtolower($this->usernameCanonical[0]);
$quotesNeeded = array('a', 'e', 'i', 'o', 'u');
foreach ($quotesNeeded as $needed) {
if ($firstLetter == $needed) {
return true;
}
}
return false;
}
/**
* Tells if the the given user has the super admin role.
*
* @return Boolean
*/
public function isAdmin()
{
return $this->hasRole(static::ROLE_ADMIN) || $this->hasRole(static::ROLE_SUPER_ADMIN);
}
/**
* Tells if the the given user has the super admin role.
*
* @return Boolean
*/
public function isSuperAdmin()
{
return $this->hasRole(static::ROLE_SUPER_ADMIN);
}
public function hasRestrictedAccess(){
return $this->hasRole(self::ROLE_BIBLIO) || $this->hasRole(self::ROLE_SCHOOL) || $this->hasRole(self::ROLE_DEMO);
}
public function getAge()
{
if ($this->birthDate == null)
return null;
$age = $this->birthDate->diff(new \DateTime('now'), true);
return (int) $age->format('%y');
}
public function isSubscribed()
{
$date = new \DateTime();
return ($this->subscriptionExpireAt >= $date || $this->isSubscriber);
}
public function winSpeakos($speakos)
{
$this->speakos += $speakos;
$this->totalSpeakos += $speakos;
}
public function __construct()
{
$this->gameConfigs = new ArrayCollection();
$this->subscribeActivities = new ArrayCollection();
$this->gameComments = new ArrayCollection();
$this->gameVotes = new ArrayCollection();
$this->gamePlays = new ArrayCollection();
$this->userProgress = new ArrayCollection();
$this->userWordProgress = new ArrayCollection();
$this->userPayments = new ArrayCollection();
$this->userGiftPayments = new ArrayCollection();
$this->userLogins = new ArrayCollection();
$this->sentences = new ArrayCollection();
$this->parts = new ArrayCollection();
$this->giftCodes = new ArrayCollection();
$this->reminderIndex = 1;
$this->newsletter = true;
$this->speakos = 0;
$this->totalSpeakos = 0;
$this->registrationConfirmed = false;
$this->male = true;
$this->locale = 'fr';
$this->password = '';
$this->serializedTags = '';
}
public function initTempData(UserTempData $data){
$this->username = $data->getUserName();
$this->password = $data->getPassword();
$this->email = $data->getEmail();
$this->serializedTags = $data->getSerializedTags();
$this->locale = $data->getLocale();
$this->address = $data->getAddress();
$this->zipCode = $data->getZipCode();
$this->city = $data->getCity();
$this->eCountry = $data->getECountry();
$this->firstName = $data->getFirstName();
$this->lastName = $data->getLastName();
$this->schoolName = $data->getSchoolName();
$this->facebookId = $data->getFacebookId();
if($this->schoolName != null && $this->schoolName != ''){
$this->addRole(User::ROLE_SCHOOL);
}
}
public function __toString(): string
{
return "#" . $this->id . " " . $this->username;
}
public function computeSlug(SluggerInterface $slugger)
{
$this->usernameCanonical = (string) $slugger->slug((string) $this->username)->lower();
}
#[ORM\PrePersist]
public function setCreatedAtValue()
{
$this->mailConfirmedAt = new \DateTimeImmutable();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
#[ORM\PreUpdate]
public function setUpdatedAtValue()
{
$this->updatedAt = new \DateTimeImmutable();
}
public function getDisplayAge(): ?int
{
if ($this->birthDate == null)
return null;
$age = $this->birthDate->diff(new \DateTime('now'), true);
$display = $age->format('%y');//.' ans';
/*if ((int) $age->format('%m') >= 6)
$display .= ' et demi';*/
return $display;
}
public function getDisplayCountry()
{
if (!$this->eCountry || $this->eCountry->getName() == 'France métropolitaine')
return 'France';
return $this->eCountry->getName();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @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 hasRole($role)
{
return in_array(strtoupper($role), $this->getRoles(), true);
}
public function addRole($role): self
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = $role;
$this->setRoles(array_unique($roles));
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
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 getBirthDate(): ?\DateTimeImmutable
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeImmutable $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getLastBirthday(): ?\DateTimeImmutable
{
return $this->lastBirthday;
}
public function setLastBirthday(?\DateTimeImmutable $lastBirthday): self
{
$this->lastBirthday = $lastBirthday;
return $this;
}
public function getLastAppLogin(): ?\DateTimeImmutable
{
return $this->lastAppLogin;
}
public function setLastAppLogin(?\DateTimeImmutable $lastAppLogin): self
{
$this->lastAppLogin = $lastAppLogin;
return $this;
}
public function getMale(): ?bool
{
return $this->male;
}
public function setMale(bool $male): self
{
$this->male = $male;
return $this;
}
public function getSchoolName(): ?string
{
return $this->schoolName;
}
public function setSchoolName(?string $schoolName): self
{
$this->schoolName = $schoolName;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getZipCode(): ?string
{
return $this->zipCode;
}
public function setZipCode(?string $zipCode): self
{
$this->zipCode = $zipCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
public function getSubscriptionExpireAt(): ?\DateTimeImmutable
{
return $this->subscriptionExpireAt;
}
public function setSubscriptionExpireAt(?\DateTimeImmutable $subscriptionExpireAt): self
{
$this->subscriptionExpireAt = $subscriptionExpireAt;
return $this;
}
public function getUnsetcardExpireAt(): ?\DateTimeImmutable
{
return $this->unsetcardExpireAt;
}
public function setUnsetcardExpireAt(?\DateTimeImmutable $unsetcardExpireAt): self
{
$this->unsetcardExpireAt = $unsetcardExpireAt;
return $this;
}
public function getSubscriptionDate(): ?\DateTimeImmutable
{
return $this->subscriptionDate;
}
public function setSubscriptionDate(?\DateTimeImmutable $subscriptionDate): self
{
$this->subscriptionDate = $subscriptionDate;
return $this;
}
public function getIsSubscriber(): ?bool
{
return $this->isSubscriber;
}
public function setIsSubscriber(?bool $isSubscriber): self
{
$this->isSubscriber = $isSubscriber;
return $this;
}
public function getSubscriptionConfirmed(): ?string
{
return $this->subscriptionConfirmed;
}
public function setSubscriptionConfirmed(?string $subscriptionConfirmed): self
{
$this->subscriptionConfirmed = $subscriptionConfirmed;
return $this;
}
public function getIsRegistrationConfirmed(): ?bool
{
return $this->isRegistrationConfirmed;
}
public function setIsRegistrationConfirmed(?bool $isRegistrationConfirmed): self
{
$this->isRegistrationConfirmed = $isRegistrationConfirmed;
return $this;
}
public function getPresentation(): ?string
{
return $this->presentation;
}
public function setPresentation(?string $presentation): self
{
$this->presentation = $presentation;
return $this;
}
public function getNewPresentation(): ?string
{
return $this->newPresentation;
}
public function setNewPresentation(?string $newPresentation): self
{
$this->newPresentation = $newPresentation;
return $this;
}
public function getIncorrectPresentation(): ?bool
{
return $this->incorrectPresentation;
}
public function setIncorrectPresentation(?bool $incorrectPresentation): self
{
$this->incorrectPresentation = $incorrectPresentation;
return $this;
}
public function getTheme(): ?string
{
return $this->theme;
}
public function setTheme(?string $theme): self
{
$this->theme = $theme;
return $this;
}
public function getBiblioId(): ?string
{
return $this->biblioId;
}
public function setBiblioId(?string $biblioId): self
{
$this->biblioId = $biblioId;
return $this;
}
public function getLastPartBoughtAt(): ?\DateTimeImmutable
{
return $this->lastPartBoughtAt;
}
public function setLastPartBoughtAt(?\DateTimeImmutable $lastPartBoughtAt): self
{
$this->lastPartBoughtAt = $lastPartBoughtAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getMailConfirmedAt(): ?\DateTimeImmutable
{
return $this->mailConfirmedAt;
}
public function setMailConfirmedAt(?\DateTimeImmutable $mailConfirmedAt): self
{
$this->mailConfirmedAt = $mailConfirmedAt;
return $this;
}
public function getSalt(): ?string
{
return $this->salt;
}
public function setSalt(string $salt): self
{
$this->salt = $salt;
return $this;
}
public function getLegacyPassword(): ?string
{
return $this->legacyPassword;
}
public function setLegacyPassword(?string $legacyPassword): self
{
$this->legacyPassword = $legacyPassword;
return $this;
}
public function getNewsletter(): ?bool
{
return $this->newsletter;
}
public function setNewsletter(bool $newsletter): self
{
$this->newsletter = $newsletter;
return $this;
}
public function getReminderIndex(): ?int
{
return $this->reminderIndex;
}
public function setReminderIndex(int $reminderIndex): self
{
$this->reminderIndex = $reminderIndex;
return $this;
}
public function getSerializedTags(): ?string
{
return $this->serializedTags;
}
public function setSerializedTags(string $serializedTags): self
{
$this->serializedTags = $serializedTags;
return $this;
}
public function getSpeakos(): ?int
{
return $this->speakos;
}
public function setSpeakos(int $speakos): self
{
$this->speakos = $speakos;
return $this;
}
public function addSpeakos(int $speakos): self
{
$this->speakos += $speakos;
$this->totalSpeakos += $speakos;
return $this;
}
public function getTotalSpeakos(): ?int
{
return $this->totalSpeakos;
}
public function setTotalSpeakos(int $totalSpeakos): self
{
$this->totalSpeakos = $totalSpeakos;
return $this;
}
public function getAppToken(): ?string
{
return $this->appToken;
}
public function setAppToken(?string $appToken): self
{
$this->appToken = $appToken;
return $this;
}
public function getECountry(): ?Country
{
return $this->eCountry;
}
public function setECountry(?Country $eCountry): self
{
$this->eCountry = $eCountry;
return $this;
}
public function getLibrary(): ?Library
{
return $this->library;
}
public function setLibrary(?Library $library): self
{
$this->library = $library;
return $this;
}
public function getAvatar(): ?Speaky
{
return $this->avatar;
}
public function setAvatar(?Speaky $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection<int, UserGameConfig>
*/
public function getGameConfigs(): Collection
{
return $this->gameConfigs;
}
public function addGameConfig(UserGameConfig $gameConfig): self
{
if (!$this->gameConfigs->contains($gameConfig)) {
$this->gameConfigs[] = $gameConfig;
$gameConfig->setUser($this);
}
return $this;
}
public function removeGameConfig(UserGameConfig $gameConfig): self
{
if ($this->gameConfigs->removeElement($gameConfig)) {
// set the owning side to null (unless already changed)
if ($gameConfig->getUser() === $this) {
$gameConfig->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserSubscribeActivity>
*/
public function getSubscribeActivities(): Collection
{
return $this->subscribeActivities;
}
public function addSubscribeActivity(UserSubscribeActivity $subscribeActivity): self
{
if (!$this->subscribeActivities->contains($subscribeActivity)) {
$this->subscribeActivities[] = $subscribeActivity;
$subscribeActivity->setUser($this);
}
return $this;
}
public function removeSubscribeActivity(UserSubscribeActivity $subscribeActivity): self
{
if ($this->subscribeActivities->removeElement($subscribeActivity)) {
// set the owning side to null (unless already changed)
if ($subscribeActivity->getUser() === $this) {
$subscribeActivity->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, GameComment>
*/
public function getGameComments(): Collection
{
return $this->gameComments;
}
public function addGameComment(GameComment $gameComment): self
{
if (!$this->gameComments->contains($gameComment)) {
$this->gameComments[] = $gameComment;
$gameComment->setUser($this);
}
return $this;
}
public function removeGameComment(GameComment $gameComment): self
{
if ($this->gameComments->removeElement($gameComment)) {
// set the owning side to null (unless already changed)
if ($gameComment->getUser() === $this) {
$gameComment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, GameVote>
*/
public function getGameVotes(): Collection
{
return $this->gameVotes;
}
public function addGameVote(GameVote $gameVote): self
{
if (!$this->gameVotes->contains($gameVote)) {
$this->gameVotes[] = $gameVote;
$gameVote->setUser($this);
}
return $this;
}
public function removeGameVote(GameVote $gameVote): self
{
if ($this->gameVotes->removeElement($gameVote)) {
// set the owning side to null (unless already changed)
if ($gameVote->getUser() === $this) {
$gameVote->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, GamePlay>
*/
public function getGamePlays(): Collection
{
return $this->gamePlays;
}
public function addGamePlay(GamePlay $gamePlay): self
{
if (!$this->gamePlays->contains($gamePlay)) {
$this->gamePlays[] = $gamePlay;
$gamePlay->setUser($this);
}
return $this;
}
public function removeGamePlay(GamePlay $gamePlay): self
{
if ($this->gamePlays->removeElement($gamePlay)) {
// set the owning side to null (unless already changed)
if ($gamePlay->getUser() === $this) {
$gamePlay->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserOverallProgress>
*/
public function getUserProgress(): Collection
{
return $this->userProgress;
}
public function addUserProgress(UserOverallProgress $userProgress): self
{
if (!$this->userProgress->contains($userProgress)) {
$this->userProgress[] = $userProgress;
$userProgress->setUser($this);
}
return $this;
}
public function removeUserProgress(UserOverallProgress $userProgress): self
{
if ($this->userProgress->removeElement($userProgress)) {
// set the owning side to null (unless already changed)
if ($userProgress->getUser() === $this) {
$userProgress->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserWordProgress>
*/
public function getUserWordProgress(): Collection
{
return $this->userWordProgress;
}
public function addUserWordProgress(UserWordProgress $userWordProgress): self
{
if (!$this->userWordProgress->contains($userWordProgress)) {
$this->userWordProgress[] = $userWordProgress;
$userWordProgress->setUser($this);
}
return $this;
}
public function removeUserWordProgress(UserWordProgress $userWordProgress): self
{
if ($this->userWordProgress->removeElement($userWordProgress)) {
// set the owning side to null (unless already changed)
if ($userWordProgress->getUser() === $this) {
$userWordProgress->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserPayment>
*/
public function getUserPayments(): Collection
{
return $this->userPayments;
}
public function addUserPayment(UserPayment $userPayment): self
{
if (!$this->userPayments->contains($userPayment)) {
$this->userPayments[] = $userPayment;
$userPayment->setUser($this);
}
return $this;
}
public function removeUserPayment(UserPayment $userPayment): self
{
if ($this->userPayments->removeElement($userPayment)) {
// set the owning side to null (unless already changed)
if ($userPayment->getUser() === $this) {
$userPayment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserGiftPayment>
*/
public function getUserGiftPayments(): Collection
{
return $this->userGiftPayments;
}
public function addUserGiftPayment(UserGiftPayment $userGiftPayment): self
{
if (!$this->userGiftPayments->contains($userGiftPayment)) {
$this->userGiftPayments[] = $userGiftPayment;
$userGiftPayment->setUser($this);
}
return $this;
}
public function removeUserGiftPayment(UserGiftPayment $userGiftPayment): self
{
if ($this->userGiftPayments->removeElement($userGiftPayment)) {
// set the owning side to null (unless already changed)
if ($userGiftPayment->getUser() === $this) {
$userGiftPayment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserLogin>
*/
public function getUserLogins(): Collection
{
return $this->userLogins;
}
public function addUserLogin(UserLogin $userLogin): self
{
if (!$this->userLogins->contains($userLogin)) {
$this->userLogins[] = $userLogin;
$userLogin->setUser($this);
}
return $this;
}
public function removeUserLogin(UserLogin $userLogin): self
{
if ($this->userLogins->removeElement($userLogin)) {
// set the owning side to null (unless already changed)
if ($userLogin->getUser() === $this) {
$userLogin->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserSentence>
*/
public function getSentences(): Collection
{
return $this->sentences;
}
public function addSentence(UserSentence $sentence): self
{
if (!$this->sentences->contains($sentence)) {
$this->sentences[] = $sentence;
$sentence->setUser($this);
}
return $this;
}
public function removeSentence(UserSentence $sentence): self
{
if ($this->sentences->removeElement($sentence)) {
// set the owning side to null (unless already changed)
if ($sentence->getUser() === $this) {
$sentence->setUser(null);
}
}
return $this;
}
public function getorderedSentences() {
if (!$this->orderedSentences) {
$this->orderedSentences = new ArrayCollection();
//Order the sentences by sentenceOrder
$maxOrder = 0;
foreach ($this->getSentences() as $sentence) {
if ($sentence->getSentenceOrder() > $maxOrder)
$maxOrder = $sentence->getSentenceOrder();
}
for ($i = 0; $i <= $maxOrder; $i++) {
foreach ($this->getSentences() as $sentence) {
if ($sentence->getSentenceOrder() == $i && !$this->orderedSentences->contains($sentence->getSentence()))
$this->orderedSentences->add($sentence->getSentence());
}
}
}
return $this->orderedSentences;
}
/**
* @return Collection<int, UserSpeakyPart>
*/
public function getParts(): Collection
{
return $this->parts;
}
public function addPart(UserSpeakyPart $part): self
{
if (!$this->parts->contains($part)) {
$this->parts[] = $part;
$part->setUser($this);
}
return $this;
}
public function removePart(UserSpeakyPart $part): self
{
if ($this->parts->removeElement($part)) {
// set the owning side to null (unless already changed)
if ($part->getUser() === $this) {
$part->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, GiftCode>
*/
public function getGiftCodes(): Collection
{
return $this->giftCodes;
}
public function addGiftCode(GiftCode $giftCode): self
{
if (!$this->giftCodes->contains($giftCode)) {
$this->giftCodes[] = $giftCode;
}
return $this;
}
public function removeGiftCode(GiftCode $giftCode): self
{
$this->giftCodes->removeElement($giftCode);
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getUsernameCanonical(): ?string
{
return $this->usernameCanonical;
}
public function setUsernameCanonical(string $usernameCanonical): self
{
$this->usernameCanonical = $usernameCanonical;
return $this;
}
/**
* Tells if the the given user has the school role.
*
* @return Boolean
*/
public function isSchool()
{
return $this->hasRole(static::ROLE_SCHOOL) || $this->hasRole(static::ROLE_SCHOOLGIFT);
}
public function isLibrary() {
return $this->hasRole(self::ROLE_BIBLIO || self::ROLE_ARCHIMED || self::ROLE_CVS || self::ROLE_BIBLIO_ADM);
}
}