aboutsummaryrefslogtreecommitdiff
path: root/src/Handlers/NoteHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Handlers/NoteHandler.php')
-rw-r--r--src/Handlers/NoteHandler.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Handlers/NoteHandler.php b/src/Handlers/NoteHandler.php
new file mode 100644
index 0000000..afdabb5
--- /dev/null
+++ b/src/Handlers/NoteHandler.php
@@ -0,0 +1,39 @@
+<?php
+
+
+namespace Micropoly\Handlers;
+
+
+use Micropoly\Env;
+use Micropoly\Handler;
+use Micropoly\Models\Note;
+
+class NoteHandler implements Handler
+{
+ public function handle(Env $env, array $variables)
+ {
+ $db = $env->db();
+
+ $note = Note::byId($db, $variables["id"]);
+ if ($note === null) {
+ (new NotFoundHandler())->handle($env, []);
+ return;
+ }
+
+ if ($_SERVER["REQUEST_METHOD"] === "POST") {
+ if ($_POST["delete"] === "delete") {
+ $note->delete($db);
+ http_response_code(303);
+ $url = $env->documentRoot();
+ header("Location: {$url}");
+ return;
+ }
+
+ $note->setContent($_POST["content"]);
+ $note->setTags($_POST["tag"]);
+ $note->save($db);
+ }
+
+ echo $env->twig()->render("/note.twig", ["note" => $note]);
+ }
+} \ No newline at end of file