Example #1
0
 /**
  * Показывает контент
  * @return string
  * @TODO Нужно предусмотреть возможность вывода разного контента, привязаного к одной категории
  *
  */
 public function actionShow()
 {
     $this->cat_id = Yii::$app->getRequest()->getQueryParam('id') ? Yii::$app->getRequest()->getQueryParam('id') : null;
     $cat_obg = Categories::find()->where('id = ' . $this->cat_id)->one();
     $allContent = Articles::find()->where('cat_id = ' . $this->cat_id)->all();
     $allArticlesForPager = Articles::find()->where(['cat_id' => $this->cat_id]);
     $countQueryCont = clone $allArticlesForPager;
     $pagesGlobal = new Pagination(['totalCount' => $countQueryCont->count(), 'pageSize' => 1, 'forcePageParam' => false, 'pageSizeParam' => false]);
     $artPages = $allArticlesForPager->offset($pagesGlobal->offset)->limit($pagesGlobal->limit)->all();
     foreach ($allContent as $article) {
         //var_dump($this->cat_id);
         $this->article_id = $article->id;
         $article = Articles::findOne($this->article_id);
         $allArticles = ArticlesContent::find()->where(['articles_id' => $this->article_id])->orderBy(['id' => SORT_DESC]);
         //var_dump($allArticles); exit;
         $countQuery = clone $allArticles;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
         $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
         $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
         $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
         $this->articles[] = ['article' => $article, 'contents' => $models, 'pages' => $pages, 'source' => $this->source, 'author' => $this->author];
     }
     //var_dump($this->articles); exit;
     return $this->renderPartial($cat_obg->action, ['articles' => $this->articles, 'cat' => $this->cat_id, 'pagesGlobal' => $pagesGlobal, 'artPages' => $artPages, 'cat_obg' => $cat_obg]);
 }
 protected function findModel($id)
 {
     if (($model = Articles::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #3
0
 /**
  * Показываем контент
  * @param $id
  * @return string
  */
 public function actionShow($id)
 {
     $article = Articles::findOne($id);
     $comment = new Comments();
     $this->title = $article->title;
     $allArticles = ArticlesContent::find()->where(['articles_id' => $id]);
     //var_dump($allArticles); exit;
     $countQuery = clone $allArticles;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => isset($article->onepages) ? $article->onepages : 0, 'forcePageParam' => false, 'pageSizeParam' => false]);
     $models = $allArticles->offset($pages->offset)->limit($pages->limit)->all();
     $this->source = Source::find()->where(['id' => $models[0]->source_id])->one()->title;
     $this->author = Author::find()->where(['id' => Source::find()->where(['id' => $models[0]->source_id])->one()->author_id])->one()->name;
     return $this->render('view', ['articles' => $allArticles, 'contents' => $models, 'pages' => $pages, 'title' => $this->title, 'source' => $this->source, 'author' => $this->author, 'comment' => $comment]);
 }
Example #4
0
 public function actionKlavir()
 {
     /*
     
             $query  = new Query();
            // $search_result = $query_search->from('siteSearch')->match($q)->all();  // поиск осуществляется по средством метода match с переданной поисковой фразой.
             $r = $query->from('items')
                  ->match('шкалика')
                  ->all();
     
             var_dump(Items::findOne($r)); exit;
     */
     $article_id = Articles::find()->select('MAX(id)')->scalar();
     if ($article_id) {
         $article = Articles::findOne($article_id);
     } else {
         return $this->redirect(Url::toRoute('articles/index'));
     }
     $artContent = new ArticlesContent();
     if ($artContent->load(Yii::$app->request->post())) {
         $artContent->body = Yii::$app->request->post('ArticlesContent')['body'];
         $artContent->minititle = Yii::$app->request->post('ArticlesContent')['minititle'];
         $artContent->source_id = 434;
         $artContent->articles_id = $article_id;
         if ($this->loadModel($article_id)->site_id == 13) {
             $act = new DiaryActs();
             $act->model_id = 6;
             $act->mark = 1;
             $act->user_id = 8;
             $act->save(false);
         }
         $artContent->save();
         $content = ArticlesContent::find()->where(['articles_id' => $article_id]);
         $dataCont = new ActiveDataProvider(['query' => $content]);
         return $this->render('pages', ['content' => $dataCont, 'model' => $artContent]);
     } else {
         return $this->render('klavir', ['model' => $artContent]);
     }
 }
Example #5
0
 public function actionOne()
 {
     $this->view->values = Articles::findOne((int) $_GET['id']);
     $this->view->display('one');
 }
Example #6
0
 public function actionDelete()
 {
     $article = Articles::findOne((int) $_GET['id']);
     $article->delete();
     header('Location: http://test/');
 }