diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php index 98c9939..0017c5f 100644 --- a/src/Controller/ActivityController.php +++ b/src/Controller/ActivityController.php @@ -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: diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index 02bb81f..a8e01be 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -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 } // 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', diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index ba9ca71..43de349 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -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; diff --git a/src/Service/ActivityService.php b/src/Service/ActivityService.php index 7cd25ee..9db22e3 100644 --- a/src/Service/ActivityService.php +++ b/src/Service/ActivityService.php @@ -55,6 +55,7 @@ class ActivityService return $activity; } + /// User star public function addEventUserStarAdd( int $userId, int $added, @@ -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 // 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, diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 14eaa10..7275f1d 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -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 $this->entityManagerInterface->persist($torrentStar); $this->entityManagerInterface->flush(); + + return true; } } diff --git a/templates/default/activity/event/torrent/star/add.html.twig b/templates/default/activity/event/torrent/star/add.html.twig new file mode 100644 index 0000000..e133684 --- /dev/null +++ b/templates/default/activity/event/torrent/star/add.html.twig @@ -0,0 +1,12 @@ + + {{ 'identicon' | trans }} + + +{{ 'add star to torrent' | trans }} + + + {{ torrent.name }} + +
+ {{ added | format_ago }} +
\ No newline at end of file diff --git a/templates/default/activity/event/torrent/star/delete.html.twig b/templates/default/activity/event/torrent/star/delete.html.twig new file mode 100644 index 0000000..cfdcc38 --- /dev/null +++ b/templates/default/activity/event/torrent/star/delete.html.twig @@ -0,0 +1,12 @@ + + {{ 'identicon' | trans }} + + +{{ 'removed star from torrent' | trans }} + + + {{ torrent.name }} + +
+ {{ added | format_ago }} +
\ No newline at end of file