Browse Source

add torrent star event support #4

main
ghost 1 year ago
parent
commit
a3dd5a81a9
  1. 55
      src/Controller/ActivityController.php
  2. 24
      src/Controller/TorrentController.php
  3. 7
      src/Entity/Activity.php
  4. 64
      src/Service/ActivityService.php
  5. 6
      src/Service/TorrentService.php
  6. 12
      templates/default/activity/event/torrent/star/add.html.twig
  7. 12
      templates/default/activity/event/torrent/star/delete.html.twig

55
src/Controller/ActivityController.php

@ -596,6 +596,61 @@ class ActivityController extends AbstractController @@ -596,6 +596,61 @@ class ActivityController extends AbstractController
break;
/// Torrent star
case $activity::EVENT_TORRENT_STAR_ADD:
return $this->render(
'default/activity/event/torrent/star/add.html.twig',
[
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
)->getName()
]
]
);
break;
case $activity::EVENT_TORRENT_STAR_DELETE:
return $this->render(
'default/activity/event/torrent/star/delete.html.twig',
[
'added' => $activity->getAdded(),
'user' =>
[
'id' => $activity->getUserId(),
'identicon' => $userService->identicon(
$userService->getUser(
$activity->getUserId()
)->getAddress()
)
],
'torrent' =>
[
'id' => $activity->getTorrentId(),
'name' => $torrentService->readTorrentFileByTorrentId(
$activity->getTorrentId()
)->getName()
]
]
);
break;
// Page
default:

24
src/Controller/TorrentController.php

@ -1005,7 +1005,8 @@ class TorrentController extends AbstractController @@ -1005,7 +1005,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
TorrentService $torrentService
TorrentService $torrentService,
ActivityService $activityService
): Response
{
// Init user
@ -1028,12 +1029,31 @@ class TorrentController extends AbstractController @@ -1028,12 +1029,31 @@ class TorrentController extends AbstractController
}
// Update
$torrentService->toggleTorrentStar(
$value = $torrentService->toggleTorrentStar(
$torrent->getId(),
$user->getId(),
time()
);
// Register activity event
if ($value)
{
$activityService->addEventTorrentStarAdd(
$user->getId(),
time(),
$torrent->getId()
);
}
else
{
$activityService->addEventTorrentStarDelete(
$user->getId(),
time(),
$torrent->getId()
);
}
// Redirect to info article created
return $this->redirectToRoute(
'torrent_info',

7
src/Entity/Activity.php

@ -47,9 +47,12 @@ class Activity @@ -47,9 +47,12 @@ class Activity
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 20210;
public const EVENT_TORRENT_SENSITIVE_APPROVE_DELETE = 20211;
public const EVENT_TORRENT_DOWNLOAD_FILE_ADD = 20300;
public const EVENT_TORRENT_STAR_ADD = 20300;
public const EVENT_TORRENT_STAR_DELETE = 20310;
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 20400;
public const EVENT_TORRENT_DOWNLOAD_FILE_ADD = 20400;
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 20500;
/// Article
public const EVENT_ARTICLE_ADD = 30000;

64
src/Service/ActivityService.php

@ -55,6 +55,7 @@ class ActivityService @@ -55,6 +55,7 @@ class ActivityService
return $activity;
}
/// User star
public function addEventUserStarAdd(
int $userId,
int $added,
@ -64,7 +65,7 @@ class ActivityService @@ -64,7 +65,7 @@ class ActivityService
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_USER_STAR_DELETE
Activity::EVENT_USER_STAR_ADD
);
$activity->setUserId(
@ -121,6 +122,67 @@ class ActivityService @@ -121,6 +122,67 @@ class ActivityService
// Torrent
/// Torrent star
public function addEventTorrentStarAdd(
int $userId,
int $added,
int $torrentId
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_STAR_ADD
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
public function addEventTorrentStarDelete(
int $userId,
int $added,
int $torrentId
): ?Activity
{
$activity = new Activity();
$activity->setEvent(
Activity::EVENT_TORRENT_STAR_DELETE
);
$activity->setUserId(
$userId
);
$activity->setTorrentId(
$torrentId
);
$activity->setAdded(
$added
);
$this->entityManagerInterface->persist($activity);
$this->entityManagerInterface->flush();
return $activity;
}
/// Torrent locales
public function addEventTorrentLocalesAdd(
int $userId,

6
src/Service/TorrentService.php

@ -582,12 +582,14 @@ class TorrentService @@ -582,12 +582,14 @@ class TorrentService
int $torrentId,
int $userId,
int $added
): void
): bool
{
if ($torrentStar = $this->findTorrentStar($torrentId, $userId))
{
$this->entityManagerInterface->remove($torrentStar);
$this->entityManagerInterface->flush();
return false;
}
else
@ -600,6 +602,8 @@ class TorrentService @@ -600,6 +602,8 @@ class TorrentService
$this->entityManagerInterface->persist($torrentStar);
$this->entityManagerInterface->flush();
return true;
}
}

12
templates/default/activity/event/torrent/star/add.html.twig

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
<a href="{{ path('user_info', { userId : user.id }) }}">
<img class="border-radius-50 border-color-default vertical-align-middle" src="{{ user.identicon }}" alt="{{ 'identicon' | trans }}" />
</a>
<span class="margin-x-4-px">
{{ 'add star to torrent' | trans }}
</span>
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
<div class="float-right">
{{ added | format_ago }}
</div>

12
templates/default/activity/event/torrent/star/delete.html.twig

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
<a href="{{ path('user_info', { userId : user.id }) }}">
<img class="border-radius-50 border-color-default vertical-align-middle" src="{{ user.identicon }}" alt="{{ 'identicon' | trans }}" />
</a>
<span class="margin-x-4-px">
{{ 'removed star from torrent' | trans }}
</span>
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
<div class="float-right">
{{ added | format_ago }}
</div>
Loading…
Cancel
Save