[Favourite] Move controller to plugin

This commit is contained in:
Hugo Sales 2021-04-14 19:59:37 +00:00
parent 00d71e7035
commit 974bbe164e
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
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,
];
}
}

View File

@ -70,4 +70,11 @@ class Favourite extends Module
$actions[] = $form->createView(); $actions[] = $form->createView();
return Event::next; 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;
}
} }