2017-01-05 20:17:19 +00:00
|
|
|
<?php
|
|
|
|
|
2023-03-12 18:39:18 +00:00
|
|
|
declare(strict_types=1);
|
2017-01-05 20:17:19 +00:00
|
|
|
|
2023-03-12 18:39:18 +00:00
|
|
|
namespace App\Entity\Telegram;
|
|
|
|
|
|
|
|
use App\Entity\User;
|
|
|
|
use App\Repository\AccountRepository;
|
2017-01-05 20:17:19 +00:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2023-03-12 18:39:18 +00:00
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: AccountRepository::class)]
|
|
|
|
#[ORM\HasLifecycleCallbacks]
|
|
|
|
#[ORM\Table(name: 'telegram_accounts', schema: 'users')]
|
|
|
|
#[ORM\Index(columns: ['subscriber_notification'], name: 'subscriber_notification_idx', options: [
|
|
|
|
'where' => 'subscriber_notification = TRUE',
|
|
|
|
])]
|
|
|
|
#[ORM\Index(columns: ['rename_notification'], name: 'rename_notification_idx', options: [
|
|
|
|
'where' => 'rename_notification = TRUE',
|
|
|
|
])]
|
2017-01-05 20:17:19 +00:00
|
|
|
class Account
|
|
|
|
{
|
2023-03-12 18:39:18 +00:00
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\Column(name: 'account_id', type: 'integer')]
|
|
|
|
private int $id;
|
|
|
|
|
|
|
|
#[ORM\Column(name: '', type: 'datetime')]
|
|
|
|
private \DateTime $createdAt;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
|
|
|
|
private ?\DateTime $updatedAt;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'linked_at', type: 'datetime', nullable: true)]
|
|
|
|
private ?\DateTime $linkedAt;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'first_name', type: 'text')]
|
|
|
|
private string $firstName;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'last_name', type: 'text', nullable: true)]
|
|
|
|
private ?string $lastName;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'username', type: 'text', nullable: true)]
|
|
|
|
private ?string $username;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'private_chat_id', type: 'bigint', nullable: true)]
|
|
|
|
private ?int $chatId;
|
|
|
|
|
|
|
|
#[ORM\OneToOne(targetEntity: User::class)]
|
|
|
|
#[ORM\JoinColumn(name: 'user_id', nullable: true, onDelete: 'CASCADE')]
|
|
|
|
private ?User $user;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'subscriber_notification', type: 'boolean')]
|
|
|
|
private bool $subscriberNotification = false;
|
|
|
|
|
|
|
|
#[ORM\Column(name: 'rename_notification', type: 'boolean')]
|
|
|
|
private bool $renameNotification = false;
|
2017-01-05 20:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
public function __construct(int $id)
|
|
|
|
{
|
|
|
|
$this->id = $id;
|
|
|
|
$this->createdAt = new \DateTime();
|
|
|
|
}
|
|
|
|
|
2023-03-12 18:39:18 +00:00
|
|
|
#[ORM\PreUpdate]
|
2017-01-12 22:58:52 +00:00
|
|
|
public function preUpdate(): void
|
2017-01-05 20:17:19 +00:00
|
|
|
{
|
|
|
|
$this->updatedAt = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedAt(): \DateTime
|
|
|
|
{
|
|
|
|
return $this->createdAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUpdatedAt(): \DateTime
|
|
|
|
{
|
|
|
|
return $this->updatedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLinkedAt(): \DateTime
|
|
|
|
{
|
|
|
|
return $this->linkedAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFirstName(): string
|
|
|
|
{
|
|
|
|
return $this->firstName;
|
|
|
|
}
|
|
|
|
|
2017-11-05 01:42:08 +00:00
|
|
|
public function updateFromMessageData(string $firstName, ?string $lastName, ?string $username, int $chatId): void
|
2017-01-05 20:17:19 +00:00
|
|
|
{
|
|
|
|
$this->firstName = $firstName;
|
2017-11-05 01:42:08 +00:00
|
|
|
$this->lastName = $lastName;
|
|
|
|
$this->username = $username;
|
|
|
|
$this->chatId = $chatId;
|
2017-01-05 20:17:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 22:58:52 +00:00
|
|
|
public function getLastName(): ?string
|
2017-01-05 20:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->lastName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUsername(): string
|
|
|
|
{
|
|
|
|
return $this->username;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChatId(): int
|
|
|
|
{
|
|
|
|
return $this->chatId;
|
|
|
|
}
|
|
|
|
|
2017-01-12 22:58:52 +00:00
|
|
|
public function getUser(): ?User
|
2017-01-05 20:17:19 +00:00
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
2023-03-12 18:39:18 +00:00
|
|
|
public function setUser(User $user): self
|
2017-01-05 20:17:19 +00:00
|
|
|
{
|
2023-03-12 18:39:18 +00:00
|
|
|
if ($this->user !== $user) {
|
2017-01-05 20:17:19 +00:00
|
|
|
$this->linkedAt = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->user = $user;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserId(): int
|
|
|
|
{
|
|
|
|
return $this->user->getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function disableNotifications(): self
|
|
|
|
{
|
|
|
|
$this->subscriberNotification = false;
|
|
|
|
$this->renameNotification = false;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubscriberNotification(bool $subscriberNotification): self
|
|
|
|
{
|
|
|
|
$this->subscriberNotification = $subscriberNotification;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-06 19:19:44 +00:00
|
|
|
public function toggleSubscriberNotification(): self
|
|
|
|
{
|
|
|
|
$this->subscriberNotification = !$this->subscriberNotification;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
public function isSubscriberNotification(): bool
|
|
|
|
{
|
|
|
|
return $this->subscriberNotification;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRenameNotification(bool $renameNotification): self
|
|
|
|
{
|
|
|
|
$this->renameNotification = $renameNotification;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-06 19:19:44 +00:00
|
|
|
public function toggleRenameNotification(): self
|
|
|
|
{
|
|
|
|
$this->renameNotification = !$this->renameNotification;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:17:19 +00:00
|
|
|
public function isRenameNotification(): bool
|
|
|
|
{
|
|
|
|
return $this->renameNotification;
|
|
|
|
}
|
|
|
|
}
|