[CONTROLLER][PLUGIN][Directory][Favourite][Reply][CORE][FeedController] Refactor to new FeedController

This commit is contained in:
Hugo Sales 2021-12-07 23:31:20 +00:00
parent ba87944732
commit 7783922b2e
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 35 additions and 31 deletions

View File

@ -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'),
]);
}
}

View File

@ -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)

View File

@ -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',
];
]);
}
}