summaryrefslogtreecommitdiff
path: root/src/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controller')
-rw-r--r--src/Controller/Card.php101
-rw-r--r--src/Controller/Home.php11
2 files changed, 90 insertions, 22 deletions
diff --git a/src/Controller/Card.php b/src/Controller/Card.php
index d4ee393..e7fa793 100644
--- a/src/Controller/Card.php
+++ b/src/Controller/Card.php
@@ -8,6 +8,7 @@ use Elements\Model\Card as CardModel;
use Elements\Model\CardMeta;
use Elements\Model\VoteArtwork;
use Elements\Model\VoteCard;
+use Elements\Template;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -15,6 +16,69 @@ use Symfony\Component\HttpFoundation\Response;
class Card
{
+ public static function get(Request $request)
+ {
+ $route = $request->attributes->get('route');
+ $cardId = $route['id'];
+
+ $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
+
+ return $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();
+
+ return Template::render('card/card_list.twig', [
+ 'cards' => $cards
+ ]);
+ }
+
+ public static function addCard(): string
+ {
+ // 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]',
+ ],
+ ]);
+ }
+
+ public static function displayCard(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', [
+ 'card' => $card
+ ]);
+ }
+
+ public static function editCard(Request $request)
+ {
+ $route = $request->attributes->get('route');
+ $cardId = $route['id'];
+
+ $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
+ $metas = DB::$entityManager->getRepository(CardMeta::class)->findAll();
+
+ return Template::render('card/card_edit.twig', [
+ 'card' => $card
+ ]);
+ }
+
public static function add(Request $request)
{
$card = new CardModel();
@@ -28,19 +92,19 @@ class Card
/**@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);
+ $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);
}
}
@@ -55,19 +119,18 @@ class Card
DB::save($card);
- $response = new RedirectResponse('/');
-
+ $response = new RedirectResponse('/card/' . $card->id);
return $response;
}
- public static function get(Request $request)
+ public static function edit(Request $request)
{
$route = $request->attributes->get('route');
$cardId = $route['id'];
- $card = DB::$entityManager->getRepository(CardModel::class)->find($cardId);
+ // TODO: like add but edit
- return $card->getMeta('name');
+ $response = new RedirectResponse('/card/' . $cardId);
+ return $response;
}
}
-
diff --git a/src/Controller/Home.php b/src/Controller/Home.php
index 1c1500c..7eda5ee 100644
--- a/src/Controller/Home.php
+++ b/src/Controller/Home.php
@@ -21,11 +21,16 @@ class Home
return Template::render('home.twig', [
'fields' => [
- 'name' => 'meta[name]',
- 'converted mana cost' => 'meta[cmc]',
- 'is uno reverse' => 'meta[is_uno_reverse]',
+ 'name' => 'meta[name]',
+ 'converted mana cost' => 'meta[cmc]',
+ 'is uno reverse' => 'meta[is_uno_reverse]',
],
]);
}
+
+ public static function dashboard()
+ {
+ return Template::render('dashboard.twig', []);
+ }
}