From 706ea40eecac7ac61ba1842065fcefdf27f89e08 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 30 Oct 2023 05:14:46 +0200 Subject: [PATCH] add poster event support #18 --- src/Controller/ActivityController.php | 213 ++++++++++++++++++ src/Controller/TorrentController.php | 14 -- src/Entity/Activity.php | 5 + src/Service/ActivityService.php | 203 +++++++++++++++++ .../event/torrent/poster/add.html.twig | 39 ++++ .../event/torrent/poster/add.rss.twig | 26 +++ .../torrent/poster/approve/add.html.twig | 39 ++++ .../event/torrent/poster/approve/add.rss.twig | 26 +++ .../torrent/poster/approve/delete.html.twig | 39 ++++ .../torrent/poster/approve/delete.rss.twig | 26 +++ .../event/torrent/poster/delete.html.twig | 39 ++++ .../event/torrent/poster/delete.rss.twig | 26 +++ 12 files changed, 681 insertions(+), 14 deletions(-) create mode 100644 templates/default/activity/event/torrent/poster/add.html.twig create mode 100644 templates/default/activity/event/torrent/poster/add.rss.twig create mode 100644 templates/default/activity/event/torrent/poster/approve/add.html.twig create mode 100644 templates/default/activity/event/torrent/poster/approve/add.rss.twig create mode 100644 templates/default/activity/event/torrent/poster/approve/delete.html.twig create mode 100644 templates/default/activity/event/torrent/poster/approve/delete.rss.twig create mode 100644 templates/default/activity/event/torrent/poster/delete.html.twig create mode 100644 templates/default/activity/event/torrent/poster/delete.rss.twig 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 @@ +
+
+ + {{ 'identicon' | trans }} + + {{ 'have added poster edition' | trans }} + {% if torrent.poster.exist %} + + #{{ torrent.poster.id }} + + {% else %} + #{{ torrent.poster.id }} + {% endif %} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %} +
+
+ {{ added | format_ago }} +
+
\ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/add.rss.twig b/templates/default/activity/event/torrent/poster/add.rss.twig new file mode 100644 index 0000000..348e851 --- /dev/null +++ b/templates/default/activity/event/torrent/poster/add.rss.twig @@ -0,0 +1,26 @@ + + + {{ 'User' | trans }} + #{{ user.id }} + {{ 'have added poster edition' | trans }} + #{{ torrent.poster.id }} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + {{ torrent.name }} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + {{ torrent.name }} + {% endif %} + {% endif %} + + #{{ user.id }} + {{ added | date('D, d M Y h:i:s O') }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity + \ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/approve/add.html.twig b/templates/default/activity/event/torrent/poster/approve/add.html.twig new file mode 100644 index 0000000..35685c0 --- /dev/null +++ b/templates/default/activity/event/torrent/poster/approve/add.html.twig @@ -0,0 +1,39 @@ +
+
+ + {{ 'identicon' | trans }} + + {{ 'have approved poster edition' | trans }} + {% if torrent.poster.exist %} + + #{{ torrent.poster.id }} + + {% else %} + #{{ torrent.poster.id }} + {% endif %} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %} +
+
+ {{ added | format_ago }} +
+
\ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/approve/add.rss.twig b/templates/default/activity/event/torrent/poster/approve/add.rss.twig new file mode 100644 index 0000000..3a75b3d --- /dev/null +++ b/templates/default/activity/event/torrent/poster/approve/add.rss.twig @@ -0,0 +1,26 @@ + + + {{ 'User' | trans }} + #{{ user.id }} + {{ 'have approved poster edition' | trans }} + #{{ torrent.poster.id }} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + {{ torrent.name }} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + {{ torrent.name }} + {% endif %} + {% endif %} + + #{{ user.id }} + {{ added | date('D, d M Y h:i:s O') }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity + \ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/approve/delete.html.twig b/templates/default/activity/event/torrent/poster/approve/delete.html.twig new file mode 100644 index 0000000..483a79f --- /dev/null +++ b/templates/default/activity/event/torrent/poster/approve/delete.html.twig @@ -0,0 +1,39 @@ +
+
+ + {{ 'identicon' | trans }} + + {{ 'have disapproved poster edition' | trans }} + {% if torrent.poster.exist %} + + #{{ torrent.poster.id }} + + {% else %} + #{{ torrent.poster.id }} + {% endif %} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %} +
+
+ {{ added | format_ago }} +
+
\ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/approve/delete.rss.twig b/templates/default/activity/event/torrent/poster/approve/delete.rss.twig new file mode 100644 index 0000000..42d6527 --- /dev/null +++ b/templates/default/activity/event/torrent/poster/approve/delete.rss.twig @@ -0,0 +1,26 @@ + + + {{ 'User' | trans }} + #{{ user.id }} + {{ 'have disapproved poster edition' | trans }} + #{{ torrent.poster.id }} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + {{ torrent.name }} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + {{ torrent.name }} + {% endif %} + {% endif %} + + #{{ user.id }} + {{ added | date('D, d M Y h:i:s O') }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }} + {{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity + \ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/delete.html.twig b/templates/default/activity/event/torrent/poster/delete.html.twig new file mode 100644 index 0000000..1b920a7 --- /dev/null +++ b/templates/default/activity/event/torrent/poster/delete.html.twig @@ -0,0 +1,39 @@ +
+
+ + {{ 'identicon' | trans }} + + {{ 'have deleted poster edition' | trans }} + {% if torrent.poster.exist %} + + #{{ torrent.poster.id }} + + {% else %} + #{{ torrent.sensitive.id }} + {% endif %} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + + {{ torrent.name }} + + {% if torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% endif %} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + + {{ torrent.name }} + + {% endif %} + {% endif %} +
+
+ {{ added | format_ago }} +
+
\ No newline at end of file diff --git a/templates/default/activity/event/torrent/poster/delete.rss.twig b/templates/default/activity/event/torrent/poster/delete.rss.twig new file mode 100644 index 0000000..4b7bf6a --- /dev/null +++ b/templates/default/activity/event/torrent/poster/delete.rss.twig @@ -0,0 +1,26 @@ + + + {{ 'User' | trans }} + #{{ user.id }} + {{ 'have deleted poster edition' | trans }} + #{{ torrent.poster.id }} + {{ 'for torrent' | trans }} + {% if session.user.moderator or session.user.owner %} + {{ torrent.name }} + {% else %} + {% if torrent.status == false %} + #{{ torrent.id }} ({{ 'disabled' | trans }}) + {% elseif torrent.approved == false %} + #{{ torrent.id }} ({{ 'waiting for approve' | trans }}) + {% elseif torrent.sensitive == true and session.user.sensitive == true %} + #{{ torrent.id }} + {% else %} + {{ torrent.name }} + {% endif %} + {% endif %} + + #{{ user.id }} + {{ added | date('D, d M Y h:i:s O') }} + {{ url('torrent_poster_edit', { torrentId : torrent.id }) }}#activity-{{ id }} + {{ url('torrent_poster_edit', { torrentId : torrent.id }) }}#activity + \ No newline at end of file