From 7783922b2eef8b15b672ffd3746738f325504cd4 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 7 Dec 2021 23:31:20 +0000 Subject: [PATCH] [CONTROLLER][PLUGIN][Directory][Favourite][Reply][CORE][FeedController] Refactor to new FeedController --- plugins/Directory/Controller/Directory.php | 13 +++++-- plugins/Favourite/Controller/Favourite.php | 45 ++++++++++------------ plugins/Reply/Controller/Reply.php | 8 ++-- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/plugins/Directory/Controller/Directory.php b/plugins/Directory/Controller/Directory.php index afa2a3025e..ded8c58ed0 100644 --- a/plugins/Directory/Controller/Directory.php +++ b/plugins/Directory/Controller/Directory.php @@ -23,10 +23,11 @@ declare(strict_types = 1); namespace Plugin\Directory\Controller; +use App\Core\Controller\FeedController; use App\Core\DB\DB; use Symfony\Component\HttpFoundation\Request; -class Directory +class Directory extends FeedController { /** * actors stream @@ -35,7 +36,10 @@ class Directory */ public function actors(Request $request): array { - return ['_template' => 'directory/actors.html.twig', 'actors' => DB::dql('select g from App\Entity\Actor g order by g.nickname ASC')]; + return $this->process_feed([ + '_template' => 'directory/actors.html.twig', + 'actors' => DB::dql('select a from actor a order by a.nickname ASC'), + ]); } /** @@ -45,6 +49,9 @@ class Directory */ public function groups(Request $request): array { - return ['_template' => 'directory/groups.html.twig', 'groups' => DB::dql('select g from App\Entity\Group g order by g.nickname ASC')]; + return $this->process_feed([ + '_template' => 'directory/groups.html.twig', + 'groups' => DB::dql('select g from group g order by g.nickname ASC'), + ]); } } diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php index 3999dcc399..0ea6eb4042 100644 --- a/plugins/Favourite/Controller/Favourite.php +++ b/plugins/Favourite/Controller/Favourite.php @@ -23,9 +23,8 @@ declare(strict_types = 1); namespace Plugin\Favourite\Controller; -use App\Core\Controller; +use App\Core\Controller\FeedController; use App\Core\DB\DB; -use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; @@ -40,7 +39,7 @@ use Plugin\Favourite\Entity\Favourite as FavouriteEntity; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; -class Favourite extends Controller +class Favourite extends FeedController { /** * @throws \App\Util\Exception\ServerException @@ -167,21 +166,20 @@ class Favourite extends Controller public function favouritesByActorId(Request $request, int $id) { $notes = DB::dql( - 'select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' - . 'where n.id = f.note_id ' - . 'and f.actor_id = :id ' - . 'order by f.created DESC', + <<< 'EOF' + select n from note n + join favourite f with n.id = f.note_id + where f.actor_id = :id + order by f.created DESC + EOF, ['id' => $id], ); - $notes_out = null; - Event::handle('FormatNoteList', [$notes, &$notes_out]); - - return [ + return $this->process_feed([ '_template' => 'feeds/feed.html.twig', - 'notes' => $notes_out, 'page_title' => 'Favourites feed.', - ]; + 'notes' => $notes, + ]); } public function favouritesByActorNickname(Request $request, string $nickname) @@ -200,22 +198,21 @@ class Favourite extends Controller public function reverseFavouritesByActorId(Request $request, int $id): array { $notes = DB::dql( - 'select n from App\Entity\Note n, Plugin\Favourite\Entity\Favourite f ' - . 'where n.id = f.note_id ' - . 'and f.actor_id != :id ' - . 'and n.actor_id = :id ' - . 'order by f.created DESC', + <<< 'EOF' + select n from note n + join favourite f with n.id = f.note_id + where f.actor_id != :id + and n.actor_id = :id + order by f.created DESC + EOF, ['id' => $id], ); - $notes_out = null; - Event::handle('FormatNoteList', [$notes, &$notes_out]); - - return [ + return $this->process_feed([ '_template' => 'feeds/feed.html.twig', - 'notes' => $notes, 'page_title' => 'Reverse favourites feed.', - ]; + 'notes' => $notes, + ]); } public function reverseFavouritesByActorNickname(Request $request, string $nickname) diff --git a/plugins/Reply/Controller/Reply.php b/plugins/Reply/Controller/Reply.php index 1e12ba4721..e4ae9f4e5b 100644 --- a/plugins/Reply/Controller/Reply.php +++ b/plugins/Reply/Controller/Reply.php @@ -26,7 +26,7 @@ declare(strict_types = 1); namespace Plugin\Reply\Controller; -use App\Core\Controller; +use App\Core\Controller\FeedController; use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; @@ -48,7 +48,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\HttpFoundation\Request; -class Reply extends Controller +class Reply extends FeedController { /** * Controller for the note reply non-JS page @@ -152,10 +152,10 @@ class Reply extends Controller $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); - return [ + return $this->process_feed([ '_template' => 'feeds/feed.html.twig', 'notes' => $notes_out, 'page_title' => 'Replies feed', - ]; + ]); } }