diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php index 06bdec1..5bdec65 100644 --- a/src/Controller/ActivityController.php +++ b/src/Controller/ActivityController.php @@ -1329,6 +1329,219 @@ class ActivityController extends AbstractController break; + /// Torrent Poster + case $activity::EVENT_TORRENT_POSTER_ADD: + + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + + return $this->render( + 'default/activity/event/torrent/poster/add' . $extension, + [ + 'id' => $activity->getId(), + 'added' => $activity->getAdded(), + 'user' => + [ + 'id' => $activity->getUserId(), + 'identicon' => $userService->identicon( + $userService->getUser( + $activity->getUserId() + )->getAddress() + ) + ], + 'torrent' => + [ + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'status' => $torrent->isStatus(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() + )->getName(), + 'poster' => [ + 'id' => $activity->getData()['torrentPosterId'], + 'exist' => $torrentService->getTorrentPoster( + $activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links + ) + ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] + ] + ] + ); + + break; + + case $activity::EVENT_TORRENT_POSTER_DELETE: + + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + + return $this->render( + 'default/activity/event/torrent/poster/delete' . $extension, + [ + 'id' => $activity->getId(), + 'added' => $activity->getAdded(), + 'user' => + [ + 'id' => $activity->getUserId(), + 'identicon' => $userService->identicon( + $userService->getUser( + $activity->getUserId() + )->getAddress() + ) + ], + 'torrent' => + [ + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'status' => $torrent->isStatus(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() + )->getName(), + 'poster' => [ + 'id' => $activity->getData()['torrentPosterId'], + 'exist' => $torrentService->getTorrentPoster( + $activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links + ) + ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] + ] + ] + ); + + break; + + case $activity::EVENT_TORRENT_POSTER_APPROVE_ADD: + + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + + return $this->render( + 'default/activity/event/torrent/poster/approve/add' . $extension, + [ + 'id' => $activity->getId(), + 'added' => $activity->getAdded(), + 'user' => + [ + 'id' => $activity->getUserId(), + 'identicon' => $userService->identicon( + $userService->getUser( + $activity->getUserId() + )->getAddress() + ) + ], + 'torrent' => + [ + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'status' => $torrent->isStatus(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() + )->getName(), + 'poster' => [ + 'id' => $activity->getData()['torrentPosterId'], + 'exist' => $torrentService->getTorrentPoster( + $activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links + ) + ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] + ] + ] + ); + + break; + + case $activity::EVENT_TORRENT_POSTER_APPROVE_DELETE: + + // Init torrent + if (!$torrent = $torrentService->getTorrent($activity->getTorrentId())) + { + throw $this->createNotFoundException(); + } + + return $this->render( + 'default/activity/event/torrent/poster/approve/delete' . $extension, + [ + 'id' => $activity->getId(), + 'added' => $activity->getAdded(), + 'user' => + [ + 'id' => $activity->getUserId(), + 'identicon' => $userService->identicon( + $userService->getUser( + $activity->getUserId() + )->getAddress() + ) + ], + 'torrent' => + [ + 'id' => $torrent->getId(), + 'sensitive' => $torrent->isSensitive(), + 'approved' => $torrent->isApproved(), + 'status' => $torrent->isStatus(), + 'name' => $torrentService->readTorrentFileByTorrentId( + $torrent->getId() + )->getName(), + 'poster' => [ + 'id' => $activity->getData()['torrentPosterId'], + 'exist' => $torrentService->getTorrentPoster( + $activity->getData()['torrentPosterId'] // could be deleted by moderator, remove links + ) + ] + ], + 'session' => + [ + 'user' => + [ + 'id' => $user->getId(), + 'sensitive' => $user->isSensitive(), + 'moderator' => $user->isModerator(), + 'owner' => $user->getId() === $torrent->getUserId(), + ] + ] + ] + ); + + break; + /// Torrent star case $activity::EVENT_TORRENT_STAR_ADD: diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index f5c02d9..d4bb509 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -1979,14 +1979,12 @@ class TorrentController extends AbstractController ); // Add activity event - /* @TODO $activityService->addEventTorrentPosterAdd( $user->getId(), $torrent->getId(), time(), $torrentPoster->getId() ); - */ // Redirect to info page created return $this->redirectToRoute( @@ -2068,26 +2066,22 @@ class TorrentController extends AbstractController // Add activity event if (!$torrentPoster->isApproved()) { - /* @TODO $activityService->addEventTorrentPosterApproveAdd( $user->getId(), $torrent->getId(), time(), $torrentPoster->getId() ); - */ } else { - /* @TODO $activityService->addEventTorrentPosterApproveDelete( $user->getId(), $torrent->getId(), time(), $torrentPoster->getId() ); - */ } // Update approved @@ -2157,14 +2151,12 @@ class TorrentController extends AbstractController } // Add activity event - /* @TODO $activityService->addEventTorrentPosterDelete( $user->getId(), $torrent->getId(), time(), $torrentPoster->getId() ); - */ // Update approved $torrentService->deleteTorrentPoster( @@ -2182,12 +2174,6 @@ class TorrentController extends AbstractController ); } - - - - - - // Torrent star #[Route( '/{_locale}/torrent/{torrentId}/star/toggle', diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index 233ab46..1102a03 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -62,6 +62,11 @@ class Activity public const EVENT_TORRENT_STATUS_ADD = 1800; public const EVENT_TORRENT_STATUS_DELETE = 1801; + public const EVENT_TORRENT_POSTER_ADD = 2800; + public const EVENT_TORRENT_POSTER_DELETE = 2801; + public const EVENT_TORRENT_POSTER_APPROVE_ADD = 2810; + public const EVENT_TORRENT_POSTER_APPROVE_DELETE = 2811; + // ... #[ORM\Column] diff --git a/src/Service/ActivityService.php b/src/Service/ActivityService.php index d7dfb5a..89c99e7 100644 --- a/src/Service/ActivityService.php +++ b/src/Service/ActivityService.php @@ -56,6 +56,11 @@ class ActivityService Activity::EVENT_TORRENT_SENSITIVE_APPROVE_ADD, Activity::EVENT_TORRENT_SENSITIVE_APPROVE_DELETE, + Activity::EVENT_TORRENT_POSTER_ADD, + Activity::EVENT_TORRENT_POSTER_DELETE, + Activity::EVENT_TORRENT_POSTER_APPROVE_ADD, + Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE, + Activity::EVENT_TORRENT_STAR_ADD, Activity::EVENT_TORRENT_STAR_DELETE, @@ -321,6 +326,55 @@ class ActivityService break; + /// Torrent poster + case Activity::EVENT_TORRENT_POSTER_ADD: + + $events + [ + $this->translatorInterface->trans('Torrent poster') + ] + [ + $this->translatorInterface->trans('Added') + ] = $code; + + break; + + case Activity::EVENT_TORRENT_POSTER_DELETE: + + $events + [ + $this->translatorInterface->trans('Torrent poster') + ] + [ + $this->translatorInterface->trans('Deleted') + ] = $code; + + break; + + case Activity::EVENT_TORRENT_POSTER_APPROVE_ADD: + + $events + [ + $this->translatorInterface->trans('Torrent poster') + ] + [ + $this->translatorInterface->trans('Approved') + ] = $code; + + break; + + case Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE: + + $events + [ + $this->translatorInterface->trans('Torrent poster') + ] + [ + $this->translatorInterface->trans('Disapproved') + ] = $code; + + break; + /// Torrent stars case Activity::EVENT_TORRENT_STAR_ADD: @@ -1397,4 +1451,153 @@ class ActivityService return $activity; } + + /// Torrent poster + public function addEventTorrentPosterAdd( + int $userId, + int $torrentId, + int $added, + int $torrentPosterId, + ): ?Activity + { + $activity = new Activity(); + + $activity->setEvent( + Activity::EVENT_TORRENT_POSTER_ADD + ); + + $activity->setUserId( + $userId + ); + + $activity->setTorrentId( + $torrentId + ); + + $activity->setAdded( + $added + ); + + $activity->setData( + [ + 'torrentPosterId' => $torrentPosterId + ] + ); + + $this->entityManagerInterface->persist($activity); + $this->entityManagerInterface->flush(); + + return $activity; + } + + public function addEventTorrentPosterDelete( + int $userId, + int $torrentId, + int $added, + int $torrentPosterId, + ): ?Activity + { + $activity = new Activity(); + + $activity->setEvent( + Activity::EVENT_TORRENT_POSTER_DELETE + ); + + $activity->setUserId( + $userId + ); + + $activity->setTorrentId( + $torrentId + ); + + $activity->setAdded( + $added + ); + + $activity->setData( + [ + 'torrentPosterId' => $torrentPosterId + ] + ); + + $this->entityManagerInterface->persist($activity); + $this->entityManagerInterface->flush(); + + return $activity; + } + + public function addEventTorrentPosterApproveAdd( + int $userId, + int $torrentId, + int $added, + int $torrentPosterId, + ): ?Activity + { + $activity = new Activity(); + + $activity->setEvent( + Activity::EVENT_TORRENT_POSTER_APPROVE_ADD + ); + + $activity->setUserId( + $userId + ); + + $activity->setTorrentId( + $torrentId + ); + + $activity->setAdded( + $added + ); + + $activity->setData( + [ + 'torrentPosterId' => $torrentPosterId + ] + ); + + $this->entityManagerInterface->persist($activity); + $this->entityManagerInterface->flush(); + + return $activity; + } + + public function addEventTorrentPosterApproveDelete( + int $userId, + int $torrentId, + int $added, + int $torrentPosterId, + ): ?Activity + { + $activity = new Activity(); + + $activity->setEvent( + Activity::EVENT_TORRENT_POSTER_APPROVE_DELETE + ); + + $activity->setUserId( + $userId + ); + + $activity->setTorrentId( + $torrentId + ); + + $activity->setAdded( + $added + ); + + $activity->setData( + [ + 'torrentPosterId' => $torrentPosterId + ] + ); + + $this->entityManagerInterface->persist($activity); + $this->entityManagerInterface->flush(); + + return $activity; + } } \ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/add.html.twig b/templates/default/activity/event/torrent/poster/add.html.twig new file mode 100644 index 0000000..519a6f0 --- /dev/null +++ b/templates/default/activity/event/torrent/poster/add.html.twig @@ -0,0 +1,39 @@ +