diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-14 08:49:37 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-14 08:49:37 +0000 |
| commit | 8977f8cec4ca88f13528792a453eb27328e22845 (patch) | |
| tree | 3479e7c7a3cec0a0ca923ea3c134d7243797b19d /src | |
| parent | 3226a642822a15e6cf937d3f0ec20fdf71651ea4 (diff) | |
Add description to todo
Diffstat (limited to 'src')
| -rw-r--r-- | src/DTS/Old.php | 1 | ||||
| -rw-r--r-- | src/DTS/Todo.php | 2 | ||||
| -rw-r--r-- | src/DTS/TodoRepository.php | 6 | ||||
| -rw-r--r-- | src/DTS/Validated.php | 2 | ||||
| -rw-r--r-- | src/DTS/Validator.php | 19 | ||||
| -rw-r--r-- | src/templates/confirm_deletion.php | 2 | ||||
| -rw-r--r-- | src/templates/form_fields.php | 4 | ||||
| -rw-r--r-- | src/templates/index.php | 2 | ||||
| -rw-r--r-- | src/templates/view.php | 20 |
9 files changed, 54 insertions, 4 deletions
diff --git a/src/DTS/Old.php b/src/DTS/Old.php index 0641329..6e8cbee 100644 --- a/src/DTS/Old.php +++ b/src/DTS/Old.php @@ -8,6 +8,7 @@ class Old { const FIELDS = [ 'task', + 'description', 'tag', ]; diff --git a/src/DTS/Todo.php b/src/DTS/Todo.php index 9b08e56..ca10e1d 100644 --- a/src/DTS/Todo.php +++ b/src/DTS/Todo.php @@ -10,6 +10,8 @@ class Todo public string $task = ''; + public string $description = ''; + public string $tag = ''; public string $addedAt; diff --git a/src/DTS/TodoRepository.php b/src/DTS/TodoRepository.php index 5ec759f..358ac9d 100644 --- a/src/DTS/TodoRepository.php +++ b/src/DTS/TodoRepository.php @@ -124,8 +124,9 @@ class TodoRepository implements \Iterator $todo->id = $id++; $todo->task = $data[0]; - $todo->tag = $data[1]; - $todo->addedAt = $data[2]; + $todo->description = $data[1]; + $todo->tag = $data[2]; + $todo->addedAt = $data[3]; $this->repository[] = $todo; @@ -150,6 +151,7 @@ class TodoRepository implements \Iterator foreach ($this->repository as $todo) { $success = $success && fputcsv($fp, [ $todo->task, + $todo->description, $todo->tag, $todo->addedAt, ]) !== false; diff --git a/src/DTS/Validated.php b/src/DTS/Validated.php index 9610538..9415a5f 100644 --- a/src/DTS/Validated.php +++ b/src/DTS/Validated.php @@ -8,5 +8,7 @@ class Validated { public string $task = ''; + public string $description = ''; + public string $tag = ''; } diff --git a/src/DTS/Validator.php b/src/DTS/Validator.php index 2f9c255..a2ab48f 100644 --- a/src/DTS/Validator.php +++ b/src/DTS/Validator.php @@ -21,6 +21,8 @@ class Validator $this->validateTask($request['task'], 2, 256); + $this->validateDescription($request['description'], 8, 512); + $this->validateTag($request['tag'], 2, 16); } @@ -37,6 +39,23 @@ class Validator } } + private function validateDescription(string $description, int $minLength, int $maxLength): void + { + $description = trim($description); + + if ($description === '') { + return; + } + + if (strlen($description) < $minLength || strlen($description) > $maxLength) { + $this->errors->add('description', "Must be between $minLength and $maxLength in characters in length"); + } + + if (!$this->errors->has('tite')) { + $this->validated->description = $description; + } + } + private function validateTag(string $tag, int $minLength, int $maxLength): void { $tag = trim($tag); diff --git a/src/templates/confirm_deletion.php b/src/templates/confirm_deletion.php index 85cf924..87ddf8a 100644 --- a/src/templates/confirm_deletion.php +++ b/src/templates/confirm_deletion.php @@ -14,7 +14,7 @@ <a href="/">Back</a> <form action="/delete/" method="POST"> <input type="hidden" name="id" value="<?= $todo->id; ?>"/> - <?= htmlentities("$todo->url | $todo->task | $todo->tag"); ?> + <?= htmlentities("$todo->task | $todo->tag"); ?> <button type="submit">Delete</button> </form> <p>Copyright © 2021 David T. Sadler.</p> diff --git a/src/templates/form_fields.php b/src/templates/form_fields.php index 505cf26..3b58adb 100644 --- a/src/templates/form_fields.php +++ b/src/templates/form_fields.php @@ -2,6 +2,10 @@ <?php if ($errors->has('task')) { ?> <p><?= htmlentities(implode(', ', $errors->get('task'))); ?></p> <?php } ?> +<label>Description<textarea name="description" maxlength="512" rows="8"><?= htmlspecialchars($old->get('description', $todo->description)); ?></textarea></label> +<?php if ($errors->has('description')) { ?> + <p><?= htmlentities(implode(', ', $errors->get('description'))); ?></p> +<?php } ?> <label>Tag<input type="text" name="tag" maxlength="16" value="<?= htmlspecialchars($old->get('tag', $todo->tag)); ?>"></label> <?php if ($errors->has('tag')) { ?> <p><?= htmlentities(implode(', ', $errors->get('tag'))); ?></p> diff --git a/src/templates/index.php b/src/templates/index.php index d309b2c..5abe8b3 100644 --- a/src/templates/index.php +++ b/src/templates/index.php @@ -25,7 +25,7 @@ <ol> <?php foreach ($todos as $todo) { ?> <li> - <?= htmlentities($todo->task); ?></a> | <?php if ($todo->tag) { ?><a class="no-decoration tag" href="/?tag=<?= htmlentities($todo->tag); ?>"><?= htmlentities($todo->tag); ?></a> | <?php } ?><a class="no-decoration" href="/edit/?id=<?= $todo->id; ?>">Edit</a> | <a class="no-decoration" href="/delete/confirm/?id=<?= $todo->id; ?>">Delete</a> + <a href="/view/?id=<?= $todo->id; ?>"><?= htmlentities($todo->task); ?></a> | <?php if ($todo->tag) { ?></a><a class="no-decoration tag" href="/?tag=<?= htmlentities($todo->tag); ?>"><?= htmlentities($todo->tag); ?></a> | <?php } ?><a class="no-decoration" href="/edit/?id=<?= $todo->id; ?>">Edit</a> | <a class="no-decoration" href="/delete/confirm/?id=<?= $todo->id; ?>">Delete</a> </li> <?php } ?> </ol> diff --git a/src/templates/view.php b/src/templates/view.php new file mode 100644 index 0000000..35d4c36 --- /dev/null +++ b/src/templates/view.php @@ -0,0 +1,20 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Edit - Todo</title> + <link rel="shortcut icon" href="/images/favicon.png"> + <link rel="stylesheet" href="/css/site.css"> + </head> + <body> + <section> + <h1>Todo</h1> + <h2>View</h2> + <a href="/">Back</a> + <h3><?= htmlentities("$todo->task | $todo->tag"); ?></h3> + <p><?= nl2br(htmlentities($todo->description), false); ?></p> + <p>Copyright © 2021 David T. Sadler.</p> + </section> + </body> +</html> |
