示例#1
0
 public function treatAction()
 {
     $articleMapper = new ArticleMapper();
     $categoryMapper = new CategoryMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         if ($this->getRequest()->getParam('locale') == '') {
             $locale = '';
         } else {
             $locale = $this->getRequest()->getParam('locale');
         }
         $this->getView()->set('article', $articleMapper->getArticleByIdLocale($this->getRequest()->getParam('id'), $locale));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $model = new ArticleModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $model->setCatId($this->getRequest()->getPost('cats'));
         $model->setAuthorId($this->getUser()->getId());
         $model->setDescription($this->getRequest()->getPost('description'));
         $model->setTitle($this->getRequest()->getPost('title'));
         $model->setContent($this->getRequest()->getPost('content'));
         $model->setArticleImage($this->getRequest()->getPost('image'));
         $model->setArticleImageSource($this->getRequest()->getPost('imageSource'));
         $model->setPerma($this->getRequest()->getPost('permaLink'));
         if ($this->getRequest()->getPost('language') != '') {
             $model->setLocale($this->getRequest()->getPost('language'));
         } else {
             $model->setLocale('');
         }
         $articleMapper->save($model);
         $this->redirect(array('action' => 'index'));
     }
     $this->getView()->set('cats', $categoryMapper->getCategories());
     $this->getView()->set('contentLanguage', $this->getConfig()->get('content_language'));
     $this->getView()->set('languages', $this->getTranslator()->getLocaleList());
     $this->getView()->set('multilingual', (bool) $this->getConfig()->get('multilingual_acp'));
 }
示例#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;
 }