Browse Source

add poster event support #18

main
ghost 1 year ago
parent
commit
706ea40eec
  1. 213
      src/Controller/ActivityController.php
  2. 14
      src/Controller/TorrentController.php
  3. 5
      src/Entity/Activity.php
  4. 203
      src/Service/ActivityService.php
  5. 39
      templates/default/activity/event/torrent/poster/add.html.twig
  6. 26
      templates/default/activity/event/torrent/poster/add.rss.twig
  7. 39
      templates/default/activity/event/torrent/poster/approve/add.html.twig
  8. 26
      templates/default/activity/event/torrent/poster/approve/add.rss.twig
  9. 39
      templates/default/activity/event/torrent/poster/approve/delete.html.twig
  10. 26
      templates/default/activity/event/torrent/poster/approve/delete.rss.twig
  11. 39
      templates/default/activity/event/torrent/poster/delete.html.twig
  12. 26
      templates/default/activity/event/torrent/poster/delete.rss.twig

213
src/Controller/ActivityController.php

@ -1329,6 +1329,219 @@ class ActivityController extends AbstractController @@ -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:

14
src/Controller/TorrentController.php

@ -1979,14 +1979,12 @@ class TorrentController extends AbstractController @@ -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 @@ -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 @@ -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 @@ -2182,12 +2174,6 @@ class TorrentController extends AbstractController
);
}
// Torrent star
#[Route(
'/{_locale}/torrent/{torrentId}/star/toggle',

5
src/Entity/Activity.php

@ -62,6 +62,11 @@ class Activity @@ -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]

203
src/Service/ActivityService.php

@ -56,6 +56,11 @@ class ActivityService @@ -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 @@ -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 @@ -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;
}
}

39
templates/default/activity/event/torrent/poster/add.html.twig

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<div class="row">
<div class="column width-80">
<a class="margin-r-4-px" 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>
{{ 'have added poster edition' | trans }}
{% if torrent.poster.exist %}
<a href="{{ path('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}">
#{{ torrent.poster.id }}
</a>
{% else %}
#{{ torrent.poster.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}
</div>
</div>

26
templates/default/activity/event/torrent/poster/add.rss.twig

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
<item>
<title>
{{ '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 %}
</title>
<author>#{{ user.id }}</author>
<pubDate>{{ added | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }}</guid>
<link>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity</link>
</item>

39
templates/default/activity/event/torrent/poster/approve/add.html.twig

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<div class="row">
<div class="column width-80">
<a class="margin-r-4-px" 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>
{{ 'have approved poster edition' | trans }}
{% if torrent.poster.exist %}
<a href="{{ path('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}">
#{{ torrent.poster.id }}
</a>
{% else %}
#{{ torrent.poster.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}
</div>
</div>

26
templates/default/activity/event/torrent/poster/approve/add.rss.twig

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
<item>
<title>
{{ '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 %}
</title>
<author>#{{ user.id }}</author>
<pubDate>{{ added | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }}</guid>
<link>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity</link>
</item>

39
templates/default/activity/event/torrent/poster/approve/delete.html.twig

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<div class="row">
<div class="column width-80">
<a class="margin-r-4-px" 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>
{{ 'have disapproved poster edition' | trans }}
{% if torrent.poster.exist %}
<a href="{{ path('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}">
#{{ torrent.poster.id }}
</a>
{% else %}
#{{ torrent.poster.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}
</div>
</div>

26
templates/default/activity/event/torrent/poster/approve/delete.rss.twig

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
<item>
<title>
{{ '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 %}
</title>
<author>#{{ user.id }}</author>
<pubDate>{{ added | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity-{{ id }}</guid>
<link>{{ url('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}#activity</link>
</item>

39
templates/default/activity/event/torrent/poster/delete.html.twig

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<div class="row">
<div class="column width-80">
<a class="margin-r-4-px" 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>
{{ 'have deleted poster edition' | trans }}
{% if torrent.poster.exist %}
<a href="{{ path('torrent_poster_edit', { torrentId : torrent.id, torrentPosterId : torrent.poster.id }) }}">
#{{ torrent.poster.id }}
</a>
{% else %}
#{{ torrent.sensitive.id }}
{% endif %}
{{ 'for torrent' | trans }}
{% if session.user.moderator or session.user.owner %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% 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 %}
<a href="{{ path('torrent_info', { torrentId : torrent.id }) }}">
{{ torrent.name }}
</a>
{% endif %}
{% endif %}
</div>
<div class="column width-20 text-right">
{{ added | format_ago }}
</div>
</div>

26
templates/default/activity/event/torrent/poster/delete.rss.twig

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
<item>
<title>
{{ '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 %}
</title>
<author>#{{ user.id }}</author>
<pubDate>{{ added | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('torrent_poster_edit', { torrentId : torrent.id }) }}#activity-{{ id }}</guid>
<link>{{ url('torrent_poster_edit', { torrentId : torrent.id }) }}#activity</link>
</item>
Loading…
Cancel
Save