From 974bbe164eb7ee71469242c6c45f1c9ce5ff5001 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Wed, 14 Apr 2021 19:59:37 +0000 Subject: [PATCH] [Favourite] Move controller to plugin --- plugins/Favourite/Controller/Favourite.php | 70 ++++++++++++++++++++++ plugins/Favourite/Favourite.php | 7 +++ 2 files changed, 77 insertions(+) create mode 100644 plugins/Favourite/Controller/Favourite.php diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php new file mode 100644 index 0000000000..f0b5d273ac --- /dev/null +++ b/plugins/Favourite/Controller/Favourite.php @@ -0,0 +1,70 @@ +. + +// }}} + +namespace Plugin\Favourite\Controller; + +use App\Core\DB\DB; +use Symfony\Component\HttpFoundation\Request; + +class Favourite +{ + public function favourites(Request $request) + { + $actor_id = Common::ensureLoggedIn()->getId(); + $notes = DB::dql('select f from App\Entity\Favourite f ' . + 'where f.gsactor_id = :id ' . + 'order by f.created DESC', ['id' => $actor_id]); + + Event::handle('FormatNoteList', [&$notes]); + + return [ + '_template' => 'network/public.html.twig', + 'notes' => $notes, + ]; + } + + /** + * Reverse favourites stream + * + * @param Request $request + * + * @throws \App\Util\Exception\NoLoggedInUser user not logged in + * + * @return array template + */ + public function reverseFavourites(Request $request) + { + $actor_id = Common::ensureLoggedIn()->getId(); + $notes = DB::dql('select n from App\Entity\Note n, App\Entity\Favourite f ' . + 'where n.id = f.note_id ' . + 'and f.gsactor_id != :id ' . + 'and n.gsactor_id = :id ' . + 'order by f.created DESC' , + ['id' => $actor_id]); + + Event::handle('FormatNoteList', [&$notes]); + + return [ + '_template' => 'network/reversefavs.html.twig', + 'notes' => $notes, + ]; + } +} diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 4837371786..514e7ba88d 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -70,4 +70,11 @@ class Favourite extends Module $actions[] = $form->createView(); return Event::next; } + + public function onAddRoute(RouteLoader $r) + { + $r->connect('actors', '/actors', [Controller\Directory::class, 'actors']); + $r->connect('groups', '/groups', [Controller\Directory::class, 'groups']); + return Event::next; + } }