Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array    $params
  * @param int|null $media_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $media_id = null)
 {
     $query = MediaCommentModel::find();
     $query->innerJoinWith(['commentMedia' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['media' => Media::tableName()]);
     }]);
     if ($media_id) {
         $query->andWhere(['media.id' => $media_id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'comment_media_id' => $this->comment_media_id, 'comment_parent' => $this->comment_parent, 'comment_user_id' => $this->comment_user_id]);
     $query->andFilterWhere(['like', 'comment_author', $this->comment_author])->andFilterWhere(['like', 'comment_author_email', $this->comment_author_email])->andFilterWhere(['like', 'comment_author_url', $this->comment_author_url])->andFilterWhere(['like', 'comment_author_ip', $this->comment_author_ip])->andFilterWhere(['like', 'comment_content', $this->comment_content])->andFilterWhere(['like', 'comment_approved', $this->comment_approved])->andFilterWhere(['like', 'comment_agent', $this->comment_agent])->andFilterWhere(['like', 'comment_date', $this->comment_date])->andFilterWhere(['like', 'media.media_title', $this->media_title]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Lists all Media models.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new MediaSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }