/** * Creates an Article object based on a DB row. * * @param array $row The DB row containing Article data. * @return \MicroCMS\Domain\Article */ private function buildArticle(array $row) { $article = new Article(); $article->setId($row['art_id']); $article->setTitle($row['art_title']); $article->setContent($row['art_content']); return $article; }
/** * Creates an Article object based on a DB row. * * @param array $row The DB row containing Article data. * @return \MicroCMS\Domain\Article */ protected function buildDomainObject($row) { $article = new Article(); $article->setId($row['art_id']); $article->setTitle($row['art_title']); $article->setContent($row['art_content']); return $article; }
/** * 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); } }