Example #1
0
 /**
  * Sauvegarder un article dans la bdd
  *
  * @param \Caramail\Domain\Article $article Article à sauvegarder
  */
 public function save(Article $article)
 {
     $articleData = array('title' => $article->getTitle(), 'content' => $article->getContent(), 'route' => $article->getRoute(), 'page_title' => $article->getPagetitle(), 'category' => $article->getCategory(), 'description' => $article->getDescription(), 'page' => $article->getPage());
     if ($article->getId()) {
         // The article has already been saved : update it
         $this->getDb()->update('article', $articleData, array('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);
     }
 }