diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php
new file mode 100644
index 0000000..98c9939
--- /dev/null
+++ b/src/Controller/ActivityController.php
@@ -0,0 +1,620 @@
+getEvent())
+ {
+ // User
+ case $activity::EVENT_USER_ADD:
+
+ return $this->render(
+ 'default/activity/event/user/add.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_APPROVE_ADD:
+
+ return $this->render(
+ 'default/activity/event/user/approve/add.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_APPROVE_DELETE:
+
+ return $this->render(
+ 'default/activity/event/user/approve/delete.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_MODERATOR_ADD:
+
+ return $this->render(
+ 'default/activity/event/user/moderator/add.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_MODERATOR_DELETE:
+
+ return $this->render(
+ 'default/activity/event/user/moderator/delete.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_STATUS_ADD:
+
+ return $this->render(
+ 'default/activity/event/user/status/add.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_STATUS_DELETE:
+
+ return $this->render(
+ 'default/activity/event/user/status/delete.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_STAR_ADD:
+
+ return $this->render(
+ 'default/activity/event/user/star/add.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_USER_STAR_DELETE:
+
+ return $this->render(
+ 'default/activity/event/user/star/delete.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ],
+ 'by' =>
+ [
+ 'user' =>
+ [
+ 'id' => $activity->getData()['userId'],
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getData()['userId']
+ )->getAddress()
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ // Torrent
+ case $activity::EVENT_TORRENT_ADD:
+
+ return $this->render(
+ 'default/activity/event/torrent/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;
+
+ /// Torrent Locales
+ case $activity::EVENT_TORRENT_LOCALES_ADD:
+
+ return $this->render(
+ 'default/activity/event/torrent/locales/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(),
+ 'locales' => [
+ 'id' => $activity->getData()['torrentLocalesId'],
+ 'exist' => $torrentService->getTorrentLocales(
+ $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_LOCALES_DELETE:
+
+ return $this->render(
+ 'default/activity/event/torrent/locales/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(),
+ 'locales' => [
+ 'id' => $activity->getData()['torrentLocalesId'],
+ 'exist' => $torrentService->getTorrentLocales(
+ $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_LOCALES_APPROVE_ADD:
+
+ return $this->render(
+ 'default/activity/event/torrent/locales/approve/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(),
+ 'locales' => [
+ 'id' => $activity->getData()['torrentLocalesId'],
+ 'exist' => $torrentService->getTorrentLocales(
+ $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_LOCALES_APPROVE_DELETE:
+
+ return $this->render(
+ 'default/activity/event/torrent/locales/approve/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(),
+ 'locales' => [
+ 'id' => $activity->getData()['torrentLocalesId'],
+ 'exist' => $torrentService->getTorrentLocales(
+ $activity->getData()['torrentLocalesId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ /// Torrent Sensitive
+ case $activity::EVENT_TORRENT_SENSITIVE_ADD:
+
+ return $this->render(
+ 'default/activity/event/torrent/sensitive/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(),
+ 'sensitive' => [
+ 'id' => $activity->getData()['torrentSensitiveId'],
+ 'exist' => $torrentService->getTorrentSensitive(
+ $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_SENSITIVE_DELETE:
+
+ return $this->render(
+ 'default/activity/event/torrent/sensitive/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(),
+ 'sensitive' => [
+ 'id' => $activity->getData()['torrentSensitiveId'],
+ 'exist' => $torrentService->getTorrentSensitive(
+ $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_SENSITIVE_APPROVE_ADD:
+
+ return $this->render(
+ 'default/activity/event/torrent/sensitive/approve/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(),
+ 'sensitive' => [
+ 'id' => $activity->getData()['torrentSensitiveId'],
+ 'exist' => $torrentService->getTorrentSensitive(
+ $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ case $activity::EVENT_TORRENT_SENSITIVE_APPROVE_DELETE:
+
+ return $this->render(
+ 'default/activity/event/torrent/sensitive/approve/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(),
+ 'sensitive' => [
+ 'id' => $activity->getData()['torrentSensitiveId'],
+ 'exist' => $torrentService->getTorrentSensitive(
+ $activity->getData()['torrentSensitiveId'] // could be deleted by moderator, remove links
+ )
+ ]
+ ]
+ ]
+ );
+
+ break;
+
+ // Page
+
+ default:
+
+ return $this->render(
+ 'default/activity/event/undefined.html.twig',
+ [
+ 'added' => $activity->getAdded(),
+ 'user' =>
+ [
+ 'id' => $activity->getUserId(),
+ 'identicon' => $userService->identicon(
+ $userService->getUser(
+ $activity->getUserId()
+ )->getAddress()
+ )
+ ]
+ ]
+ );
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php
index e2b3281..02bb81f 100644
--- a/src/Controller/TorrentController.php
+++ b/src/Controller/TorrentController.php
@@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request;
use App\Service\UserService;
use App\Service\TorrentService;
+use App\Service\ActivityService;
class TorrentController extends AbstractController
{
@@ -332,7 +333,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService
): Response
{
// Init user
@@ -463,7 +465,7 @@ class TorrentController extends AbstractController
if (empty($form['locales']['error']))
{
// Save data
- $torrentService->addTorrentLocales(
+ $torrentLocales = $torrentService->addTorrentLocales(
$torrent->getId(),
$user->getId(),
time(),
@@ -471,6 +473,14 @@ class TorrentController extends AbstractController
$user->isApproved()
);
+ // Register activity event
+ $activityService->addEventTorrentLocalesAdd(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentLocales->getId()
+ );
+
// Redirect to info article created
return $this->redirectToRoute(
'torrent_info',
@@ -516,7 +526,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService,
): Response
{
// Init user
@@ -545,6 +556,27 @@ class TorrentController extends AbstractController
);
}
+ // Register activity event
+ if (!$torrentLocales->isApproved())
+ {
+ $activityService->addEventTorrentLocalesApproveAdd(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentLocales->getId()
+ );
+ }
+
+ else
+ {
+ $activityService->addEventTorrentLocalesApproveDelete(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentLocales->getId()
+ );
+ }
+
// Update approved
$torrentService->toggleTorrentLocalesApproved(
$torrentLocales->getId()
@@ -578,7 +610,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService
): Response
{
// Init user
@@ -607,6 +640,14 @@ class TorrentController extends AbstractController
);
}
+ // Add activity event
+ $activityService->addEventTorrentLocalesDelete(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentLocales->getId()
+ );
+
// Update approved
$torrentService->deleteTorrentLocales(
$torrentLocales->getId()
@@ -646,7 +687,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService
): Response
{
// Init user
@@ -749,7 +791,7 @@ class TorrentController extends AbstractController
if ($request->isMethod('post'))
{
// Save data
- $torrentService->addTorrentSensitive(
+ $torrentSensitive = $torrentService->addTorrentSensitive(
$torrent->getId(),
$user->getId(),
time(),
@@ -757,6 +799,14 @@ class TorrentController extends AbstractController
$user->isApproved()
);
+ // Add activity event
+ $activityService->addEventTorrentSensitiveAdd(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentSensitive->getId()
+ );
+
// Redirect to info article created
return $this->redirectToRoute(
'torrent_info',
@@ -800,7 +850,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService
): Response
{
// Init user
@@ -829,6 +880,27 @@ class TorrentController extends AbstractController
);
}
+ // Add activity event
+ if (!$torrentSensitive->isApproved())
+ {
+ $activityService->addEventTorrentSensitiveApproveAdd(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentSensitive->getId()
+ );
+ }
+
+ else
+ {
+ $activityService->addEventTorrentSensitiveApproveDelete(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentSensitive->getId()
+ );
+ }
+
// Update approved
$torrentService->toggleTorrentSensitiveApproved(
$torrentSensitive->getId()
@@ -862,7 +934,8 @@ class TorrentController extends AbstractController
Request $request,
TranslatorInterface $translator,
UserService $userService,
- TorrentService $torrentService
+ TorrentService $torrentService,
+ ActivityService $activityService
): Response
{
// Init user
@@ -891,6 +964,14 @@ class TorrentController extends AbstractController
);
}
+ // Add activity event
+ $activityService->addEventTorrentSensitiveDelete(
+ $user->getId(),
+ $torrent->getId(),
+ time(),
+ $torrentSensitive->getId()
+ );
+
// Update approved
$torrentService->deleteTorrentSensitive(
$torrentSensitive->getId()
diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php
index 425cbe5..0ce686a 100644
--- a/src/Controller/UserController.php
+++ b/src/Controller/UserController.php
@@ -44,46 +44,10 @@ class UserController extends AbstractController
UserService $userService
): Response
{
- // Init user session
- $user = $userService->init(
- $request->getClientIp()
- );
-
- // Build activity history
- $activities = [];
-
- /*
- foreach ($activityService->findLast($user->isModerator()) as $activity)
- {
- if (!$activity->getUserId())
- {
- continue;
- }
-
- $activityUser = $userService->getUser(
- $activity->getUserId()
- );
-
- $activities[] =
- [
- 'user' =>
- [
- 'id' => $activityUser->getId(),
- 'identicon' => $userService->identicon(
- $activityUser->getAddress(),
- 24
- )
- ],
- 'type' => 'join',
- 'added' => $activity->getAdded()
- ];
- }
- */
-
return $this->render(
'default/user/dashboard.html.twig',
[
- 'activities' => $activities
+ 'activities' => $activityService->findLastActivities()
]
);
}
@@ -271,7 +235,8 @@ class UserController extends AbstractController
public function toggleStar(
Request $request,
TranslatorInterface $translator,
- UserService $userService
+ UserService $userService,
+ ActivityService $activityService,
): Response
{
// Init user
@@ -294,12 +259,31 @@ class UserController extends AbstractController
}
// Update
- $userService->toggleUserStar(
+ $value = $userService->toggleUserStar(
$user->getId(),
$userTarget->getId(),
time()
);
+ // Add activity event
+ if ($value)
+ {
+ $activityService->addEventUserStarAdd(
+ $user->getId(),
+ time(),
+ $userTarget->getId()
+ );
+ }
+
+ else
+ {
+ $activityService->addEventUserStarDelete(
+ $user->getId(),
+ time(),
+ $userTarget->getId()
+ );
+ }
+
// Redirect to info article created
return $this->redirectToRoute(
'user_info',
diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php
index 2b370ab..ba9ca71 100644
--- a/src/Entity/Activity.php
+++ b/src/Entity/Activity.php
@@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\ActivityRepository;
+use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ActivityRepository::class)]
@@ -13,18 +14,62 @@ class Activity
#[ORM\Column]
private ?int $id = null;
- #[ORM\Column(length: 255)]
- private ?string $event = null;
+ #[ORM\Column]
+ private ?int $event = null;
+
+ // Event codes
+
+ /// User
+ public const EVENT_USER_ADD = 10000;
+
+ public const EVENT_USER_APPROVE_ADD = 10200;
+ public const EVENT_USER_APPROVE_DELETE = 10210;
+
+ public const EVENT_USER_MODERATOR_ADD = 10300;
+ public const EVENT_USER_MODERATOR_DELETE = 10310;
+
+ public const EVENT_USER_STATUS_ADD = 10400;
+ public const EVENT_USER_STATUS_DELETE = 10410;
+
+ public const EVENT_USER_STAR_ADD = 10500;
+ public const EVENT_USER_STAR_DELETE = 10510;
+
+ /// Torrent
+ public const EVENT_TORRENT_ADD = 20000;
+
+ public const EVENT_TORRENT_LOCALES_ADD = 20100;
+ public const EVENT_TORRENT_LOCALES_DELETE = 20101;
+ public const EVENT_TORRENT_LOCALES_APPROVE_ADD = 20110;
+ public const EVENT_TORRENT_LOCALES_APPROVE_DELETE = 20111;
+
+ public const EVENT_TORRENT_SENSITIVE_ADD = 20200;
+ public const EVENT_TORRENT_SENSITIVE_DELETE = 20201;
+ 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_DOWNLOAD_MAGNET_ADD = 20400;
+
+ /// Article
+ public const EVENT_ARTICLE_ADD = 30000;
+ // ...
#[ORM\Column]
- private ?int $added = null;
-
- #[ORM\Column(nullable: true)]
private ?int $userId = null;
#[ORM\Column(nullable: true)]
private ?int $articleId = null;
+ #[ORM\Column(nullable: true)]
+ private ?int $torrentId = null;
+
+ #[ORM\Column]
+ private ?int $added = null;
+
+ #[ORM\Column(type: Types::ARRAY)]
+ private array $data = [];
+
public function getId(): ?int
{
return $this->id;
@@ -37,37 +82,18 @@ class Activity
return $this;
}
- public function getEvent(): ?string
+ public function getEvent(): ?int
{
return $this->event;
}
- public function setEvent(string $event): static
+ public function setEvent(int $event): static
{
$this->event = $event;
return $this;
}
- public function getAdded(): ?int
- {
- return $this->added;
- }
-
- public function setAdded(int $added): static
- {
- $this->added = $added;
-
- return $this;
- }
-
- public function setApproved(bool $approved): static
- {
- $this->approved = $approved;
-
- return $this;
- }
-
public function getUserId(): ?int
{
return $this->userId;
@@ -85,15 +111,46 @@ class Activity
return $this->articleId;
}
- public function setArticleId(?int $articleId): static
+ public function setArticleId(int $articleId): static
{
$this->articleId = $articleId;
return $this;
}
- public function isApproved(): ?bool
+ public function getTorrentId(): ?int
{
- return $this->approved;
+ return $this->torrentId;
+ }
+
+ public function setTorrentId(?int $torrentId): static
+ {
+ $this->torrentId = $torrentId;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function getData(): array
+ {
+ return $this->data;
+ }
+
+ public function setData(array $data): static
+ {
+ $this->data = $data;
+
+ return $this;
}
}
diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php
index 6d26c74..78d420e 100644
--- a/src/Repository/ActivityRepository.php
+++ b/src/Repository/ActivityRepository.php
@@ -20,28 +20,4 @@ class ActivityRepository extends ServiceEntityRepository
{
parent::__construct($registry, Activity::class);
}
-
- public function findLast(int $start = 0, int $limit = 10): array
- {
- return $this->createQueryBuilder('a')
- ->orderBy('a.id', 'DESC') // same to a.added
- ->setFirstResult($start)
- ->setMaxResults($limit)
- ->getQuery()
- ->getResult()
- ;
- }
-
- public function findLastByApprovedField(bool $approved, int $start = 0, int $limit = 10): array
- {
- return $this->createQueryBuilder('a')
- ->orderBy('a.id', 'DESC') // same to a.added
- ->where('a.approved = :approved')
- ->setParameter('approved', $approved)
- ->setFirstResult($start)
- ->setMaxResults($limit)
- ->getQuery()
- ->getResult()
- ;
- }
}
diff --git a/src/Service/ActivityService.php b/src/Service/ActivityService.php
index 268fb0b..7cd25ee 100644
--- a/src/Service/ActivityService.php
+++ b/src/Service/ActivityService.php
@@ -6,49 +6,416 @@ use App\Entity\Activity;
use App\Repository\ActivityRepository;
use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
-
class ActivityService
{
- private EntityManagerInterface $entityManager;
- private ActivityRepository $activityRepository;
- private ParameterBagInterface $parameterBagInterface;
+ private EntityManagerInterface $entityManagerInterface;
public function __construct(
- EntityManagerInterface $entityManager,
- ParameterBagInterface $parameterBagInterface
+ EntityManagerInterface $entityManagerInterface
)
{
- $this->entityManager = $entityManager;
- $this->activityRepository = $entityManager->getRepository(Activity::class);
- $this->parameterBagInterface = $parameterBagInterface;
+ $this->entityManagerInterface = $entityManagerInterface;
}
- public function addEvent(int $userId, string $event, array $data): ?Activity
+ public function findLastActivities(): array
+ {
+ return $this->entityManagerInterface
+ ->getRepository(Activity::class)
+ ->findBy(
+ [],
+ [
+ 'id' => 'DESC'
+ ]
+ );
+ }
+
+ // User
+ public function addEventUserJoin(
+ int $userId,
+ int $added
+ ): ?Activity
{
$activity = new Activity();
- $activity->setEvent($event);
- $activity->setUserId($userId);
- $activity->setApproved($approved);
- $activity->setAdded(time());
+ $activity->setEvent(
+ Activity::EVENT_USER_ADD
+ );
- $this->entityManager->persist($activity);
- $this->entityManager->flush();
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
return $activity;
}
- public function findLast(bool $moderator): ?array
+ public function addEventUserStarAdd(
+ int $userId,
+ int $added,
+ int $userIdTarget
+ ): ?Activity
{
- if ($moderator)
- {
- return $this->activityRepository->findLast();
- }
+ $activity = new Activity();
- else
- {
- return $this->activityRepository->findLastByApprovedField(true);
- }
+ $activity->setEvent(
+ Activity::EVENT_USER_STAR_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'userId' => $userIdTarget
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventUserStarDelete(
+ int $userId,
+ int $added,
+ int $userIdTarget
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_USER_STAR_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'userId' => $userIdTarget
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ // Torrent
+
+ /// Torrent locales
+ public function addEventTorrentLocalesAdd(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentLocalesId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_LOCALES_ADD
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentLocalesId' => $torrentLocalesId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentLocalesDelete(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentLocalesId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_LOCALES_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentLocalesId' => $torrentLocalesId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentLocalesApproveAdd(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentLocalesId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_LOCALES_APPROVE_ADD
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentLocalesId' => $torrentLocalesId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentLocalesApproveDelete(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentLocalesId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_LOCALES_APPROVE_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentLocalesId' => $torrentLocalesId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ /// Torrent sensitive
+ public function addEventTorrentSensitiveAdd(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentSensitiveId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_SENSITIVE_ADD
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentSensitiveId' => $torrentSensitiveId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentSensitiveDelete(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentSensitiveId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_SENSITIVE_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentSensitiveId' => $torrentSensitiveId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentSensitiveApproveAdd(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentSensitiveId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_SENSITIVE_APPROVE_ADD
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentSensitiveId' => $torrentSensitiveId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
+ }
+
+ public function addEventTorrentSensitiveApproveDelete(
+ int $userId,
+ int $torrentId,
+ int $added,
+ int $torrentSensitiveId,
+ ): ?Activity
+ {
+ $activity = new Activity();
+
+ $activity->setEvent(
+ Activity::EVENT_TORRENT_SENSITIVE_APPROVE_DELETE
+ );
+
+ $activity->setUserId(
+ $userId
+ );
+
+ $activity->setTorrentId(
+ $torrentId
+ );
+
+ $activity->setAdded(
+ $added
+ );
+
+ $activity->setData(
+ [
+ 'torrentSensitiveId' => $torrentSensitiveId
+ ]
+ );
+
+ $this->entityManagerInterface->persist($activity);
+ $this->entityManagerInterface->flush();
+
+ return $activity;
}
}
\ No newline at end of file
diff --git a/src/Service/UserService.php b/src/Service/UserService.php
index 3774a1c..ccbd341 100644
--- a/src/Service/UserService.php
+++ b/src/Service/UserService.php
@@ -84,6 +84,7 @@ class UserService
$user->setApproved(true);
$user->setModerator(true);
$user->setSensitive(false);
+
$this->save($user);
}
@@ -151,12 +152,14 @@ class UserService
int $userId,
int $userIdTarget,
int $added
- ): void
+ ): bool
{
if ($userStar = $this->findUserStar($userId, $userIdTarget))
{
$this->entityManagerInterface->remove($userStar);
$this->entityManagerInterface->flush();
+
+ return false;
}
else
@@ -169,6 +172,8 @@ class UserService
$this->entityManagerInterface->persist($userStar);
$this->entityManagerInterface->flush();
+
+ return true;
}
}
diff --git a/templates/default/activity/event/torrent/add.html.twig b/templates/default/activity/event/torrent/add.html.twig
new file mode 100644
index 0000000..201afff
--- /dev/null
+++ b/templates/default/activity/event/torrent/add.html.twig
@@ -0,0 +1,12 @@
+
+
+
+
+ {{ 'added torrent' | trans }}
+
+
+ {{ torrent.name }}
+
+