aboutsummaryrefslogtreecommitdiff
path: root/src/TemplateModelWrappers/NoteForTemplate.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-02-10 22:36:13 +0100
committerLaria Carolin Chabowski <laria@laria.me>2020-02-10 22:36:13 +0100
commit62b0b360fa8a1a2d1fd6d89d4d227a0ef559cb8a (patch)
tree5db624a9ac4ce011c18941cbdd13da6e76492c58 /src/TemplateModelWrappers/NoteForTemplate.php
parent2eb5a432d2229788ce2fdb09f36c6f4bebdea813 (diff)
downloadmicropoly-62b0b360fa8a1a2d1fd6d89d4d227a0ef559cb8a.tar.gz
micropoly-62b0b360fa8a1a2d1fd6d89d4d227a0ef559cb8a.tar.bz2
micropoly-62b0b360fa8a1a2d1fd6d89d4d227a0ef559cb8a.zip
Implement simple attachment support
It is now possible to upload and view attachments! Attachments are saved by their content hash, therefore they are automatically deduplicated and we can later easily add integrity checks. Still missing: - Deleting attachments - Multiple file inputs (idea: when the user fills in a file input, create a new empty file input beneath with js) - (nice to have) Thumbnails
Diffstat (limited to 'src/TemplateModelWrappers/NoteForTemplate.php')
-rw-r--r--src/TemplateModelWrappers/NoteForTemplate.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/TemplateModelWrappers/NoteForTemplate.php b/src/TemplateModelWrappers/NoteForTemplate.php
new file mode 100644
index 0000000..baafe21
--- /dev/null
+++ b/src/TemplateModelWrappers/NoteForTemplate.php
@@ -0,0 +1,44 @@
+<?php
+
+
+namespace Micropoly\TemplateModelWrappers;
+
+
+use Micropoly\Models\Note;
+use SQLite3;
+
+class NoteForTemplate
+{
+ private SQLite3 $db;
+ private Note $note;
+
+ /**
+ * NoteForModel constructor.
+ * @param SQLite3 $db
+ * @param Note $note
+ */
+ public function __construct(SQLite3 $db, Note $note)
+ {
+ $this->db = $db;
+ $this->note = $note;
+ }
+
+ /**
+ * @param SQLite3 $db
+ * @param Note[] $notes
+ * @return self[]
+ */
+ public static function wrapMany(SQLite3 $db, array $notes): array
+ {
+ return array_map(static fn(Note $note) => new self($db, $note), $notes);
+ }
+
+ public function getId(): string { return $this->note->getId(); }
+ public function getContent(): string { return $this->note->getContent(); }
+ public function getTags(): array { return $this->note->getTags(); }
+
+ public function getAttachments(): array
+ {
+ return $this->note->getAttachments($this->db);
+ }
+} \ No newline at end of file