2021-09-14 21:40:50 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Component\Tag\Controller;
|
|
|
|
|
2021-09-21 00:17:13 +09:00
|
|
|
use App\Core\Cache;
|
2021-09-14 21:40:50 +09:00
|
|
|
use App\Core\Controller;
|
2021-09-21 00:17:13 +09:00
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Util\Common;
|
|
|
|
use Component\Tag\Tag as CompTag;
|
2021-09-14 21:40:50 +09:00
|
|
|
|
|
|
|
class Tag extends Controller
|
|
|
|
{
|
|
|
|
public function tag(string $tag)
|
|
|
|
{
|
2021-09-21 00:17:13 +09:00
|
|
|
// TODO scope
|
|
|
|
$per_page = Common::config('streams', 'notes_per_page');
|
|
|
|
$page = $this->int('page') ?: 1;
|
|
|
|
$tag = CompTag::canonicalTag($tag);
|
|
|
|
$notes = array_reverse( // TODO meme
|
|
|
|
Cache::getList(
|
|
|
|
"tag-{$tag}",
|
|
|
|
fn () => DB::dql(
|
|
|
|
'select n from note n join note_tag nt with nt.note_id = n.id ' .
|
|
|
|
'where nt.canonical = :tag order by nt.created ASC, n.id ASC',
|
|
|
|
['tag' => $tag]),
|
|
|
|
offset: $per_page * ($page - 1),
|
|
|
|
limit: $per_page - 1
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'_template' => 'tag_stream.html.twig',
|
|
|
|
'notes' => $notes,
|
|
|
|
'page' => $page,
|
|
|
|
];
|
2021-09-14 21:40:50 +09:00
|
|
|
}
|
|
|
|
}
|