diff --git a/old/src/PointToolsBundle/Entity/Subscription.php b/old/src/PointToolsBundle/Entity/Subscription.php deleted file mode 100644 index 0edfda5..0000000 --- a/old/src/PointToolsBundle/Entity/Subscription.php +++ /dev/null @@ -1,48 +0,0 @@ -author = $author; - $this->subscriber = $subscriber; - } - - public function getAuthor(): User - { - return $this->author; - } - - public function getSubscriber(): User - { - return $this->subscriber; - } -} diff --git a/old/src/PointToolsBundle/Repository/SubscriptionRepository.php b/old/src/PointToolsBundle/Repository/SubscriptionRepository.php deleted file mode 100644 index 8ac974e..0000000 --- a/old/src/PointToolsBundle/Repository/SubscriptionRepository.php +++ /dev/null @@ -1,49 +0,0 @@ -getEntityManager()->persist($entity); - } - - /** - * @param int $id - * - * @return int - */ - public function getUserSubscribersCountById(int $id): int - { - $qb = $this->createQueryBuilder('s'); - return $qb - ->select('COUNT(s.subscriber)') - ->innerJoin('s.author', 'sa') - ->where('sa.id = :id') - ->setParameter('id', $id) - ->getQuery()->getSingleScalarResult() - ; - } - - /** - * @param User $user - * @param User[] $subscribers - */ - public function removeSubscribers(User $user, array $subscribers): void - { - $qb = $this->createQueryBuilder('s'); - $qb - ->delete() - ->where('s.author = :author') - ->andWhere('s.subscriber IN (:subscribers)') - ->setParameter('author', $user->getId()) - ->setParameter('subscribers', $subscribers) - ->getQuery()->execute(); - ; - } -} \ No newline at end of file diff --git a/src/Entity/Subscription.php b/src/Entity/Subscription.php new file mode 100644 index 0000000..bdfabcd --- /dev/null +++ b/src/Entity/Subscription.php @@ -0,0 +1,39 @@ +author = $author; + $this->subscriber = $subscriber; + } + + public function getAuthor(): User + { + return $this->author; + } + + public function getSubscriber(): User + { + return $this->subscriber; + } +} diff --git a/src/Repository/SubscriptionRepository.php b/src/Repository/SubscriptionRepository.php new file mode 100644 index 0000000..098b9dc --- /dev/null +++ b/src/Repository/SubscriptionRepository.php @@ -0,0 +1,60 @@ + + * + * @method Subscription|null find($id, $lockMode = null, $lockVersion = null) + * @method Subscription|null findOneBy(array $criteria, array $orderBy = null) + * @method Subscription[] findAll() + * @method Subscription[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class SubscriptionRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Subscription::class); + } + + public function save(Subscription $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function getUserSubscribersCountById(int $id): int + { + $qb = $this->createQueryBuilder('s'); + return $qb + ->select('COUNT(s.subscriber)') + ->innerJoin('s.author', 'sa') + ->where('sa.id = :id') + ->setParameter('id', $id) + ->getQuery()->getSingleScalarResult() + ; + } + + /** @param User[] $subscribers */ + public function removeSubscribers(User $user, array $subscribers): void + { + $qb = $this->createQueryBuilder('s'); + $qb + ->delete() + ->where('s.author = :author') + ->andWhere('s.subscriber IN (:subscribers)') + ->setParameter('author', $user->getId()) + ->setParameter('subscribers', $subscribers) + ->getQuery()->execute(); + } +}