[PLUGINS][BlogCollections] Entities and base plugin and controller done

This commit is contained in:
2022-02-05 16:15:34 +00:00
parent e0ceddc2e6
commit 2b9f70f89f
7 changed files with 408 additions and 20 deletions

View File

@@ -60,9 +60,9 @@ class AttachmentCollections extends Plugin
]);
DB::persist($col);
DB::persist(AttachmentCollectionEntry::create([
'attachment_id' => $vars['vars']['attachment_id'],
'note_id' => $vars['vars']['note_id'],
'collection_id' => $col->getId(),
'attachment_id' => $vars['vars']['attachment_id'],
'note_id' => $vars['vars']['note_id'],
'attachment_collection_id' => $col->getId(),
]));
}
protected function removeItem(Actor $owner, array $vars, array $items, array $collections)
@@ -70,7 +70,7 @@ class AttachmentCollections extends Plugin
return DB::dql(<<<'EOF'
DELETE FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry
WHERE entry.attachment_id = :attach_id AND entry.note_id = :note_id
AND entry.collection_id IN (
AND entry.attachment_collection_id IN (
SELECT album.id FROM \Plugin\AttachmentCollections\Entity\AttachmentCollection AS album
WHERE album.actor_id = :user_id
AND album.id IN (:ids)
@@ -89,9 +89,9 @@ class AttachmentCollections extends Plugin
// prevent user from putting something in a collection (s)he doesn't own:
if (\in_array($id, $collections)) {
DB::persist(AttachmentCollectionEntry::create([
'attachment_id' => $vars['vars']['attachment_id'],
'note_id' => $vars['vars']['note_id'],
'collection_id' => $id,
'attachment_id' => $vars['vars']['attachment_id'],
'note_id' => $vars['vars']['note_id'],
'attachment_collection_id' => $id,
]));
}
}
@@ -101,6 +101,7 @@ class AttachmentCollections extends Plugin
{
return $vars['path'] === 'note_attachment_show';
}
protected function getCollectionsBy(Actor $owner, ?array $vars = null, bool $ids_only = false): array
{
if (\is_null($vars)) {
@@ -108,9 +109,9 @@ class AttachmentCollections extends Plugin
} else {
$res = DB::dql(
<<<'EOF'
SELECT entry.collection_id FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry
SELECT entry.attachment_collection_id FROM \Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry AS entry
INNER JOIN \Plugin\AttachmentCollections\Entity\AttachmentCollection AS attachment_collection
WITH attachment_collection.id = entry.collection_id
WITH attachment_collection.id = entry.attachment_collection_id
WHERE entry.attachment_id = :attach_id AND entry.note_id = :note_id AND attachment_collection.actor_id = :id
EOF,
[
@@ -123,7 +124,7 @@ class AttachmentCollections extends Plugin
if (!$ids_only) {
return $res;
}
return array_map(fn ($x) => $x['collection_id'], $res);
return array_map(fn ($x) => $x['attachment_collection_id'], $res);
}
public function onAddRoute(RouteLoader $r): bool

View File

@@ -59,7 +59,7 @@ class AttachmentCollections extends MetaCollectionController
WITH entry.attachment_id = attach.id
LEFT JOIN \App\Entity\Note AS notice
WITH entry.note_id = notice.id
WHERE entry.collection_id = :cid
WHERE entry.attachment_collection_id = :cid
EOF,
['cid' => $collection_id],
);

View File

@@ -14,7 +14,7 @@ class AttachmentCollectionEntry extends Entity
private int $id;
private int $note_id;
private int $attachment_id;
private int $collection_id;
private int $attachment_collection_id;
public function setId(int $id): self
{
@@ -49,15 +49,15 @@ class AttachmentCollectionEntry extends Entity
return $this->attachment_id;
}
public function setCollectionId(int $collection_id): self
public function setAttachmentCollectionId(int $attachment_collection_id): self
{
$this->collection_id = $collection_id;
$this->attachment_collection_id = $attachment_collection_id;
return $this;
}
public function getCollectionId(): int
public function getAttachmentCollectionId(): int
{
return $this->collection_id;
return $this->attachment_collection_id;
}
// @codeCoverageIgnoreEnd
@@ -68,10 +68,10 @@ class AttachmentCollectionEntry extends Entity
return [
'name' => 'attachment_collection_entry',
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to note table'],
'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to attachment table'],
'collection_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Collection.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to collection table'],
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to note table'],
'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to attachment table'],
'attachment_collection_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'AttachmentCollection.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to collection table'],
],
'primary key' => ['id'],
];