Browse Source

refactor bookmarks to stars

main
ghost 1 year ago
parent
commit
f260bda7ee
  1. 16
      src/Controller/TorrentController.php
  2. 6
      src/Entity/TorrentStar.php
  3. 22
      src/Repository/TorrentStarRepository.php
  4. 36
      src/Service/TorrentService.php
  5. 6
      templates/default/torrent/info.html.twig
  6. 6
      translations/messages+intl-icu.uk.xlf

16
src/Controller/TorrentController.php

@ -126,13 +126,13 @@ class TorrentController extends AbstractController @@ -126,13 +126,13 @@ class TorrentController extends AbstractController
)
]
],
'bookmark' =>
'star' =>
[
'exist' => (bool) $torrentService->findTorrentBookmark(
'exist' => (bool) $torrentService->findTorrentStar(
$torrent->getId(),
$user->getId()
),
'total' => $torrentService->findTorrentBookmarksTotalByTorrentId(
'total' => $torrentService->findTorrentStarsTotalByTorrentId(
$torrent->getId()
)
],
@ -901,10 +901,10 @@ class TorrentController extends AbstractController @@ -901,10 +901,10 @@ class TorrentController extends AbstractController
);
}
// Torrent bookmark
// Torrent star
#[Route(
'/{_locale}/torrent/{torrentId}/bookmark/toggle',
name: 'torrent_bookmark_toggle',
'/{_locale}/torrent/{torrentId}/star/toggle',
name: 'torrent_star_toggle',
requirements:
[
'torrentId' => '\d+',
@ -914,7 +914,7 @@ class TorrentController extends AbstractController @@ -914,7 +914,7 @@ class TorrentController extends AbstractController
'GET'
]
)]
public function toggleBookmark(
public function toggleStar(
Request $request,
TranslatorInterface $translator,
UserService $userService,
@ -941,7 +941,7 @@ class TorrentController extends AbstractController @@ -941,7 +941,7 @@ class TorrentController extends AbstractController
}
// Update
$torrentService->toggleTorrentBookmark(
$torrentService->toggleTorrentStar(
$torrent->getId(),
$user->getId(),
time()

6
src/Entity/TorrentBookmark.php → src/Entity/TorrentStar.php

@ -2,11 +2,11 @@ @@ -2,11 +2,11 @@
namespace App\Entity;
use App\Repository\TorrentBookmarkRepository;
use App\Repository\TorrentStarRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TorrentBookmarkRepository::class)]
class TorrentBookmark
#[ORM\Entity(repositoryClass: TorrentStarRepository::class)]
class TorrentStar
{
#[ORM\Id]
#[ORM\GeneratedValue]

22
src/Repository/TorrentBookmarkRepository.php → src/Repository/TorrentStarRepository.php

@ -2,29 +2,29 @@ @@ -2,29 +2,29 @@
namespace App\Repository;
use App\Entity\TorrentBookmark;
use App\Entity\TorrentStar;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<TorrentBookmark>
* @extends ServiceEntityRepository<TorrentStar>
*
* @method TorrentBookmark|null find($id, $lockMode = null, $lockVersion = null)
* @method TorrentBookmark|null findOneBy(array $criteria, array $orderBy = null)
* @method TorrentBookmark[] findAll()
* @method TorrentBookmark[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @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 TorrentBookmarkRepository extends ServiceEntityRepository
class TorrentStarRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, TorrentBookmark::class);
parent::__construct($registry, TorrentStar::class);
}
public function findTorrentBookmark(
public function findTorrentStar(
int $torrentId,
int $userId
): ?TorrentBookmark
): ?TorrentStar
{
return $this->createQueryBuilder('tb')
->where('tb.torrentId = :torrentId')
@ -38,7 +38,7 @@ class TorrentBookmarkRepository extends ServiceEntityRepository @@ -38,7 +38,7 @@ class TorrentBookmarkRepository extends ServiceEntityRepository
;
}
public function findTorrentBookmarksTotalByTorrentId(
public function findTorrentStarsTotalByTorrentId(
int $torrentId
): int
{

36
src/Service/TorrentService.php

@ -5,14 +5,14 @@ namespace App\Service; @@ -5,14 +5,14 @@ namespace App\Service;
use App\Entity\Torrent;
use App\Entity\TorrentLocales;
use App\Entity\TorrentSensitive;
use App\Entity\TorrentBookmark;
use App\Entity\TorrentStar;
use App\Entity\TorrentDownloadFile;
use App\Entity\TorrentDownloadMagnet;
use App\Repository\TorrentRepository;
use App\Repository\TorrentLocalesRepository;
use App\Repository\TorrentSensitiveRepository;
use App\Repository\TorrentBookmarkRepository;
use App\Repository\TorrentStarRepository;
use App\Repository\TorrentDownloadFileRepository;
use App\Repository\TorrentDownloadMagnetRepository;
@ -424,45 +424,45 @@ class TorrentService @@ -424,45 +424,45 @@ class TorrentService
return $torrentSensitive;
}
// Torrent bookmark
public function findTorrentBookmark(
// Torrent star
public function findTorrentStar(
int $torrentId,
int $userId
): ?TorrentBookmark
): ?TorrentStar
{
return $this->entityManagerInterface
->getRepository(TorrentBookmark::class)
->findTorrentBookmark($torrentId, $userId);
->getRepository(TorrentStar::class)
->findTorrentStar($torrentId, $userId);
}
public function findTorrentBookmarksTotalByTorrentId(int $torrentId): int
public function findTorrentStarsTotalByTorrentId(int $torrentId): int
{
return $this->entityManagerInterface
->getRepository(TorrentBookmark::class)
->findTorrentBookmarksTotalByTorrentId($torrentId);
->getRepository(TorrentStar::class)
->findTorrentStarsTotalByTorrentId($torrentId);
}
public function toggleTorrentBookmark(
public function toggleTorrentStar(
int $torrentId,
int $userId,
int $added
): void
{
if ($torrentBookmark = $this->findTorrentBookmark($torrentId, $userId))
if ($torrentStar = $this->findTorrentStar($torrentId, $userId))
{
$this->entityManagerInterface->remove($torrentBookmark);
$this->entityManagerInterface->remove($torrentStar);
$this->entityManagerInterface->flush();
}
else
{
$torrentBookmark = new TorrentBookmark();
$torrentStar = new TorrentStar();
$torrentBookmark->setTorrentId($torrentId);
$torrentBookmark->setUserId($userId);
$torrentBookmark->setAdded($added);
$torrentStar->setTorrentId($torrentId);
$torrentStar->setUserId($userId);
$torrentStar->setAdded($added);
$this->entityManagerInterface->persist($torrentBookmark);
$this->entityManagerInterface->persist($torrentStar);
$this->entityManagerInterface->flush();
}
}

6
templates/default/torrent/info.html.twig

@ -56,8 +56,8 @@ @@ -56,8 +56,8 @@
<sup class="cursor-default" title="{{ 'Total' | trans }}">
{{ torrent.download.file.total }}
</sup>
<a class="margin-l-8-px margin-r-4-px" href="{{ path('torrent_bookmark_toggle', {torrentId : torrent.id}) }}" title="{{ 'Bookmark' | trans }}">
{% if torrent.bookmark.exist %}
<a class="margin-l-8-px margin-r-4-px" href="{{ path('torrent_star_toggle', {torrentId : torrent.id}) }}" title="{{ 'Star' | trans }}">
{% if torrent.star.exist %}
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
{% endif %}
</a>
<sup class="cursor-default" title="{{ 'Total' | trans }}">
{{ torrent.bookmark.total }}
{{ torrent.star.total }}
</sup>
</div>
{#

6
translations/messages+intl-icu.uk.xlf

@ -357,9 +357,9 @@ @@ -357,9 +357,9 @@
<source>Download torrent file</source>
<target>Download torrent file</target>
</trans-unit>
<trans-unit id="G6xAB4g" resname="Bookmark">
<source>Bookmark</source>
<target>Bookmark</target>
<trans-unit id="G6xAB4g" resname="Star">
<source>Star</source>
<target>Star</target>
</trans-unit>
<trans-unit id="lxuXQjW" resname="Filename">
<source>Filename</source>

Loading…
Cancel
Save