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