<?php
namespace App\Entity\Account;
use App\Entity\Channel\Channel;
use App\Entity\Channel\Group;
use App\Entity\Channel\Service;
use App\Entity\ChannelUserData\ChannelUserData;
use App\Entity\Chat\ChatNotification;
use App\Entity\Chat\Conversation;
use App\Entity\Chat\ConversationUser;
use App\Repository\Account\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Nellapp\Bundle\SDKBundle\Auth\Entity\Token;
use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
use Nellapp\Bundle\SDKBundle\Auth\Entity\UserMethodTrait;
use Symfony\Component\Serializer\Annotation as Serial;
#[
ORM\Entity(repositoryClass: UserRepository::class),
ORM\Index(columns: ['email'], flags: ['fulltext']),
ORM\Index(columns: ['first_name', 'last_name'], flags: ['fulltext']),
ORM\Table(name: 'account_users'),
]
class User implements UserInterface
{
use UserMethodTrait;
#[ORM\Id, ORM\Column(type: 'string')]
#[Serial\Groups(['Message', 'WS_MESSAGE', 'Conversation', 'GlobalJSVariable', 'PostMessage', 'PostMessageReaction', 'PostCoordinators', 'ChatNotification', 'Api'])]
private ?string $id = null;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[Serial\Groups(['Admin_User', 'Api'])]
private ?string $email = null;
/**
* @var string[]
*/
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'string', nullable: true)]
#[Serial\Groups(['Message', 'WS_MESSAGE', 'Conversation', 'GlobalJSVariable', 'ChatNotification', 'Api'])]
private ?string $firstName = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Serial\Groups(['Message', 'WS_MESSAGE', 'Conversation', 'GlobalJSVariable', 'ChatNotification', 'Api'])]
private ?string $lastName = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $avatar = null;
#[ORM\Embedded(class: Token::class)]
private ?Token $token = null;
#[ORM\Column(type: 'text', nullable: true)]
#[Serial\Groups(['Message', 'WS_MESSAGE', 'Conversation', 'GlobalJSVariable', 'ChatNotification', 'Api'])]
private ?string $avatarPath = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTime $signingLimitDate = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private ?bool $hasSeenIntro = false;
#[ORM\ManyToMany(targetEntity: Service::class, mappedBy: 'users')]
private Collection $services;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ConversationUser::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $conversationUsers;
#[ORM\ManyToMany(targetEntity: Group::class, mappedBy: 'users', fetch: 'EXTRA_LAZY')]
private ?Collection $groups;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ChannelUserData::class)]
private ?Collection $channelUserDatas;
#[ORM\Column(type: 'string', nullable: true)]
#[Serial\Groups(['Message', 'Conversation', 'GlobalJSVariable'])]
private ?string $hashTag = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ChatNotification::class)]
private ?Collection $chatNotifications;
#[ORM\ManyToOne(targetEntity: Channel::class, fetch: 'LAZY')]
private ?Channel $lastSelectedChannel = null;
public function __construct()
{
$this->services = new ArrayCollection();
$this->conversationUsers = new ArrayCollection();
$this->channelUserDatas = new ArrayCollection();
$this->chatNotifications = new ArrayCollection();
}
#[Serial\Groups(['Message', 'WS_MESSAGE', 'Conversation', 'GlobalJSVariable', 'ChatNotification', 'Api'])]
public function getUserName(): string
{
return $this;
}
public function getConversationUserByConversation(Conversation $conversation): ?ConversationUser
{
$conversationUser = $this->getConversationUsers()->filter(function (ConversationUser $conversationUser) use ($conversation) {
return $conversationUser->getConversation()->getId() === $conversation->getId();
})->first();
return $conversationUser !== false ? $conversationUser : null;
}
public function getGroups(): Collection
{
return $this->groups ?? $this->groups = new ArrayCollection();
}
public function addGroup(Group $group): self
{
if (!$this->getGroups()->contains($group)) {
$this->getGroups()->add($group);
}
return $this;
}
public function removeGroup(Group $group): self
{
if ($this->getGroups()->contains($group)) {
$this->getGroups()->removeElement($group);
}
return $this;
}
public function getSigningLimitDate(): ?\DateTime
{
return $this->signingLimitDate;
}
public function setSigningLimitDate(?\DateTime $signingLimitDate): static
{
$this->signingLimitDate = $signingLimitDate;
return $this;
}
public function getHasSeenIntro(): ?bool
{
return $this->hasSeenIntro;
}
public function setHasSeenIntro(bool $hasSeenIntro): self
{
$this->hasSeenIntro = $hasSeenIntro;
return $this;
}
/**
* @return Collection<int, Service>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Service $service): self
{
if (!$this->services->contains($service)) {
$this->services[] = $service;
$service->addUser($this);
}
return $this;
}
public function removeService(Service $service): self
{
if ($this->services->removeElement($service)) {
$service->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, ConversationUser>
*/
public function getConversationUsers(): Collection
{
return $this->conversationUsers ?? $this->conversationUsers = new ArrayCollection();
}
public function addConversationUser(ConversationUser $conversationUser): self
{
if (!$this->getConversationUsers()->contains($conversationUser)) {
$this->conversationUsers[] = $conversationUser;
$conversationUser->setUser($this);
}
return $this;
}
public function removeConversationUser(ConversationUser $conversationUser): self
{
if ($this->conversationUsers->removeElement($conversationUser)) {
// set the owning side to null (unless already changed)
if ($conversationUser->getUser() === $this) {
$conversationUser->setUser(null);
}
}
return $this;
}
public function getHashTag(): ?string
{
return $this->hashTag;
}
public function setHashTag(string $hashTag): void
{
$this->hashTag = $hashTag;
}
/**
* @return Collection<int, ChatNotification>
*/
public function getChatNotifications(): Collection
{
return $this->chatNotifications;
}
public function addChatNotification(ChatNotification $chatNotification): self
{
if (!$this->chatNotifications->contains($chatNotification)) {
$this->chatNotifications[] = $chatNotification;
$chatNotification->setUser($this);
}
return $this;
}
public function removeChatNotification(ChatNotification $chatNotification): self
{
if ($this->chatNotifications->removeElement($chatNotification)) {
// set the owning side to null (unless already changed)
if ($chatNotification->getUser() === $this) {
$chatNotification->setUser(null);
}
}
return $this;
}
public function getLastSelectedChannel(): ?Channel
{
return $this->lastSelectedChannel;
}
public function setLastSelectedChannel(?Channel $lastSelectedChannel): void
{
$this->lastSelectedChannel = $lastSelectedChannel;
}
}