From 4f37cb97825f4c5cd88e39082d4b8a0006fff897 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 12 Mar 2023 20:50:52 +0300 Subject: [PATCH] Ported SubscriptionEvent entity and SubscriptionEventRepository. --- .../Entity/SubscriptionEvent.php | 93 ------------------- src/Entity/SubscriptionEvent.php | 72 ++++++++++++++ .../SubscriptionEventRepository.php | 62 ++++++------- 3 files changed, 103 insertions(+), 124 deletions(-) delete mode 100644 old/src/PointToolsBundle/Entity/SubscriptionEvent.php create mode 100644 src/Entity/SubscriptionEvent.php rename {old/src/PointToolsBundle => src}/Repository/SubscriptionEventRepository.php (69%) diff --git a/old/src/PointToolsBundle/Entity/SubscriptionEvent.php b/old/src/PointToolsBundle/Entity/SubscriptionEvent.php deleted file mode 100644 index 183e270..0000000 --- a/old/src/PointToolsBundle/Entity/SubscriptionEvent.php +++ /dev/null @@ -1,93 +0,0 @@ -author = $author; - $this->subscriber = $subscriber; - $this->action = $action; - $this->date = new \DateTime(); - } - - public function getId(): int - { - return $this->id; - } - - public function getDate(): \DateTime - { - return $this->date; - } - - public function getSubscriber(): User - { - return $this->subscriber; - } - - public function getAuthor(): User - { - return $this->author; - } - - public function getAction(): string - { - return $this->action; - } -} diff --git a/src/Entity/SubscriptionEvent.php b/src/Entity/SubscriptionEvent.php new file mode 100644 index 0000000..0f5d298 --- /dev/null +++ b/src/Entity/SubscriptionEvent.php @@ -0,0 +1,72 @@ +author = $author; + $this->subscriber = $subscriber; + $this->action = $action; + $this->date = new \DateTime(); + } + + public function getId(): int + { + return $this->id; + } + + public function getDate(): \DateTime + { + return $this->date; + } + + public function getSubscriber(): User + { + return $this->subscriber; + } + + public function getAuthor(): User + { + return $this->author; + } + + public function getAction(): string + { + return $this->action; + } +} diff --git a/old/src/PointToolsBundle/Repository/SubscriptionEventRepository.php b/src/Repository/SubscriptionEventRepository.php similarity index 69% rename from old/src/PointToolsBundle/Repository/SubscriptionEventRepository.php rename to src/Repository/SubscriptionEventRepository.php index d0ad0cb..021e247 100644 --- a/old/src/PointToolsBundle/Repository/SubscriptionEventRepository.php +++ b/src/Repository/SubscriptionEventRepository.php @@ -1,22 +1,39 @@ + * + * @method SubscriptionEvent|null find($id, $lockMode = null, $lockVersion = null) + * @method SubscriptionEvent|null findOneBy(array $criteria, array $orderBy = null) + * @method SubscriptionEvent[] findAll() + * @method SubscriptionEvent[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class SubscriptionEventRepository extends ServiceEntityRepository { - public function add(SubscriptionEvent $entity): void + public function __construct(ManagerRegistry $registry) { - $this->getEntityManager()->persist($entity); + parent::__construct($registry, SubscriptionEvent::class); + } + + public function save(SubscriptionEvent $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } } - /** - * @return int - */ public function getLastDayEventsCount(): int { $qb = $this->createQueryBuilder('se'); @@ -31,13 +48,7 @@ class SubscriptionEventRepository extends EntityRepository ; } - /** - * Creates QueryBuilder object for pagination of user subscribers events - * - * @param User $user - * - * @return QueryBuilder - */ + /** Creates QueryBuilder object for pagination of user subscribers events */ public function createUserLastSubscribersEventsQuery(User $user): QueryBuilder { $qb = $this->createQueryBuilder('se'); @@ -54,9 +65,6 @@ class SubscriptionEventRepository extends EntityRepository /** * Get last user subscriber events * - * @param User $user - * @param int $limit - * * @return SubscriptionEvent[] */ public function getUserLastSubscribersEvents(User $user, int $limit = 20): array @@ -67,11 +75,7 @@ class SubscriptionEventRepository extends EntityRepository return $qb->getQuery()->getResult(); } - /** - * Get last global subscriptions QueryBuilder for pagination - * - * @return QueryBuilder - */ + /** Get last global subscriptions QueryBuilder for pagination */ public function createLastSubscriptionEventsQuery(): QueryBuilder { $qb = $this->createQueryBuilder('se'); @@ -87,8 +91,6 @@ class SubscriptionEventRepository extends EntityRepository /** * Get last global subscription events * - * @param int $limit - * * @return SubscriptionEvent[] */ public function getLastSubscriptionEvents(int $limit = 20): array @@ -99,9 +101,7 @@ class SubscriptionEventRepository extends EntityRepository return $qb->getQuery()->getResult(); } - /** - * @return SubscriptionEvent[] - */ + /** @return SubscriptionEvent[] */ public function getLastEventsByDay(int $days = 30): array { $qb = $this->createQueryBuilder('se'); @@ -130,4 +130,4 @@ class SubscriptionEventRepository extends EntityRepository return $result; } -} \ No newline at end of file +}