2021-09-14 21:40:50 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-09-14 21:40:50 +09:00
|
|
|
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-22 00:39:36 +09:00
|
|
|
use App\Util\Common;
|
2021-09-21 00:17:13 +09:00
|
|
|
use Component\Tag\Tag as CompTag;
|
2021-09-14 21:40:50 +09:00
|
|
|
|
|
|
|
class Tag extends Controller
|
|
|
|
{
|
2021-12-08 04:53:56 +09:00
|
|
|
private function process(string|array $canon_single_or_multi, null|string|array $tag_single_or_multi, string $key, string $query, string $template)
|
2021-09-14 21:40:50 +09:00
|
|
|
{
|
2021-11-25 00:51:01 +09:00
|
|
|
$actor = Common::actor();
|
|
|
|
$page = $this->int('page') ?: 1;
|
|
|
|
$lang = $this->string('lang');
|
2021-12-08 04:53:56 +09:00
|
|
|
|
2021-11-28 22:09:04 +09:00
|
|
|
$results = Cache::pagedStream(
|
2021-12-08 04:53:56 +09:00
|
|
|
key: $key,
|
2021-11-26 20:48:35 +09:00
|
|
|
query: $query,
|
2021-12-08 04:53:56 +09:00
|
|
|
query_args: ['canon' => $canon_single_or_multi],
|
2021-11-25 00:51:01 +09:00
|
|
|
actor: $actor,
|
2021-10-10 17:26:18 +09:00
|
|
|
page: $page,
|
2021-09-21 00:17:13 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
2021-11-28 22:09:04 +09:00
|
|
|
'_template' => $template,
|
2021-12-08 04:53:56 +09:00
|
|
|
'tag_name' => $tag_single_or_multi,
|
2021-11-28 22:09:04 +09:00
|
|
|
'results' => $results,
|
2021-09-21 00:17:13 +09:00
|
|
|
'page' => $page,
|
|
|
|
];
|
2021-09-14 21:40:50 +09:00
|
|
|
}
|
2021-11-26 20:48:35 +09:00
|
|
|
|
2021-12-08 04:53:56 +09:00
|
|
|
public function single_note_tag(string $canon)
|
2021-11-26 20:48:35 +09:00
|
|
|
{
|
|
|
|
return $this->process(
|
2021-12-08 04:53:56 +09:00
|
|
|
canon_single_or_multi: $canon,
|
|
|
|
tag_single_or_multi: $this->string('tag'),
|
|
|
|
key: CompTag::cacheKeys($canon)['note_single'],
|
2021-11-26 20:48:35 +09:00
|
|
|
query: 'select n from note n join note_tag nt with n.id = nt.note_id where nt.canonical = :canon order by nt.created DESC, nt.note_id DESC',
|
2021-11-28 22:09:04 +09:00
|
|
|
template: 'note_tag_feed.html.twig',
|
2021-11-26 20:48:35 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-08 04:53:56 +09:00
|
|
|
public function multi_note_tags(string $canons)
|
2021-11-26 20:48:35 +09:00
|
|
|
{
|
|
|
|
return $this->process(
|
2021-12-08 04:53:56 +09:00
|
|
|
canon_single_or_multi: explode(',', $canons),
|
|
|
|
tag_single_or_multi: !\is_null($this->string('tags')) ? explode(',', $this->string('tags')) : null,
|
|
|
|
key: CompTag::cacheKeys(str_replace(',', '-', $canons))['note_multi'],
|
2021-11-26 20:48:35 +09:00
|
|
|
query: 'select n from note n join note_tag nt with n.id = nt.note_id where nt.canonical in (:canon) order by nt.created DESC, nt.note_id DESC',
|
2021-11-28 22:09:04 +09:00
|
|
|
template: 'note_tag_feed.html.twig',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-08 04:53:56 +09:00
|
|
|
public function single_actor_tag(string $canon)
|
2021-11-28 22:09:04 +09:00
|
|
|
{
|
|
|
|
return $this->process(
|
2021-12-08 04:53:56 +09:00
|
|
|
canon_single_or_multi: $canon,
|
|
|
|
tag_single_or_multi: $this->string('tag'),
|
|
|
|
key: CompTag::cacheKeys($canon)['actor_single'],
|
2021-11-28 22:09:04 +09:00
|
|
|
query: 'select a from actor a join actor_tag at with a.id = at.tagged where at.canonical = :canon order by at.modified DESC',
|
|
|
|
template: 'actor_tag_feed.html.twig',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-08 04:53:56 +09:00
|
|
|
public function multi_actor_tag(string $canons)
|
2021-11-28 22:09:04 +09:00
|
|
|
{
|
|
|
|
return $this->process(
|
2021-12-08 04:53:56 +09:00
|
|
|
canon_single_or_multi: explode(',', $canons),
|
|
|
|
tag_single_or_multi: !\is_null($this->string('tags')) ? explode(',', $this->string('tags')) : null,
|
|
|
|
key: CompTag::cacheKeys(str_replace(',', '-', $canons))['actor_multi'],
|
2021-11-28 22:09:04 +09:00
|
|
|
query: 'select a from actor a join actor_tag at with a.id = at.tagged where at.canonical = :canon order by at.modified DESC',
|
|
|
|
template: 'actor_tag_feed.html.twig',
|
2021-11-26 20:48:35 +09:00
|
|
|
);
|
|
|
|
}
|
2021-09-14 21:40:50 +09:00
|
|
|
}
|