/** * 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); } }