mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-22 12:44:25 +00:00
add torrent star event support #4
This commit is contained in:
parent
ef84fefca3
commit
a3dd5a81a9
@ -596,6 +596,61 @@ class ActivityController extends AbstractController
|
|||||||
|
|
||||||
break;
|
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
|
// Page
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1005,7 +1005,8 @@ class TorrentController extends AbstractController
|
|||||||
Request $request,
|
Request $request,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
UserService $userService,
|
UserService $userService,
|
||||||
TorrentService $torrentService
|
TorrentService $torrentService,
|
||||||
|
ActivityService $activityService
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
// Init user
|
// Init user
|
||||||
@ -1028,12 +1029,31 @@ class TorrentController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
$torrentService->toggleTorrentStar(
|
$value = $torrentService->toggleTorrentStar(
|
||||||
$torrent->getId(),
|
$torrent->getId(),
|
||||||
$user->getId(),
|
$user->getId(),
|
||||||
time()
|
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
|
// Redirect to info article created
|
||||||
return $this->redirectToRoute(
|
return $this->redirectToRoute(
|
||||||
'torrent_info',
|
'torrent_info',
|
||||||
|
@ -47,9 +47,12 @@ class Activity
|
|||||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 20210;
|
public const EVENT_TORRENT_SENSITIVE_APPROVE_ADD = 20210;
|
||||||
public const EVENT_TORRENT_SENSITIVE_APPROVE_DELETE = 20211;
|
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
|
/// Article
|
||||||
public const EVENT_ARTICLE_ADD = 30000;
|
public const EVENT_ARTICLE_ADD = 30000;
|
||||||
|
@ -55,6 +55,7 @@ class ActivityService
|
|||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// User star
|
||||||
public function addEventUserStarAdd(
|
public function addEventUserStarAdd(
|
||||||
int $userId,
|
int $userId,
|
||||||
int $added,
|
int $added,
|
||||||
@ -64,7 +65,7 @@ class ActivityService
|
|||||||
$activity = new Activity();
|
$activity = new Activity();
|
||||||
|
|
||||||
$activity->setEvent(
|
$activity->setEvent(
|
||||||
Activity::EVENT_USER_STAR_DELETE
|
Activity::EVENT_USER_STAR_ADD
|
||||||
);
|
);
|
||||||
|
|
||||||
$activity->setUserId(
|
$activity->setUserId(
|
||||||
@ -121,6 +122,67 @@ class ActivityService
|
|||||||
|
|
||||||
// Torrent
|
// 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
|
/// Torrent locales
|
||||||
public function addEventTorrentLocalesAdd(
|
public function addEventTorrentLocalesAdd(
|
||||||
int $userId,
|
int $userId,
|
||||||
|
@ -582,12 +582,14 @@ class TorrentService
|
|||||||
int $torrentId,
|
int $torrentId,
|
||||||
int $userId,
|
int $userId,
|
||||||
int $added
|
int $added
|
||||||
): void
|
): bool
|
||||||
{
|
{
|
||||||
if ($torrentStar = $this->findTorrentStar($torrentId, $userId))
|
if ($torrentStar = $this->findTorrentStar($torrentId, $userId))
|
||||||
{
|
{
|
||||||
$this->entityManagerInterface->remove($torrentStar);
|
$this->entityManagerInterface->remove($torrentStar);
|
||||||
$this->entityManagerInterface->flush();
|
$this->entityManagerInterface->flush();
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -600,6 +602,8 @@ class TorrentService
|
|||||||
|
|
||||||
$this->entityManagerInterface->persist($torrentStar);
|
$this->entityManagerInterface->persist($torrentStar);
|
||||||
$this->entityManagerInterface->flush();
|
$this->entityManagerInterface->flush();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
templates/default/activity/event/torrent/star/add.html.twig
Normal file
12
templates/default/activity/event/torrent/star/add.html.twig
Normal file
@ -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>
|
@ -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…
x
Reference in New Issue
Block a user