WIP: Symfony 6 project remake #2

Draft
skobkin wants to merge 103 commits from symfony6_remake into master
3 changed files with 92 additions and 132 deletions
Showing only changes of commit 6d557c9a40 - Show all commits

View file

@ -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()
;
}
}

View file

@ -1,106 +1,58 @@
<?php <?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 Doctrine\ORM\Mapping as ORM;
use src\PointToolsBundle\Entity\User;
/** #[ORM\Entity(repositoryClass: AccountRepository::class)]
* @ORM\Table(name="telegram_accounts", schema="users", indexes={ #[ORM\HasLifecycleCallbacks]
* @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}), #[ORM\Table(name: 'telegram_accounts', schema: 'users')]
* @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}), #[ORM\Index(columns: ['subscriber_notification'], name: 'subscriber_notification_idx', options: [
* }) 'where' => 'subscriber_notification = TRUE',
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository") ])]
* @ORM\HasLifecycleCallbacks() #[ORM\Index(columns: ['rename_notification'], name: 'rename_notification_idx', options: [
*/ 'where' => 'rename_notification = TRUE',
])]
class Account class Account
{ {
/** #[ORM\Id]
* Telegram user ID #[ORM\Column(name: 'account_id', type: 'integer')]
* private int $id;
* @var int
*
* @ORM\Id()
* @ORM\Column(name="account_id", type="integer")
*/
private $id;
/** #[ORM\Column(name: '', type: 'datetime')]
* @var \DateTime private \DateTime $createdAt;
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/** #[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
* @var \DateTime private ?\DateTime $updatedAt;
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/** #[ORM\Column(name: 'linked_at', type: 'datetime', nullable: true)]
* @var \DateTime private ?\DateTime $linkedAt;
*
* @ORM\Column(name="linked_at", type="datetime", nullable=true)
*/
private $linkedAt;
/** #[ORM\Column(name: 'first_name', type: 'text')]
* @var string private string $firstName;
*
* @ORM\Column(name="first_name", type="text")
*/
private $firstName;
/** #[ORM\Column(name: 'last_name', type: 'text', nullable: true)]
* @var string|null private ?string $lastName;
*
* @ORM\Column(name="last_name", type="text", nullable=true)
*/
private $lastName;
/** #[ORM\Column(name: 'username', type: 'text', nullable: true)]
* @var string|null private ?string $username;
*
* @ORM\Column(name="username", type="text", nullable=true)
*/
private $username;
/** #[ORM\Column(name: 'private_chat_id', type: 'bigint', nullable: true)]
* ID of private chat with user private ?int $chatId;
*
* @var int
*
* @ORM\Column(name="private_chat_id", type="bigint", nullable=true)
*/
private $chatId;
/** #[ORM\OneToOne(targetEntity: User::class)]
* @var User #[ORM\JoinColumn(name: 'user_id', nullable: true, onDelete: 'CASCADE')]
* private ?User $user;
* @ORM\OneToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", nullable=true, onDelete="CASCADE")
*/
private $user;
/** #[ORM\Column(name: 'subscriber_notification', type: 'boolean')]
* Notifications about new subscribers private bool $subscriberNotification = false;
*
* @var bool
*
* @ORM\Column(name="subscriber_notification", type="boolean")
*/
private $subscriberNotification = false;
/** #[ORM\Column(name: 'rename_notification', type: 'boolean')]
* Notifications about user renaming private bool $renameNotification = false;
*
* @var bool
*
* @ORM\Column(name="rename_notification", type="boolean")
*/
private $renameNotification = false;
public function __construct(int $id) public function __construct(int $id)
@ -109,9 +61,7 @@ class Account
$this->createdAt = new \DateTime(); $this->createdAt = new \DateTime();
} }
/** #[ORM\PreUpdate]
* @ORM\PreUpdate()
*/
public function preUpdate(): void public function preUpdate(): void
{ {
$this->updatedAt = new \DateTime(); $this->updatedAt = new \DateTime();
@ -170,9 +120,9 @@ class Account
return $this->user; 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(); $this->linkedAt = new \DateTime();
} }

View file

@ -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()
;
}
}