diff options
author | Daniel Weipert <code@drogueronin.de> | 2022-01-10 20:29:04 +0100 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2022-01-10 20:29:04 +0100 |
commit | a319f3a419790925bed539ba141038c72a83e70f (patch) | |
tree | dfb24183cc693863df733e190dbbc6da93bb82e5 /src/Controller |
Initial commit
Diffstat (limited to 'src/Controller')
-rw-r--r-- | src/Controller/Card.php | 31 | ||||
-rw-r--r-- | src/Controller/Home.php | 22 |
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'); + } +} + |