Ejemplo n.º 1
0
 /**
  * Creates an Article object based on a DB row.
  *
  * @param array $row The DB row containing Article data.
  * @return \MicroCMS\Domain\Article
  */
 protected function buildDomainObject($row)
 {
     $article = new Article();
     $article->setId($row['art_id']);
     $article->setTitle($row['art_title']);
     $article->setContent($row['art_content']);
     $article->setPrice($row['art_price']);
     $article->setGame($this->gameDAO->find($row['game_id']));
     $article->setImages($this->getArticleImageDAO()->findAllByArticle($article->getId()));
     return $article;
 }
Ejemplo n.º 2
0
$app->get('/admin', function () use($app) {
    $articles = $app['dao.article']->findAll();
    $comments = $app['dao.comment']->findAll();
    $users = $app['dao.user']->findAll();
    $games = $app['dao.game']->findAll();
    return $app['twig']->render('admin.html.twig', array('articles' => $articles, 'comments' => $comments, 'games' => $games, 'users' => $users));
})->bind('admin');
// Basket home page
$app->get('/basket', function () use($app) {
    $basket = $app['dao.basket']->creationBasket();
    return $app['twig']->render('basket.html.twig');
})->bind('basket');
// Add a new article
$app->match('/admin/article/add', function (Request $request) use($app) {
    $article = new Article();
    $article->setImages([new ArticleImage()]);
    $games = $app['dao.game']->findAll();
    $articleForm = $app['form.factory']->create(new ArticleType(), $article, array('games' => $games));
    $articleForm->handleRequest($request);
    if ($articleForm->isSubmitted() && $articleForm->isValid()) {
        $app['dao.article']->save($article);
        $app['session']->getFlashBag()->add('success', 'The article was successfully created.');
    }
    return $app['twig']->render('article_form.html.twig', array('title' => 'New article', 'articleForm' => $articleForm->createView()));
})->bind('admin_article_add');
// Edit an existing article
$app->match('/admin/article/{id}/edit', function ($id, Request $request) use($app) {
    $article = $app['dao.article']->find($id);
    $games = $app['dao.game']->findAll();
    $articleForm = $app['form.factory']->create(new ArticleType(), $article, array('games' => $games));
    $articleForm->handleRequest($request);