From 4cacc94240944ff316104bfd1b5e8e00fad14517 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 14 Jan 2022 18:21:36 +0100 Subject: Add Artworks, Votes and better routing --- src/Controller/Card.php | 42 ++++++++++++++++++++++++++++++++++++++++++ src/Controller/Home.php | 11 ++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) (limited to 'src/Controller') diff --git a/src/Controller/Card.php b/src/Controller/Card.php index 39560bb..d4ee393 100644 --- a/src/Controller/Card.php +++ b/src/Controller/Card.php @@ -3,8 +3,12 @@ namespace Elements\Controller; use Elements\DB; +use Elements\Model\Artwork; use Elements\Model\Card as CardModel; use Elements\Model\CardMeta; +use Elements\Model\VoteArtwork; +use Elements\Model\VoteCard; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -21,11 +25,49 @@ class Card DB::save($meta); } + /**@var UploadedFile[] $files*/ + if ($files = $request->files->get('images')) { + foreach ($files as $file) { + $image = Artwork::fromUploadedFile($file); + + /*TEST*/ + for ($i = 0; $i <= rand(0, 40); $i++) { + $vote = new VoteArtwork(); + $vote->value = rand(-1, 1) >= 0 ? 1 : -1; + $image->addVote($vote); + DB::save($vote); + } + /*TEST*/ + + $card->addArtwork($image); + DB::save($image); + } + } + + /*TEST*/ + for ($i = 0; $i <= rand(0, 60); $i++) { + $vote = new VoteCard(); + $vote->value = rand(-1, 1) > 0 ? 1 : -1; + $card->addVote($vote); + DB::save($vote); + } + /*TEST*/ + DB::save($card); $response = new RedirectResponse('/'); return $response; } + + public static function get(Request $request) + { + $route = $request->attributes->get('route'); + $cardId = $route['id']; + + $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId); + + return $card->getMeta('name'); + } } diff --git a/src/Controller/Home.php b/src/Controller/Home.php index 511b89b..1c1500c 100644 --- a/src/Controller/Home.php +++ b/src/Controller/Home.php @@ -14,9 +14,18 @@ class Home echo "
";
     $c && var_dump(
       array_map(fn ($item) => [$item->key, $item->value], $c->meta->toArray()),
+      array_map(fn ($item) => " Votes: " . $item->getVotesTotal(), $c->artworks->toArray()),
+      array_map(fn ($item) => $item->value, $c->votes->toArray()),
+      'Votes: ' . $c->getVotesTotal(),
     );
 
-    return Template::render('home.twig');
+    return Template::render('home.twig', [
+      'fields' => [
+	'name' => 'meta[name]',
+	'converted mana cost' => 'meta[cmc]',
+	'is uno reverse' => 'meta[is_uno_reverse]',
+      ],
+    ]);
   }
 }
 
-- 
cgit v1.2.3