app/Entity/Schema/ORM/LinkedInToken.php line 17

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.  * LinkedIn Token.
  8.  */
  9. #[ORM\Entity]
  10. #[ORM\Table(name'linkedin_token')]
  11. #[ORM\Index(name'lit_token'columns: ['lit_token'])]
  12. #[ORM\Index(name'lit_m_id'columns: ['lit_m_id'])]
  13. #[ORM\UniqueConstraint(name'lit_user_id__m_id'columns: ['lit_user_id''lit_m_id'])]
  14. class LinkedInToken
  15. {
  16.     /**
  17.      * @var int
  18.      */
  19.     #[ORM\Column(name'lit_id'type'integer'nullablefalseoptions: ['unsigned' => true])]
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  22.     private $id;
  23.     /**
  24.      * @var Member|null
  25.      */
  26.     #[ORM\ManyToOne(targetEntityMember::class)]
  27.     #[ORM\JoinColumn(name'lit_m_id'referencedColumnName'm_id'nullabletrue)]
  28.     private $member;
  29.     /**
  30.      * The SmarterQueue users.
  31.      *
  32.      * @var Collection|User[]
  33.      */
  34.     #[ORM\ManyToMany(targetEntityUser::class, inversedBy'linkedInTokens')]
  35.     #[ORM\JoinTable(name'linkedin_token_users'joinColumns: [new ORM\JoinColumn(name'litu_lit_id'referencedColumnName'lit_id'onDelete'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(name'litu_u_id'referencedColumnName'u_id'onDelete'CASCADE')])]
  36.     private $users;
  37.     /**
  38.      * @deprecated Kept for Doctrine mapping purposes, use $users collection instead
  39.      *
  40.      * @var User|null
  41.      */
  42.     #[ORM\Column(name'lit_sq_u_id'type'integer'nullabletrueoptions: ['unsigned' => true])]
  43.     private $user;
  44.     /**
  45.      * The Linkedin external user ID.
  46.      *
  47.      * @var string
  48.      */
  49.     #[ORM\Column(name'lit_user_id'type'string'length32nullablefalse)]
  50.     private $externalUserId;
  51.     /**
  52.      * @var string
  53.      */
  54.     #[ORM\Column(name'lit_token'type'text'length16777215nullablefalse)]
  55.     private $token;
  56.     /**
  57.      * @var string|null
  58.      */
  59.     #[ORM\Column(name'lit_token_owner_display_name'type'string'length128nullabletrue)]
  60.     private $tokenOwnerDisplayName;
  61.     /**
  62.      * @var \DateTimeInterface
  63.      */
  64.     #[ORM\Column(name'lit_token_expiry'type'datetime'nullabletrue)]
  65.     private $tokenExpiry;
  66.     /**
  67.      * @var \DateTime|null
  68.      */
  69.     #[ORM\Column(name'lit_token_last_checked'type'datetime'nullabletrue)]
  70.     private $tokenLastChecked;
  71.     /**
  72.      * @var string|null
  73.      */
  74.     #[ORM\Column(name'lit_refresh_token'type'text'nullabletrue)]
  75.     private $refreshToken;
  76.     /**
  77.      * @var \DateTimeInterface|null
  78.      */
  79.     #[ORM\Column(name'lit_refresh_token_expiry'type'datetime'nullabletrue)]
  80.     private $refreshTokenExpiry;
  81.     /**
  82.      * @var bool|null
  83.      */
  84.     #[ORM\Column(name'lit_deleted'type'boolean'nullabletrue)]
  85.     private $deleted false;
  86.     /**
  87.      * @var bool|null
  88.      */
  89.     #[ORM\Column(name'lit_login_enabled'type'boolean'nullabletrueoptions: ['default' => '1'])]
  90.     private $loginEnabled true;
  91.     #[ORM\OneToMany(targetEntityLinkedIn::class, mappedBy'token')]
  92.     private $linkedInEntities;
  93.     public function __construct(
  94.         ?Member $member,
  95.         string $externalUserId,
  96.         string $token,
  97.         \DateTimeInterface $tokenExpiry,
  98.         ?string $tokenOwnerDisplayName,
  99.         ?User $user null
  100.     ) {
  101.         $this->member $member;
  102.         $this->externalUserId $externalUserId;
  103.         $this->token $token;
  104.         $this->tokenExpiry $tokenExpiry;
  105.         $this->tokenOwnerDisplayName $tokenOwnerDisplayName;
  106.         $this->linkedInEntities = new ArrayCollection();
  107.         $this->users = new ArrayCollection();
  108.         if ($user !== null)
  109.         {
  110.             $this->addUser($user);
  111.         }
  112.         // Forcefully disable login for the Overhaul for security reasons.
  113.         $this->loginEnabled false;
  114.     }
  115.     public function getId(): ?int
  116.     {
  117.         return $this->id;
  118.     }
  119.     public function getMember(): ?Member
  120.     {
  121.         return $this->member;
  122.     }
  123.     public function setMember(?Member $member): self
  124.     {
  125.         $this->member $member;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return Collection|User[]
  130.      */
  131.     public function getUsers(): Collection
  132.     {
  133.         return $this->users;
  134.     }
  135.     public function addUser(User $user): self
  136.     {
  137.         if (!$this->users->contains($user))
  138.         {
  139.             $this->users->add($user);
  140.         }
  141.         return $this;
  142.     }
  143.     public function removeUser(User $user): self
  144.     {
  145.         $this->users->removeElement($user);
  146.         return $this;
  147.     }
  148.     public function getExternalUserId(): string
  149.     {
  150.         return $this->externalUserId;
  151.     }
  152.     public function setExternalUserId(string $userId): self
  153.     {
  154.         $this->externalUserId $userId;
  155.         return $this;
  156.     }
  157.     public function getToken(): string
  158.     {
  159.         return $this->token;
  160.     }
  161.     public function setToken(string $token): self
  162.     {
  163.         $this->token $token;
  164.         return $this;
  165.     }
  166.     public function getTokenOwnerDisplayName(): ?string
  167.     {
  168.         return $this->tokenOwnerDisplayName;
  169.     }
  170.     public function setTokenOwnerDisplayName(?string $tokenOwnerDisplayName): self
  171.     {
  172.         $this->tokenOwnerDisplayName $tokenOwnerDisplayName;
  173.         return $this;
  174.     }
  175.     public function getTokenExpiry(): \DateTimeInterface
  176.     {
  177.         return $this->tokenExpiry;
  178.     }
  179.     public function setTokenExpiry(\DateTimeInterface $tokenExpiry): self
  180.     {
  181.         $this->tokenExpiry $tokenExpiry;
  182.         return $this;
  183.     }
  184.     public function getTokenLastChecked(): ?\DateTimeInterface
  185.     {
  186.         return $this->tokenLastChecked;
  187.     }
  188.     public function setTokenLastChecked(?\DateTimeInterface $tokenLastChecked): self
  189.     {
  190.         $this->tokenLastChecked $tokenLastChecked;
  191.         return $this;
  192.     }
  193.     public function getRefreshToken(): ?string
  194.     {
  195.         return $this->refreshToken;
  196.     }
  197.     public function setRefreshToken(?string $refreshToken): self
  198.     {
  199.         $this->refreshToken $refreshToken;
  200.         return $this;
  201.     }
  202.     public function getRefreshTokenExpiry(): ?\DateTimeInterface
  203.     {
  204.         return $this->refreshTokenExpiry;
  205.     }
  206.     public function setRefreshTokenExpiry(?\DateTimeInterface $refreshTokenExpiry): self
  207.     {
  208.         $this->refreshTokenExpiry $refreshTokenExpiry;
  209.         return $this;
  210.     }
  211.     public function isDeleted(): bool
  212.     {
  213.         return $this->deleted;
  214.     }
  215.     public function setDeleted(bool $deleted): void
  216.     {
  217.         $this->deleted $deleted;
  218.     }
  219.     public function isLoginEnabled(): bool
  220.     {
  221.         return $this->loginEnabled;
  222.     }
  223.     public function setLoginEnabled(bool $loginEnabled): self
  224.     {
  225.         $this->loginEnabled $loginEnabled;
  226.         return $this;
  227.     }
  228.     /**
  229.      * Get all connected social profiles for this user token.
  230.      *
  231.      * @param bool $onlyActive
  232.      *   If it should filter out all deleted profiles.
  233.      *
  234.      * @return \Doctrine\Common\Collections\Collection<LinkedInSocialProfile>
  235.      */
  236.     public function getSocialProfiles(bool $onlyActive false): Collection
  237.     {
  238.         return $this->linkedInEntities
  239.             ->filter(fn (LinkedIn $linkedInEntity): bool => !$onlyActive || !$linkedInEntity->isDeleted())
  240.             ->map(fn (LinkedIn $linkedInEntity): LinkedInSocialProfile => $linkedInEntity->getSocialProfile());
  241.     }
  242.     public function addLinkedInEntity(LinkedIn $linkedInEntity): self
  243.     {
  244.         if (!$this->linkedInEntities->contains($linkedInEntity))
  245.         {
  246.             $this->linkedInEntities->add($linkedInEntity);
  247.         }
  248.         return $this;
  249.     }
  250.     public function removeLinkedInEntity(LinkedIn $linkedInEntity): self
  251.     {
  252.         $this->linkedInEntities->removeElement($linkedInEntity);
  253.         return $this;
  254.     }
  255. }