summaryrefslogtreecommitdiff
path: root/src/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller')
-rw-r--r--src/Controller/Card.php61
1 files changed, 53 insertions, 8 deletions
diff --git a/src/Controller/Card.php b/src/Controller/Card.php
index e7fa793..3d8d8e0 100644
--- a/src/Controller/Card.php
+++ b/src/Controller/Card.php
@@ -28,14 +28,13 @@ class Card
public static function getAll(): array
{
- // TODO: is that correct? yes - how to call this getAll?
return DB::$entityManager->getRepository(CardModel::class)->findAll();
}
public static function listCards(): string
{
// get all cards
- $cards = DB::$entityManager->getRepository(CardModel::class)->findAll();
+ $cards = self::getAll();
return Template::render('card/card_list.twig', [
'cards' => $cards
@@ -47,25 +46,40 @@ class Card
// TODO: how to access all available meta?
return Template::render('card/card_add.twig', [
'fields' => [
- 'name' => 'meta[name]',
- 'converted mana cost' => 'meta[cmc]',
- 'is uno reverse' => 'meta[is_uno_reverse]',
+ 'name' => 'name',
+ 'converted mana cost' => 'cmc',
+ 'is uno reverse' => 'is_uno_reverse',
],
]);
}
- public static function displayCard(Request $request): string
+ public static function viewCard(Request $request): string
{
$route = $request->attributes->get('route');
$cardId = $route['id'];
$card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
- return Template::render('card/card_display.twig', [
+ return Template::render('card/card_view.twig', [
'card' => $card
]);
}
+ public static function viewArtwork(Request $request): string
+ {
+ $route = $request->attributes->get('route');
+ $cardId = $route['id'];
+ $artworkId = $route['artworkId'];
+
+ $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
+ $artwork = DB::$entityManager->getRepository(Artwork::class)->find($artworkId);
+
+ return Template::render('artwork/artwork_view.twig', [
+ 'card' => $card,
+ 'artwork' => $artwork
+ ]);
+ }
+
public static function editCard(Request $request)
{
$route = $request->attributes->get('route');
@@ -127,10 +141,41 @@ class Card
{
$route = $request->attributes->get('route');
$cardId = $route['id'];
+ $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
- // TODO: like add but edit
+ foreach ($request->get('meta') as $key => $value) {
+ $meta = $card->getMeta($key);
+ if ($meta == null) {
+ $meta = new CardMeta($key, $value);
+ $card->addMeta($meta);
+ } else {
+ $meta->value = strval($value);
+ }
+
+ DB::save($meta);
+ }
+
+ DB::save($card);
$response = new RedirectResponse('/card/' . $cardId);
return $response;
}
+
+ public static function vote(Request $request)
+ {
+ var_dump('VOTE');
+ $route = $request->attributes->get('route');
+ $cardId = $route['id'];
+ $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
+
+ $vote = new VoteCard();
+ $vote->value = intval($request->get('value'));
+ $card->addVote($vote);
+ DB::save($vote);
+ DB::save($card);
+
+ // TODO: redirect to last visited
+ $response = new RedirectResponse('/card');
+ return $response;
+ }
}