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

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

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

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

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

36
src/Service/TorrentService.php

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

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

@ -56,8 +56,8 @@
<sup class="cursor-default" title="{{ 'Total' | trans }}"> <sup class="cursor-default" title="{{ 'Total' | trans }}">
{{ torrent.download.file.total }} {{ torrent.download.file.total }}
</sup> </sup>
<a class="margin-l-8-px margin-r-4-px" href="{{ path('torrent_bookmark_toggle', {torrentId : torrent.id}) }}" title="{{ 'Bookmark' | trans }}"> <a class="margin-l-8-px margin-r-4-px" href="{{ path('torrent_star_toggle', {torrentId : torrent.id}) }}" title="{{ 'Star' | trans }}">
{% if torrent.bookmark.exist %} {% if torrent.star.exist %}
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> <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"/> <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> </svg>
@ -68,7 +68,7 @@
{% endif %} {% endif %}
</a> </a>
<sup class="cursor-default" title="{{ 'Total' | trans }}"> <sup class="cursor-default" title="{{ 'Total' | trans }}">
{{ torrent.bookmark.total }} {{ torrent.star.total }}
</sup> </sup>
</div> </div>
{# {#

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

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

Loading…
Cancel
Save