aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-25 17:01:06 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-25 17:01:06 +0200
commitd65d2d360929b0288285150604b4410ac19728dd (patch)
tree4053d49e0ca7ee32281b626746b196e07125b5c8
parentfc04360d11adcf9fb28070a828d44ef84357134e (diff)
downloadimperium-d65d2d360929b0288285150604b4410ac19728dd.zip
imperium-d65d2d360929b0288285150604b4410ac19728dd.tar.gz
add task controller class to can be used in the future
-rw-r--r--imperium/Controller/Task.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/imperium/Controller/Task.php b/imperium/Controller/Task.php
new file mode 100644
index 0000000..faf4570
--- /dev/null
+++ b/imperium/Controller/Task.php
@@ -0,0 +1,87 @@
+<?php
+
+
+namespace Imperium\Controller;
+
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Imperium\Action\Todo;
+use Imperium\Exception\Kedavra;
+use Imperium\Html\Form\Form;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Response;
+use Twig\Error\LoaderError;
+use Twig\Error\RuntimeError;
+use Twig\Error\SyntaxError;
+
+class Task extends Controller
+{
+ /**
+ *
+ * Close a task
+ *
+ * @param int $id
+ *
+ * @return RedirectResponse
+ *
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws Kedavra
+ *
+ */
+ public function finish(int $id): RedirectResponse
+ {
+ return Todo::destroy($id) ? $this->back('removed') : $this->back('not removed',false);
+ }
+
+ /**
+ *
+ * Create a task
+ *
+ * @return RedirectResponse
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ *
+ */
+ public function add(): RedirectResponse
+ {
+ $todo = collect($this->request()->request->all())->del(CSRF_TOKEN,'method')->all();
+ return Todo::create($todo) ? $this->back('created') : $this->back('fail',false);
+ }
+
+ /**
+ *
+ * Display all tasks
+ *
+ * @return Response
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ * @throws LoaderError
+ * @throws RuntimeError
+ * @throws SyntaxError
+ *
+ */
+ public function home(): Response
+ {
+ $todo = Todo::query()->by('due',self::ASC)->all();
+ $form = $this->form()->start('task','add')
+ ->row()
+ ->input(Form::TEXT,'task','task')
+ ->end_row_and_new()
+ ->textarea('description','description')
+ ->end_row_and_new()
+ ->input(Form::DATE,'due','The due date')
+ ->end_row_and_new()
+ ->select(false,'priority',['none','low','medium','high'])
+ ->end_row_and_new()
+ ->submit('add')
+ ->end_row()
+ ->get();
+ return $this->view('@todo/home',compact('todo','form'));
+ }
+} \ No newline at end of file