aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-02-15 23:48:26 +0100
committerLaria Carolin Chabowski <laria@laria.me>2020-02-15 23:48:26 +0100
commit7f84e36fb2f6a380635bc773eae32aa42203422c (patch)
treeda87ac3d533d64aa7371b89ff61522c0710a3cc0 /src/Handlers
parentd24d5f2e21fd4bfb5c369e2932a4c62328ffa758 (diff)
downloadmicropoly-7f84e36fb2f6a380635bc773eae32aa42203422c.tar.gz
micropoly-7f84e36fb2f6a380635bc773eae32aa42203422c.tar.bz2
micropoly-7f84e36fb2f6a380635bc773eae32aa42203422c.zip
Improve attachments
- Allow multiple uploads at once - Make uploads deletable
Diffstat (limited to 'src/Handlers')
-rw-r--r--src/Handlers/NoteHandler.php10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Handlers/NoteHandler.php b/src/Handlers/NoteHandler.php
index 4ce3179..726b773 100644
--- a/src/Handlers/NoteHandler.php
+++ b/src/Handlers/NoteHandler.php
@@ -35,6 +35,16 @@ class NoteHandler implements Handler
$note->setTags($_POST["tag"]);
$note->save($db);
+ $deleteAttachments = $_POST['attachment_delete'] ?? [];
+ $deleteAttachments = array_filter($deleteAttachments, fn ($ok) => (bool)(int)$ok);
+ $deleteAttachments = array_keys($deleteAttachments);
+ $deleteAttachments = Attachment::byIds($db, $deleteAttachments);
+ $deleteAttachments = array_filter($deleteAttachments, fn (Attachment $att) => $att->getNoteId() === $note->getId());
+
+ /** @var Attachment $att */
+ foreach ($deleteAttachments as $att)
+ $att->delete($db, $env->attachmentsPath());
+
if (isset($_FILES['attachments']))
Attachment::createFromUploads($env->db(), $env->attachmentsPath(), $note, $_FILES['attachments']);
}