Exemplo n.º 1
0
 /**
  * Renders the index view for the module
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionIndex()
 {
     $commentForm = new CommentForm();
     if (\Yii::$app->request->post('CommentForm')) {
         $commentForm->load(\Yii::$app->request->post());
         $commentForm->save();
         return $this->renderAjax('editModal', ['model' => $commentForm]);
     }
     if (\Yii::$app->request->isAjax) {
         switch (\Yii::$app->request->post('action')) {
             case 'editComment':
                 $commentID = \Yii::$app->request->post('commentID');
                 $comment = Comment::findOne($commentID);
                 if (!$comment) {
                     throw new NotFoundHttpException("Комментарий с идентификатором {$commentID} не найден!");
                 }
                 if (empty($commentForm->commentID)) {
                     $commentForm->loadComment($comment);
                 }
                 return $this->renderAjax('editModal', ['model' => $commentForm]);
             case 'SeedComments':
             case 'DeletedComments':
             case 'RestoreComments':
             case 'PublishComments':
             case 'UnpublishComments':
                 if (empty(\Yii::$app->request->post('commentsIDs'))) {
                     throw new InvalidParamException('Не переданы комментарии для функции!');
                 }
                 return $this->doComment(\Yii::$app->request->post('action'));
                 break;
         }
     }
     $commentsSearch = new CommentSearch();
     return $this->render('index', ['comments' => $commentsSearch->search(\Yii::$app->request->get()), 'waitCheck' => Comment::find()->where(['published' => 0, 'checked' => 0, 'deleted' => 0])->count()]);
 }
Exemplo n.º 2
0
 public function search($params)
 {
     $query = Comment::find();
     $query->joinWith('post');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'comment.content', $this->content])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'create_time', $this->create_time])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'post.title', $this->post_title]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find();
     $query->joinWith(['user']);
     //加上这句 一看就知道这个就是连表的
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'userId' => $this->user->nickName, 'typeId' => $this->typeId, 'score' => $this->score, 'useCount' => $this->useCount, 'useLessCount' => $this->useLessCount, 'publishTime' => $this->publishTime, 'hotCount' => $this->hotCount, 'sysUserId' => $this->sysUserId]);
     $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 public function actionIndex()
 {
     $todayStart = strtotime(date('Y-m-d'));
     $newsViews = NewsViews::find()->select("SUM(`views`)")->where(['date' => $todayStart])->scalar();
     if (!$newsViews) {
         $newsViews = 0;
     }
     $todayViewedNews = NewsViews::find()->select('newsID')->where(['date' => $todayStart])->orderBy('views DESC')->asArray()->all();
     $popularFiveToday = $popularToday = $todayPopularNews = [];
     if ($todayViewedNews) {
         $popularFiveToday = ArrayHelper::getColumn(array_slice($todayViewedNews, 0, 5), 'newsID');
     }
     $sViews = NewsViews::find()->select(['title' => 'date', 'views' => 'COUNT(`views`)'])->groupBy('date')->limit(30)->asArray()->all();
     array_walk($sViews, function (&$item, $key) {
         $item['title'] = \Yii::$app->formatter->asDate($item['title']);
     });
     return $this->render('index', ['monthlyViews' => $sViews, 'todayViewedNewsCount' => count($todayViewedNews), 'lastNews' => new ActiveDataProvider(['query' => News::find(), 'pagination' => ['pageSize' => 5], 'sort' => ['defaultOrder' => ['publishDate' => SORT_DESC]]]), 'popularToday' => new ActiveDataProvider(['query' => News::find()->select(['news.*', 'todayViews' => 'newsViews.views'])->where(['in', 'id', $popularFiveToday])->with('todayViews')->joinWith('todayViews')->orderBy(['todayViews' => SORT_DESC]), 'pagination' => ['pageSize' => 5], 'sort' => false]), 'lastAuth' => new ActiveDataProvider(['query' => Authorization::find()->with('user'), 'pagination' => ['pageSize' => 5], 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]), 'newsCount' => News::find()->where("publishDate >= '{$todayStart}'")->count(), 'newsViews' => $newsViews, 'commentsCount' => Comment::find()->where("date >= '{$todayStart}'")->count()]);
 }