예제 #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());
     if ($article->getId()) {
         // The article has already been saved : update it
         $this->getDb()->update('t_article', $articleData, array('art_id' => $article->getId()));
     } else {
         // The article has never been saved : insert it
         $this->getDb()->insert('t_article', $articleData);
         // Get the id of the newly created article and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $article->setId($id);
     }
 }
예제 #2
0
 /**
  * Converts an Article object into an associative array for JSON encoding
  *
  * @param Article $article Article object
  *
  * @return array Associative array whose fields are the article properties.
  */
 private function buildArticleArray(Article $article)
 {
     $data = array('id' => $article->getId(), 'title' => $article->getTitle(), 'content' => $article->getContent());
     return $data;
 }