mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-04-01 01:25:39 +00:00
refactor bookmarks to stars
This commit is contained in:
parent
997d9db562
commit
f260bda7ee
6 changed files with 46 additions and 46 deletions
53
src/Repository/TorrentStarRepository.php
Normal file
53
src/Repository/TorrentStarRepository.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\TorrentStar;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<TorrentStar>
|
||||
*
|
||||
* @method TorrentStar|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method TorrentStar|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method TorrentStar[] findAll()
|
||||
* @method TorrentStar[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class TorrentStarRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, TorrentStar::class);
|
||||
}
|
||||
|
||||
public function findTorrentStar(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentStar
|
||||
{
|
||||
return $this->createQueryBuilder('tb')
|
||||
->where('tb.torrentId = :torrentId')
|
||||
->andWhere('tb.userId = :userId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->setParameter('userId', $userId)
|
||||
->orderBy('tb.id', 'DESC') // same to ts.added
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findTorrentStarsTotalByTorrentId(
|
||||
int $torrentId
|
||||
): int
|
||||
{
|
||||
return $this->createQueryBuilder('tb')
|
||||
->select('count(tb.id)')
|
||||
->where('tb.torrentId = :torrentId')
|
||||
->setParameter('torrentId', $torrentId)
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue