Exemplo n.º 1
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.º 2
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.º 3
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()]);
 }
Exemplo n.º 4
0
 public function doComment($action)
 {
     $action = preg_replace('/Comments/', '', $action);
     $param = '';
     $value = 1;
     switch ($action) {
         case 'Seed':
             $param = 'checked';
             break;
         case 'Restore':
             $value = 0;
         case 'Deleted':
             $param = 'deleted';
             break;
         case 'Unpublish':
             $value = 0;
         case 'Publish':
             $param = 'published';
             break;
     }
     if (empty($param)) {
         return false;
     }
     $params = [$param => $value];
     if ($param != 'checked') {
         $params['checked'] = 1;
     }
     return Comment::updateAll($params, ['in', 'id', \Yii::$app->request->post('commentsIDs')]);
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['post_id' => 'id']);
 }
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComment()
 {
     return $this->hasOne(Comment::className(), ['id' => 'id']);
 }