Пример #1
0
 /**
  * Saves an article into the database.
  *
  * @param \MicroCMS\Domain\Article $article The article to save
  */
 public function save(Article $article)
 {
     $articleData = array('art_title' => $article->getTitle(), 'art_content' => $article->getContent(), 'art_price' => $article->getPrice(), 'game_id' => $article->getGame()->getId());
     if ($article->getId()) {
         // The article has already been saved : update it
         $this->getDb()->update('article', $articleData, array('art_id' => $article->getId()));
     } else {
         // The article has never been saved : insert it
         $this->getDb()->insert('article', $articleData);
         // Get the id of the newly created article and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $article->setId($id);
     }
     $images = $article->getImages();
     foreach ($images as $image) {
         $image->setArticle($article);
         $this->getArticleImageDAO()->save($image);
     }
 }
Пример #2
0
// Admin home page
$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));