[Favourite] Move table and left panel links to plugin

This commit is contained in:
Hugo Sales 2021-04-15 00:57:29 +00:00
parent 5f4815b12f
commit 8e56dbb95c
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 23 additions and 12 deletions

View File

@ -22,6 +22,8 @@
namespace Plugin\Favourite\Controller;
use App\Core\DB\DB;
use App\Core\Event;
use App\Util\Common;
use Symfony\Component\HttpFoundation\Request;
class Favourite
@ -29,9 +31,9 @@ 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]);
$notes = DB::dql('select f from Plugin\Favourite\Entity\Favourite f ' .
'where f.gsactor_id = :id ' .
'order by f.created DESC', ['id' => $actor_id]);
Event::handle('FormatNoteList', [&$notes]);
@ -53,12 +55,12 @@ class Favourite
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]);
$notes = DB::dql('select n from App\Entity\Note n, Plugin\Favourite\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]);

View File

@ -26,7 +26,8 @@ use App\Core\Modules\Module;
use App\Core\Router\RouteLoader;
use App\Entity\Note;
use App\Util\Common;
use Plugin\Favourite\Entity\Favourite as Fave;
use App\Util\Formatting;
use App\Util\Nickname;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
@ -72,10 +73,18 @@ class Favourite extends Module
return Event::next;
}
public function onInsertLeftPanelLink(string $user_nickname, &$res)
{
$res .= Formatting::twigRender(<<<END
<a href="{{ path("favourites", {'nickname' : user_nickname}) }}" class='hover-effect {{ active("favourites") }}'>Favourites</a>
<a href="{{ path("reverse_favourites", {'nickname' : user_nickname}) }}" class='hover-effect {{ active("reverse_favourites") }}'>Reverse Favs</a>
END, ['user_nickname' => $user_nickname]);
}
public function onAddRoute(RouteLoader $r)
{
$r->connect('favourites', '/favourites', [Controller\Favourite::class, 'favourites']);
$r->connect('reverse_favourites', '/reversefavs', [Controller\Favourite::class, 'reverseFavourites']);
$r->connect('favourites', '/favourites/{nickname<' . Nickname::DISPLAY_FMT . '>}', [Controller\Favourite::class, 'favourites']);
$r->connect('reverse_favourites', '/reverse_favourites/{nickname<' . Nickname::DISPLAY_FMT . '>}', [Controller\Favourite::class, 'reverseFavourites']);
return Event::next;
}
}