Compare commits
3 Commits
4f37cb9782
...
c2d682967a
Author | SHA1 | Date |
---|---|---|
Alexey Skobkin | c2d682967a | |
Alexey Skobkin | 6d557c9a40 | |
Alexey Skobkin | 528099baa9 |
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="rename_log", schema="users", indexes={
|
||||
* @ORM\Index(name="idx_rename_log_date", columns={"date"}),
|
||||
* @ORM\Index(name="idx_rename_log_old_login", columns={"old_login"})
|
||||
* })
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRenameEventRepository", readOnly=true)
|
||||
*/
|
||||
class UserRenameEvent
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="user_id", nullable=false, onDelete="CASCADE")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="date", type="datetime")
|
||||
*/
|
||||
private $date;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="old_login", type="text")
|
||||
*/
|
||||
private $oldLogin;
|
||||
|
||||
|
||||
public function __construct(User $user, string $old)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->oldLogin = $old;
|
||||
$this->date = new \DateTime();
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDate(): \DateTime
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getOldLogin(): string
|
||||
{
|
||||
return $this->oldLogin;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Repository\Telegram;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use src\PointToolsBundle\Entity\Telegram\Account;
|
||||
|
||||
class AccountRepository extends EntityRepository
|
||||
{
|
||||
public function add(Account $entity): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total number of accounts
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAccountsCount(): int
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->select('COUNT(a)')
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns number of accounts with linked Point.im profile
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLinkedAccountsCount(): int
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->select('COUNT(a)')
|
||||
->where('a.user IS NOT NULL')
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use src\PointToolsBundle\Entity\UserRenameEvent;
|
||||
|
||||
class UserRenameEventRepository extends EntityRepository
|
||||
{
|
||||
public function add(UserRenameEvent $event)
|
||||
{
|
||||
$this->getEntityManager()->persist($event);
|
||||
}
|
||||
}
|
|
@ -1,106 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace src\PointToolsBundle\Entity\Telegram;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Telegram;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\AccountRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use src\PointToolsBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* @ORM\Table(name="telegram_accounts", schema="users", indexes={
|
||||
* @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}),
|
||||
* @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}),
|
||||
* })
|
||||
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository")
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
#[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',
|
||||
])]
|
||||
class Account
|
||||
{
|
||||
/**
|
||||
* Telegram user ID
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Id()
|
||||
* @ORM\Column(name="account_id", type="integer")
|
||||
*/
|
||||
private $id;
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(name: 'account_id', type: 'integer')]
|
||||
private int $id;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="created_at", type="datetime")
|
||||
*/
|
||||
private $createdAt;
|
||||
#[ORM\Column(name: '', type: 'datetime')]
|
||||
private \DateTime $createdAt;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
|
||||
*/
|
||||
private $updatedAt;
|
||||
#[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
|
||||
private ?\DateTime $updatedAt;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*
|
||||
* @ORM\Column(name="linked_at", type="datetime", nullable=true)
|
||||
*/
|
||||
private $linkedAt;
|
||||
#[ORM\Column(name: 'linked_at', type: 'datetime', nullable: true)]
|
||||
private ?\DateTime $linkedAt;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="first_name", type="text")
|
||||
*/
|
||||
private $firstName;
|
||||
#[ORM\Column(name: 'first_name', type: 'text')]
|
||||
private string $firstName;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(name="last_name", type="text", nullable=true)
|
||||
*/
|
||||
private $lastName;
|
||||
#[ORM\Column(name: 'last_name', type: 'text', nullable: true)]
|
||||
private ?string $lastName;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*
|
||||
* @ORM\Column(name="username", type="text", nullable=true)
|
||||
*/
|
||||
private $username;
|
||||
#[ORM\Column(name: 'username', type: 'text', nullable: true)]
|
||||
private ?string $username;
|
||||
|
||||
/**
|
||||
* ID of private chat with user
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="private_chat_id", type="bigint", nullable=true)
|
||||
*/
|
||||
private $chatId;
|
||||
#[ORM\Column(name: 'private_chat_id', type: 'bigint', nullable: true)]
|
||||
private ?int $chatId;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @ORM\OneToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="user_id", nullable=true, onDelete="CASCADE")
|
||||
*/
|
||||
private $user;
|
||||
#[ORM\OneToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(name: 'user_id', nullable: true, onDelete: 'CASCADE')]
|
||||
private ?User $user;
|
||||
|
||||
/**
|
||||
* Notifications about new subscribers
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(name="subscriber_notification", type="boolean")
|
||||
*/
|
||||
private $subscriberNotification = false;
|
||||
#[ORM\Column(name: 'subscriber_notification', type: 'boolean')]
|
||||
private bool $subscriberNotification = false;
|
||||
|
||||
/**
|
||||
* Notifications about user renaming
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
* @ORM\Column(name="rename_notification", type="boolean")
|
||||
*/
|
||||
private $renameNotification = false;
|
||||
#[ORM\Column(name: 'rename_notification', type: 'boolean')]
|
||||
private bool $renameNotification = false;
|
||||
|
||||
|
||||
public function __construct(int $id)
|
||||
|
@ -109,9 +61,7 @@ class Account
|
|||
$this->createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PreUpdate()
|
||||
*/
|
||||
#[ORM\PreUpdate]
|
||||
public function preUpdate(): void
|
||||
{
|
||||
$this->updatedAt = new \DateTime();
|
||||
|
@ -170,9 +120,9 @@ class Account
|
|||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(User $user): Account
|
||||
public function setUser(User $user): self
|
||||
{
|
||||
if (!$this->user && $user) {
|
||||
if ($this->user !== $user) {
|
||||
$this->linkedAt = new \DateTime();
|
||||
}
|
||||
|
|
@ -9,10 +9,10 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\Table(name: 'users', schema: 'users')]
|
||||
#[ORM\Index(columns: ['public'], name: 'idx_user_public')]
|
||||
#[ORM\Index(columns: ['is_removed'], name: 'idx_user_removed')]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
class User
|
||||
{
|
||||
public const AVATAR_SIZE_SMALL = '24';
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRenameEventRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRenameEventRepository::class, readOnly: true)]
|
||||
#[ORM\Table(name: 'rename_log', schema: 'users')]
|
||||
class UserRenameEvent
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue(strategy: 'AUTO')]
|
||||
#[ORM\Column(name: 'id', type: 'integer')]
|
||||
private ?int $id;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(name: 'user_id', nullable: false, onDelete: 'CASCADE')]
|
||||
private User $user;
|
||||
|
||||
#[ORM\Column(name: 'date', type: 'datetime')]
|
||||
private \DateTime $date;
|
||||
|
||||
#[ORM\Column(name: 'old_login', type: 'text')]
|
||||
private string $oldLogin;
|
||||
|
||||
|
||||
public function __construct(User $user, string $old)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->oldLogin = $old;
|
||||
$this->date = new \DateTime();
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getDate(): \DateTime
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getOldLogin(): string
|
||||
{
|
||||
return $this->oldLogin;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository\Telegram;
|
||||
|
||||
use App\Entity\Telegram\Account;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Account>
|
||||
*
|
||||
* @method Account|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Account|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Account[] findAll()
|
||||
* @method Account[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class AccountRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Account::class);
|
||||
}
|
||||
|
||||
public function save(Account $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAccountsCount(): int
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->select('COUNT(a)')
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function getLinkedAccountsCount(): int
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->select('COUNT(a)')
|
||||
->where('a.user IS NOT NULL')
|
||||
->getQuery()->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\UserRenameEvent;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<UserRenameEvent>
|
||||
*
|
||||
* @method UserRenameEvent|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method UserRenameEvent|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method UserRenameEvent[] findAll()
|
||||
* @method UserRenameEvent[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class UserRenameEventRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, UserRenameEvent::class);
|
||||
}
|
||||
|
||||
public function save(UserRenameEvent $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue