. // }}} namespace Plugin\AttachmentCollections\Controller; use App\Core\DB\DB; use App\Core\Router\Router; use Component\Collection\Util\Controller\MetaCollectionController; use Plugin\AttachmentCollections\Entity\AttachmentCollection; class AttachmentCollections extends MetaCollectionController { public function createCollection(int $owner_id, string $name) { DB::persist(AttachmentCollection::create([ 'name' => $name, 'actor_id' => $owner_id, ])); } public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string { if (\is_null($owner_nickname)) { return Router::url( 'collection_notes_view_by_actor_id', ['id' => $owner_id, 'cid' => $collection_id], ); } return Router::url( 'collection_notes_view_by_nickname', ['nickname' => $owner_nickname, 'cid' => $collection_id], ); } public function getCollectionItems(int $owner_id, $collection_id): array { [$attachs, $notes] = DB::dql( <<<'EOF' SELECT attach, notice FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry LEFT JOIN \Component\Attachment\Entity\Attachment AS attach WITH entry.attachment_id = attach.id LEFT JOIN \App\Entity\Note AS notice WITH entry.note_id = notice.id WHERE entry.collection_id = :cid EOF, ['cid' => $collection_id], ); return [ '_template' => 'AttachmentCollections/collection_entry_view.html.twig', 'attachments' => array_values($attachs), 'bare_notes' => array_values($notes), ]; } public function getCollectionsByActorId(int $owner_id): array { return DB::findBy(AttachmentCollection::class, ['actor_id' => $owner_id], order_by: ['id' => 'desc']); } public function getCollectionBy(int $owner_id, int $collection_id): AttachmentCollection { return DB::findOneBy(AttachmentCollection::class, ['id' => $collection_id]); } }