Example #1
0
 public function showAction()
 {
     $commentMapper = new CommentMapper();
     if ($this->getRequest()->getPost('saveComment')) {
         $date = new \Ilch\Date();
         $commentModel = new CommentModel();
         if ($this->getRequest()->getPost('fkId')) {
             $commentModel->setKey('article/index/show/id/' . $this->getRequest()->getParam('id') . '/id_c/' . $this->getRequest()->getPost('fkId'));
             $commentModel->setFKId($this->getRequest()->getPost('fkId'));
         } else {
             $commentModel->setKey('article/index/show/id/' . $this->getRequest()->getParam('id'));
         }
         $commentModel->setText($this->getRequest()->getPost('article_comment_text'));
         $commentModel->setDateCreated($date);
         $commentModel->setUserId($this->getUser()->getId());
         $commentMapper->save($commentModel);
     }
     if ($this->getRequest()->isPost() & $this->getRequest()->getParam('preview') == 'true') {
         $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('preview'), array('action' => 'index'));
         $title = $this->getRequest()->getPost('title');
         $catId = $this->getRequest()->getPost('cats');
         $content = $this->getRequest()->getPost('content');
         $image = $this->getRequest()->getPost('image');
         $articleModel = new ArticleModel();
         $articleModel->setTitle($title);
         $articleModel->setCatId($catId);
         $articleModel->setContent($content);
         $articleModel->setArticleImage($image);
         $articleModel->setVisits(0);
         $this->getView()->set('article', $articleModel);
     } else {
         $articleMapper = new ArticleMapper();
         $articleModel = new ArticleModel();
         $categoryMapper = new CategoryMapper();
         $article = $articleMapper->getArticleByIdLocale($this->getRequest()->getParam('id'));
         $articlesCats = $categoryMapper->getCategoryById($article->getCatId());
         $comments = $commentMapper->getCommentsByKey('article/index/show/id/' . $this->getRequest()->getParam('id'));
         $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('menuCats'), array('controller' => 'cats', 'action' => 'index'))->add($articlesCats->getName(), array('controller' => 'cats', 'action' => 'show', 'id' => $articlesCats->getId()))->add($article->getTitle(), array('action' => 'show', 'id' => $article->getId()));
         $articleModel->setId($article->getId());
         $articleModel->setVisits($article->getVisits() + 1);
         $articleMapper->saveVisits($articleModel);
         $this->getLayout()->set('metaTitle', $article->getTitle());
         $this->getLayout()->set('metaDescription', $article->getDescription());
         $this->getView()->set('article', $article);
         $this->getView()->set('comments', $comments);
     }
 }
Example #2
0
 /**
  * Returns article model found by the key.
  *
  * @param string $id
  * @param string $locale
  * @return ArticleModel|null
  */
 public function getArticleByIdLocale($id, $locale = '')
 {
     $sql = 'SELECT * FROM [prefix]_articles as p
                 INNER JOIN [prefix]_articles_content as pc ON p.id = pc.article_id
                 WHERE p.`id` = "' . (int) $id . '" AND pc.locale = "' . $this->db()->escape($locale) . '"';
     $articleRow = $this->db()->queryRow($sql);
     if (empty($articleRow)) {
         return null;
     }
     $articleModel = new ArticleModel();
     $articleModel->setId($articleRow['id']);
     $articleModel->setCatId($articleRow['cat_id']);
     $articleModel->setAuthorId($articleRow['author_id']);
     $articleModel->setVisits($articleRow['visits']);
     $articleModel->setDescription($articleRow['description']);
     $articleModel->setTitle($articleRow['title']);
     $articleModel->setContent($articleRow['content']);
     $articleModel->setLocale($articleRow['locale']);
     $articleModel->setPerma($articleRow['perma']);
     $articleModel->setDateCreated($articleRow['date_created']);
     $articleModel->setArticleImage($articleRow['article_img']);
     $articleModel->setArticleImageSource($articleRow['article_img_source']);
     return $articleModel;
 }