コード例 #1
0
ファイル: CommentDAO.php プロジェクト: FranckParis/NanarStore
 /**
  * Saves a comment into the database.
  *
  * @param \NanarStore\Domain\Comment $comment The comment to save
  */
 public function save(Comment $comment)
 {
     $commentData = array('art_id' => $comment->getArticle()->getId(), 'usr_id' => $comment->getAuthor()->getId(), 'com_content' => $comment->getContent(), 'com_grade' => $comment->getGrade());
     if ($comment->getId()) {
         // The comment has already been saved : update it
         $this->getDb()->update('t_comment', $commentData, array('com_id' => $comment->getId()));
     } else {
         // The comment has never been saved : insert it
         $this->getDb()->insert('t_comment', $commentData);
         // Get the id of the newly created comment and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $comment->setId($id);
     }
 }