summaryrefslogtreecommitdiff
path: root/src/Controller/Home.php
blob: 36879e04e5294c343919fb745d3aef0126b3c23a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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()),
      array_map(fn ($item) => "<img style='max-width: 100%;max-height:300px;' src='$item->path'> Votes: " . $item->getVotesTotal(), $c->artworks->toArray()),
      array_map(fn ($item) => $item->value, $c->votes->toArray()),
      'Votes: ' . $c->getVotesTotal(),
    );

    return Template::render('home.twig', [
      'fields' => [
        'name' => 'meta[name]',
        'converted mana cost' => 'meta[cmc]',
        'is uno reverse' => 'meta[is_uno_reverse]',
      ],
    ]);
  }

  public static function dashboard()
  {
    $cards = DB::$entityManager->getRepository(Card::class)->findAll();
    $cardOfTheDay = $cards[array_rand($cards)];
    return Template::render('dashboard.twig', [
      'cardOfTheDay' => $cardOfTheDay,
    ]);
  }
}