summaryrefslogtreecommitdiff
path: root/src/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller')
-rw-r--r--src/Controller/Card.php31
-rw-r--r--src/Controller/Home.php22
2 files changed, 53 insertions, 0 deletions
diff --git a/src/Controller/Card.php b/src/Controller/Card.php
new file mode 100644
index 0000000..39560bb
--- /dev/null
+++ b/src/Controller/Card.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Elements\Controller;
+
+use Elements\DB;
+use Elements\Model\Card as CardModel;
+use Elements\Model\CardMeta;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+class Card
+{
+ public static function add(Request $request)
+ {
+ $card = new CardModel();
+
+ foreach ($request->get('meta') as $key => $value) {
+ $meta = new CardMeta($key, $value);
+ $card->addMeta($meta);
+ DB::save($meta);
+ }
+
+ DB::save($card);
+
+ $response = new RedirectResponse('/');
+
+ return $response;
+ }
+}
+
diff --git a/src/Controller/Home.php b/src/Controller/Home.php
new file mode 100644
index 0000000..511b89b
--- /dev/null
+++ b/src/Controller/Home.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Elements\Controller;
+
+use Elements\DB;
+use Elements\Model\Card;
+use Elements\Template;
+
+class Home
+{
+ public static function index()
+ {
+ $c = DB::$entityManager->getRepository(Card::class)->findOneBy([], ['id' => 'DESC']);
+ echo "<pre>";
+ $c && var_dump(
+ array_map(fn ($item) => [$item->key, $item->value], $c->meta->toArray()),
+ );
+
+ return Template::render('home.twig');
+ }
+}
+