/** * Inserts or updates a article model in the database. * * @param ArticleModel $article */ public function save(ArticleModel $article) { if ($article->getId()) { if ($this->getArticleByIdLocale($article->getId(), $article->getLocale())) { $this->db()->update('articles')->values(array('cat_id' => $article->getCatId()))->where(array('id' => $article->getId()))->execute(); $this->db()->update('articles_content')->values(array('title' => $article->getTitle(), 'description' => $article->getDescription(), 'content' => $article->getContent(), 'perma' => $article->getPerma(), 'article_img' => $article->getArticleImage(), 'article_img_source' => $article->getArticleImageSource()))->where(array('article_id' => $article->getId(), 'locale' => $article->getLocale()))->execute(); } else { $this->db()->insert('articles_content')->values(array('article_id' => $article->getId(), 'author_id' => $article->getAuthorId(), 'description' => $article->getDescription(), 'title' => $article->getTitle(), 'content' => $article->getContent(), 'perma' => $article->getPerma(), 'locale' => $article->getLocale(), 'article_img' => $article->getArticleImage(), 'article_img_source' => $article->getArticleImageSource()))->execute(); } } else { $date = new \Ilch\Date(); $articleId = $this->db()->insert('articles')->values(array('cat_id' => $article->getCatId(), 'date_created' => $date->toDb()))->execute(); $this->db()->insert('articles_content')->values(array('article_id' => $articleId, 'author_id' => $article->getAuthorId(), 'description' => $article->getDescription(), 'title' => $article->getTitle(), 'content' => $article->getContent(), 'perma' => $article->getPerma(), 'locale' => $article->getLocale(), 'article_img' => $article->getArticleImage(), 'article_img_source' => $article->getArticleImageSource()))->execute(); } }