ghost
1 year ago
7 changed files with 743 additions and 210 deletions
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
<?php |
||||
|
||||
namespace App\Entity; |
||||
|
||||
use App\Repository\TorrentDownloadFileRepository; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Entity(repositoryClass: TorrentDownloadFileRepository::class)] |
||||
class TorrentDownloadFile |
||||
{ |
||||
#[ORM\Id] |
||||
#[ORM\GeneratedValue] |
||||
#[ORM\Column] |
||||
private ?int $id = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $torrentId = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $userId = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $added = null; |
||||
|
||||
public function getId(): ?int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function setId(string $id): static |
||||
{ |
||||
$this->id = $id; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getTorrentId(): ?int |
||||
{ |
||||
return $this->torrentId; |
||||
} |
||||
|
||||
public function setTorrentId(int $torrentId): static |
||||
{ |
||||
$this->torrentId = $torrentId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getUserId(): ?int |
||||
{ |
||||
return $this->userId; |
||||
} |
||||
|
||||
public function setUserId(int $userId): static |
||||
{ |
||||
$this->userId = $userId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getAdded(): ?int |
||||
{ |
||||
return $this->added; |
||||
} |
||||
|
||||
public function setAdded(int $added): static |
||||
{ |
||||
$this->added = $added; |
||||
|
||||
return $this; |
||||
} |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
<?php |
||||
|
||||
namespace App\Entity; |
||||
|
||||
use App\Repository\TorrentDownloadMagnetRepository; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Entity(repositoryClass: TorrentDownloadMagnetRepository::class)] |
||||
class TorrentDownloadMagnet |
||||
{ |
||||
#[ORM\Id] |
||||
#[ORM\GeneratedValue] |
||||
#[ORM\Column] |
||||
private ?int $id = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $torrentId = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $userId = null; |
||||
|
||||
#[ORM\Column] |
||||
private ?int $added = null; |
||||
|
||||
public function getId(): ?int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function setId(string $id): static |
||||
{ |
||||
$this->id = $id; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getTorrentId(): ?int |
||||
{ |
||||
return $this->torrentId; |
||||
} |
||||
|
||||
public function setTorrentId(int $torrentId): static |
||||
{ |
||||
$this->torrentId = $torrentId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getUserId(): ?int |
||||
{ |
||||
return $this->userId; |
||||
} |
||||
|
||||
public function setUserId(int $userId): static |
||||
{ |
||||
$this->userId = $userId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getAdded(): ?int |
||||
{ |
||||
return $this->added; |
||||
} |
||||
|
||||
public function setAdded(int $added): static |
||||
{ |
||||
$this->added = $added; |
||||
|
||||
return $this; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
<?php |
||||
|
||||
namespace App\Repository; |
||||
|
||||
use App\Entity\TorrentDownloadFile; |
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
||||
use Doctrine\Persistence\ManagerRegistry; |
||||
|
||||
/** |
||||
* @extends ServiceEntityRepository<TorrentDownloadFile> |
||||
* |
||||
* @method TorrentDownloadFile|null find($id, $lockMode = null, $lockVersion = null) |
||||
* @method TorrentDownloadFile|null findOneBy(array $criteria, array $orderBy = null) |
||||
* @method TorrentDownloadFile[] findAll() |
||||
* @method TorrentDownloadFile[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
||||
*/ |
||||
class TorrentDownloadFileRepository extends ServiceEntityRepository |
||||
{ |
||||
public function __construct(ManagerRegistry $registry) |
||||
{ |
||||
parent::__construct($registry, TorrentDownloadFile::class); |
||||
} |
||||
|
||||
public function findTorrentDownloadFile( |
||||
int $torrentId, |
||||
int $userId |
||||
): ?TorrentDownloadFile |
||||
{ |
||||
return $this->createQueryBuilder('tdf') |
||||
->where('tdf.torrentId = :torrentId') |
||||
->andWhere('tdf.userId = :userId') |
||||
->setParameter('torrentId', $torrentId) |
||||
->setParameter('userId', $userId) |
||||
->orderBy('tdf.id', 'DESC') // same to ts.added |
||||
->setMaxResults(1) |
||||
->getQuery() |
||||
->getOneOrNullResult() |
||||
; |
||||
} |
||||
|
||||
public function findTorrentDownloadFilesTotalByTorrentId( |
||||
int $torrentId |
||||
): int |
||||
{ |
||||
return $this->createQueryBuilder('tdf') |
||||
->select('count(tdf.id)') |
||||
->where('tdf.torrentId = :torrentId') |
||||
->setParameter('torrentId', $torrentId) |
||||
->getQuery() |
||||
->getSingleScalarResult() |
||||
; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
<?php |
||||
|
||||
namespace App\Repository; |
||||
|
||||
use App\Entity\TorrentDownloadMagnet; |
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
||||
use Doctrine\Persistence\ManagerRegistry; |
||||
|
||||
/** |
||||
* @extends ServiceEntityRepository<TorrentDownloadMagnet> |
||||
* |
||||
* @method TorrentDownloadMagnet|null find($id, $lockMode = null, $lockVersion = null) |
||||
* @method TorrentDownloadMagnet|null findOneBy(array $criteria, array $orderBy = null) |
||||
* @method TorrentDownloadMagnet[] findAll() |
||||
* @method TorrentDownloadMagnet[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
||||
*/ |
||||
class TorrentDownloadMagnetRepository extends ServiceEntityRepository |
||||
{ |
||||
public function __construct(ManagerRegistry $registry) |
||||
{ |
||||
parent::__construct($registry, TorrentDownloadMagnet::class); |
||||
} |
||||
|
||||
public function findTorrentDownloadMagnet( |
||||
int $torrentId, |
||||
int $userId |
||||
): ?TorrentDownloadMagnet |
||||
{ |
||||
return $this->createQueryBuilder('tdm') |
||||
->where('tdm.torrentId = :torrentId') |
||||
->andWhere('tdm.userId = :userId') |
||||
->setParameter('torrentId', $torrentId) |
||||
->setParameter('userId', $userId) |
||||
->orderBy('tdm.id', 'DESC') // same to ts.added |
||||
->setMaxResults(1) |
||||
->getQuery() |
||||
->getOneOrNullResult() |
||||
; |
||||
} |
||||
|
||||
public function findTorrentDownloadMagnetsTotalByTorrentId( |
||||
int $torrentId |
||||
): int |
||||
{ |
||||
return $this->createQueryBuilder('tdm') |
||||
->select('count(tdm.id)') |
||||
->where('tdm.torrentId = :torrentId') |
||||
->setParameter('torrentId', $torrentId) |
||||
->getQuery() |
||||
->getSingleScalarResult() |
||||
; |
||||
} |
||||
} |
Loading…
Reference in new issue