summaryrefslogtreecommitdiff
path: root/src/Controller/Card.php
blob: 39560bb4da42a44f805b7c6d9e0b8f9c814f2a18 (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
<?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;
  }
}