app/Entity/Schema/ORM/FacebookToken.php line 16

Open in your IDE?
  1. <?php
  2. namespace Sq\Entity\Schema\ORM;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * Facebook Token.
  8.  */
  9. #[ORM\Entity]
  10. #[ORM\Table(name'facebook_token')]
  11. #[ORM\Index(name'fbt_m_id'columns: ['fbt_m_id'])]
  12. #[ORM\UniqueConstraint(name'fbt_fb_id__m_id'columns: ['fbt_fb_id''fbt_m_id'])]
  13. class FacebookToken
  14. {
  15.     /**
  16.      * @var int
  17.      */
  18.     #[ORM\Column(name'fbt_id'type'integer'nullablefalseoptions: ['unsigned' => true])]
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  21.     private $id;
  22.     /**
  23.      * @var Member
  24.      */
  25.     #[ORM\ManyToOne(targetEntityMember::class)]
  26.     #[ORM\JoinColumn(name'fbt_m_id'referencedColumnName'm_id'nullabletrue)]
  27.     private $member;
  28.     /**
  29.      * @var Collection|User[]
  30.      */
  31.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'facebookTokens')]
  32.     #[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')])]
  33.     private $users;
  34.     /**
  35.      * @deprecated Kept for Doctrine mapping purposes, use $users collection instead
  36.      *
  37.      * @var User|null
  38.      */
  39.     #[ORM\Column(name'fbt_u_id'type'integer'nullabletrueoptions: ['unsigned' => true])]
  40.     private $user;
  41.     /**
  42.      * @var string|null
  43.      */
  44.     #[ORM\Column(name'fbt_fb_id'type'string'length64nullabletrue)]
  45.     private $facebookId;
  46.     /**
  47.      * @var string
  48.      */
  49.     #[ORM\Column(name'fbt_user_token'type'text'length16777215nullabletrue)]
  50.     private $userToken;
  51.     /**
  52.      * @var string|null
  53.      */
  54.     #[ORM\Column(name'fbt_token_owner_display_name'type'string'length128nullabletrue)]
  55.     private $tokenOwnerDisplayName;
  56.     /**
  57.      * @var bool|null
  58.      */
  59.     #[ORM\Column(name'fbt_error'type'boolean'nullabletrue)]
  60.     private $error false;
  61.     /**
  62.      * @var bool|null
  63.      */
  64.     #[ORM\Column(name'fbt_deleted'type'boolean'nullabletrue)]
  65.     private $deleted false;
  66.     /**
  67.      * @var bool|null
  68.      */
  69.     #[ORM\Column(name'fbt_login_enabled'type'boolean'nullabletrueoptions: ['default' => '1'])]
  70.     private $loginEnabled true;
  71.     #[ORM\OneToMany(targetEntityFacebook::class, mappedBy'facebookToken')]
  72.     private $facebookEntities;
  73.     #[ORM\OneToMany(targetEntityInstagram::class, mappedBy'facebookToken')]
  74.     private $instagramEntities;
  75.     public function __construct(?Member $memberstring $userTokenstring $tokenOwnerDisplayName, ?string $facebookId null, ?User $user null)
  76.     {
  77.         $this->member $member;
  78.         $this->userToken $userToken;
  79.         $this->tokenOwnerDisplayName $tokenOwnerDisplayName;
  80.         $this->facebookId $facebookId;
  81.         $this->users = new ArrayCollection();
  82.         if ($user !== null)
  83.         {
  84.             $this->addUser($user);
  85.         }
  86.         $this->facebookEntities = new ArrayCollection();
  87.         $this->instagramEntities = new ArrayCollection();
  88.     }
  89.     public function getId(): ?int
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getMember(): ?Member
  94.     {
  95.         return $this->member;
  96.     }
  97.     // If a member has already been set, do not disassociate said member from the Facebook Token.
  98.     public function setMember(Member $member): self
  99.     {
  100.         $this->member $member;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection|User[]
  105.      */
  106.     public function getUsers(): Collection
  107.     {
  108.         return $this->users;
  109.     }
  110.     public function addUser(User $user): self
  111.     {
  112.         if (!$this->users->contains($user))
  113.         {
  114.             $this->users->add($user);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeUser(User $user): self
  119.     {
  120.         $this->users->removeElement($user);
  121.         return $this;
  122.     }
  123.     public function getFacebookId(): ?string
  124.     {
  125.         return $this->facebookId;
  126.     }
  127.     public function setFacebookId(?string $facebookId): self
  128.     {
  129.         $this->facebookId $facebookId;
  130.         return $this;
  131.     }
  132.     public function getUserToken(): string
  133.     {
  134.         return $this->userToken;
  135.     }
  136.     public function setUserToken(string $userToken): self
  137.     {
  138.         $this->userToken $userToken;
  139.         return $this;
  140.     }
  141.     public function getTokenOwnerDisplayName(): ?string
  142.     {
  143.         return $this->tokenOwnerDisplayName;
  144.     }
  145.     public function setTokenOwnerDisplayName(?string $tokenOwnerDisplayName): self
  146.     {
  147.         $this->tokenOwnerDisplayName $tokenOwnerDisplayName;
  148.         return $this;
  149.     }
  150.     public function hasError(): bool
  151.     {
  152.         return $this->error;
  153.     }
  154.     public function setError(bool $error): self
  155.     {
  156.         $this->error $error;
  157.         return $this;
  158.     }
  159.     public function isDeleted(): bool
  160.     {
  161.         return $this->deleted;
  162.     }
  163.     public function setDeleted(bool $deleted): self
  164.     {
  165.         $this->deleted $deleted;
  166.         return $this;
  167.     }
  168.     public function isLoginEnabled(): bool
  169.     {
  170.         return $this->loginEnabled;
  171.     }
  172.     public function setLoginEnabled(bool $loginEnabled): self
  173.     {
  174.         $this->loginEnabled $loginEnabled;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get all connected Facebook social profiles for this user token.
  179.      * Does not include Instagram social profiles that also use this token.
  180.      *
  181.      * @param bool $onlyActive
  182.      *   If it should filter out all deleted profiles.
  183.      *
  184.      * @return \Doctrine\Common\Collections\Collection<FacebookSocialProfile>
  185.      */
  186.     public function getFacebookSocialProfiles(bool $onlyActive false): Collection
  187.     {
  188.         return $this->facebookEntities
  189.             ->filter(fn (Facebook $facebookEntity): bool => !$onlyActive || !$facebookEntity->isDeleted())
  190.             ->map(fn (Facebook $facebookEntity): FacebookSocialProfile => $facebookEntity->getSocialProfile());
  191.     }
  192.     public function addFacebookEntity(Facebook $accountEntity): self
  193.     {
  194.         if (!$this->facebookEntities->contains($accountEntity))
  195.         {
  196.             $this->facebookEntities->add($accountEntity);
  197.         }
  198.         return $this;
  199.     }
  200.     public function removeFacebookEntity(Facebook $accountEntity): self
  201.     {
  202.         $this->facebookEntities->removeElement($accountEntity);
  203.         return $this;
  204.     }
  205.     /**
  206.      * Get all connected Instagram social profiles for this user token.
  207.      * Does not include Facebook social profiles that also use this token.
  208.      *
  209.      * @param bool $onlyActive
  210.      *   If it should filter out all deleted profiles.
  211.      *
  212.      * @return \Doctrine\Common\Collections\Collection<InstagramSocialProfile>
  213.      */
  214.     public function getInstagramSocialProfiles(bool $onlyActive false): Collection
  215.     {
  216.         return $this->instagramEntities
  217.             ->filter(fn (Instagram $instagramEntity): bool => !$onlyActive || !$instagramEntity->isDeleted())
  218.             ->map(fn (Instagram $instagramEntity): InstagramSocialProfile => $instagramEntity->getSocialProfile());
  219.     }
  220.     public function addInstagramEntity(Instagram $profile): self
  221.     {
  222.         if (!$this->instagramEntities->contains($profile))
  223.         {
  224.             $this->instagramEntities->add($profile);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeInstagramEntity(Instagram $profile): self
  229.     {
  230.         $this->instagramEntities->removeElement($profile);
  231.         return $this;
  232.     }
  233. }