/** * Creates an Comment object based on a DB row. * * @param array $row The DB row containing Comment data. * @return \MicroCMS\Domain\Comment */ protected function buildDomainObject($row) { // Find the associated article $reservationId = $row['NUM_RESA']; $reservation = $this->reservationDAO->find($reservationId); $comment = new Comment(); $comment->setId($row['COM_ID']); $comment->setUserId($row['USER_ID']); $comment->setContent($row['COM_CONTENT']); $comment->setReservation($row['NUM_RESA']); return $comment; }
/** * Creates an Comment object based on a DB row. * * @param array $row The DB row containing Comment data. * @return \MicroCMS\Domain\Comment */ protected function buildDomainObject($row) { $comment = new Comment(); $comment->setId($row['com_id']); $comment->setContent($row['com_content']); $comment->setAuthor($row['com_author']); if (array_key_exists('art_id', $row)) { // Find and set the associated article $articleId = $row['art_id']; $article = $this->articleDAO->find($articleId); $comment->setArticle($article); } return $comment; }
/** * Saves a comment into the database. * * @param \MicroCMS\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()); 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); } }