<?php
namespace Sq\Entity\Schema\ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Facebook Token.
*/
#[ORM\Entity]
#[ORM\Table(name: 'facebook_token')]
#[ORM\Index(name: 'fbt_m_id', columns: ['fbt_m_id'])]
#[ORM\UniqueConstraint(name: 'fbt_fb_id__m_id', columns: ['fbt_fb_id', 'fbt_m_id'])]
class FacebookToken
{
/**
* @var int
*/
#[ORM\Column(name: 'fbt_id', type: 'integer', nullable: false, options: ['unsigned' => true])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var Member
*/
#[ORM\ManyToOne(targetEntity: Member::class)]
#[ORM\JoinColumn(name: 'fbt_m_id', referencedColumnName: 'm_id', nullable: true)]
private $member;
/**
* @var Collection|User[]
*/
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'facebookTokens')]
#[ORM\JoinTable(name: 'facebook_token_users', joinColumns: [new ORM\JoinColumn(name: 'fbtu_fbt_id', referencedColumnName: 'fbt_id', onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(name: 'fbtu_u_id', referencedColumnName: 'u_id', onDelete: 'CASCADE')])]
private $users;
/**
* @deprecated Kept for Doctrine mapping purposes, use $users collection instead
*
* @var User|null
*/
#[ORM\Column(name: 'fbt_u_id', type: 'integer', nullable: true, options: ['unsigned' => true])]
private $user;
/**
* @var string|null
*/
#[ORM\Column(name: 'fbt_fb_id', type: 'string', length: 64, nullable: true)]
private $facebookId;
/**
* @var string
*/
#[ORM\Column(name: 'fbt_user_token', type: 'text', length: 16777215, nullable: true)]
private $userToken;
/**
* @var string|null
*/
#[ORM\Column(name: 'fbt_token_owner_display_name', type: 'string', length: 128, nullable: true)]
private $tokenOwnerDisplayName;
/**
* @var bool|null
*/
#[ORM\Column(name: 'fbt_error', type: 'boolean', nullable: true)]
private $error = false;
/**
* @var bool|null
*/
#[ORM\Column(name: 'fbt_deleted', type: 'boolean', nullable: true)]
private $deleted = false;
/**
* @var bool|null
*/
#[ORM\Column(name: 'fbt_login_enabled', type: 'boolean', nullable: true, options: ['default' => '1'])]
private $loginEnabled = true;
#[ORM\OneToMany(targetEntity: Facebook::class, mappedBy: 'facebookToken')]
private $facebookEntities;
#[ORM\OneToMany(targetEntity: Instagram::class, mappedBy: 'facebookToken')]
private $instagramEntities;
public function __construct(?Member $member, string $userToken, string $tokenOwnerDisplayName, ?string $facebookId = null, ?User $user = null)
{
$this->member = $member;
$this->userToken = $userToken;
$this->tokenOwnerDisplayName = $tokenOwnerDisplayName;
$this->facebookId = $facebookId;
$this->users = new ArrayCollection();
if ($user !== null)
{
$this->addUser($user);
}
$this->facebookEntities = new ArrayCollection();
$this->instagramEntities = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMember(): ?Member
{
return $this->member;
}
// If a member has already been set, do not disassociate said member from the Facebook Token.
public function setMember(Member $member): self
{
$this->member = $member;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user))
{
$this->users->add($user);
}
return $this;
}
public function removeUser(User $user): self
{
$this->users->removeElement($user);
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
public function getUserToken(): string
{
return $this->userToken;
}
public function setUserToken(string $userToken): self
{
$this->userToken = $userToken;
return $this;
}
public function getTokenOwnerDisplayName(): ?string
{
return $this->tokenOwnerDisplayName;
}
public function setTokenOwnerDisplayName(?string $tokenOwnerDisplayName): self
{
$this->tokenOwnerDisplayName = $tokenOwnerDisplayName;
return $this;
}
public function hasError(): bool
{
return $this->error;
}
public function setError(bool $error): self
{
$this->error = $error;
return $this;
}
public function isDeleted(): bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function isLoginEnabled(): bool
{
return $this->loginEnabled;
}
public function setLoginEnabled(bool $loginEnabled): self
{
$this->loginEnabled = $loginEnabled;
return $this;
}
/**
* Get all connected Facebook social profiles for this user token.
* Does not include Instagram social profiles that also use this token.
*
* @param bool $onlyActive
* If it should filter out all deleted profiles.
*
* @return \Doctrine\Common\Collections\Collection<FacebookSocialProfile>
*/
public function getFacebookSocialProfiles(bool $onlyActive = false): Collection
{
return $this->facebookEntities
->filter(fn (Facebook $facebookEntity): bool => !$onlyActive || !$facebookEntity->isDeleted())
->map(fn (Facebook $facebookEntity): FacebookSocialProfile => $facebookEntity->getSocialProfile());
}
public function addFacebookEntity(Facebook $accountEntity): self
{
if (!$this->facebookEntities->contains($accountEntity))
{
$this->facebookEntities->add($accountEntity);
}
return $this;
}
public function removeFacebookEntity(Facebook $accountEntity): self
{
$this->facebookEntities->removeElement($accountEntity);
return $this;
}
/**
* Get all connected Instagram social profiles for this user token.
* Does not include Facebook social profiles that also use this token.
*
* @param bool $onlyActive
* If it should filter out all deleted profiles.
*
* @return \Doctrine\Common\Collections\Collection<InstagramSocialProfile>
*/
public function getInstagramSocialProfiles(bool $onlyActive = false): Collection
{
return $this->instagramEntities
->filter(fn (Instagram $instagramEntity): bool => !$onlyActive || !$instagramEntity->isDeleted())
->map(fn (Instagram $instagramEntity): InstagramSocialProfile => $instagramEntity->getSocialProfile());
}
public function addInstagramEntity(Instagram $profile): self
{
if (!$this->instagramEntities->contains($profile))
{
$this->instagramEntities->add($profile);
}
return $this;
}
public function removeInstagramEntity(Instagram $profile): self
{
$this->instagramEntities->removeElement($profile);
return $this;
}
}