2021-12-24 09:38:06 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
// {{{ 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\AttachmentCollections\Controller;
|
|
|
|
|
|
|
|
use App\Core\DB\DB;
|
2021-12-26 18:48:16 +09:00
|
|
|
use App\Core\Router\Router;
|
2022-01-03 05:04:52 +09:00
|
|
|
use Component\Collection\Util\Controller\MetaCollectionController;
|
2021-12-30 09:51:12 +09:00
|
|
|
use Plugin\AttachmentCollections\Entity\AttachmentCollection;
|
2021-12-24 09:38:06 +09:00
|
|
|
|
2022-01-03 05:04:52 +09:00
|
|
|
class AttachmentCollections extends MetaCollectionController
|
2021-12-24 09:38:06 +09:00
|
|
|
{
|
2021-12-30 09:51:12 +09:00
|
|
|
public function createCollection(int $owner_id, string $name)
|
2021-12-24 09:38:06 +09:00
|
|
|
{
|
2021-12-30 09:51:12 +09:00
|
|
|
DB::persist(AttachmentCollection::create([
|
|
|
|
'name' => $name,
|
|
|
|
'actor_id' => $owner_id,
|
|
|
|
]));
|
2021-12-24 09:38:06 +09:00
|
|
|
}
|
2021-12-30 09:51:12 +09:00
|
|
|
public function getCollectionUrl(int $owner_id, ?string $owner_nickname, int $collection_id): string
|
2021-12-24 09:38:06 +09:00
|
|
|
{
|
2021-12-30 09:51:12 +09:00
|
|
|
if (\is_null($owner_nickname)) {
|
|
|
|
return Router::url(
|
|
|
|
'collection_notes_view_by_actor_id',
|
|
|
|
['id' => $owner_id, 'cid' => $collection_id],
|
|
|
|
);
|
2021-12-24 09:38:06 +09:00
|
|
|
}
|
2021-12-30 09:51:12 +09:00
|
|
|
return Router::url(
|
|
|
|
'collection_notes_view_by_nickname',
|
|
|
|
['nickname' => $owner_nickname, 'cid' => $collection_id],
|
|
|
|
);
|
2021-12-24 09:38:06 +09:00
|
|
|
}
|
2021-12-30 09:51:12 +09:00
|
|
|
public function getCollectionItems(int $owner_id, $collection_id): array
|
2021-12-24 09:38:06 +09:00
|
|
|
{
|
2021-12-28 13:39:09 +09:00
|
|
|
[$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,
|
2021-12-30 09:51:12 +09:00
|
|
|
['cid' => $collection_id],
|
2021-12-24 09:38:06 +09:00
|
|
|
);
|
|
|
|
return [
|
2022-01-03 03:40:09 +09:00
|
|
|
'_template' => 'AttachmentCollections/collection_entry_view.html.twig',
|
2021-12-28 13:39:09 +09:00
|
|
|
'attachments' => array_values($attachs),
|
|
|
|
'bare_notes' => array_values($notes),
|
2021-12-24 09:38:06 +09:00
|
|
|
];
|
|
|
|
}
|
2022-01-03 05:04:52 +09:00
|
|
|
public function getCollectionsByActorId(int $owner_id): array
|
2021-12-30 09:51:12 +09:00
|
|
|
{
|
|
|
|
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]);
|
|
|
|
}
|
2022-01-05 06:58:49 +09:00
|
|
|
|
|
|
|
public function setCollectionName(int $actor_id, string $actor_nickname, AttachmentCollection $collection, string $name)
|
|
|
|
{
|
|
|
|
$collection->setName($name);
|
|
|
|
DB::persist($collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeCollection(int $actor_id, string $actor_nickname, AttachmentCollection $collection)
|
|
|
|
{
|
|
|
|
DB::remove($collection);
|
|
|
|
}
|
2021-12-24 09:38:06 +09:00
|
|
|
}
|