common/models/search/Media.php
/**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
public function search($params)
    {
        $query = MediaModel::find();
        $query->innerJoinWith([
            'mediaAuthor' => function ($query) {
                return $query->from(['user' => User::tableName()]);
            },
        ])->from(['media' => $this->tableName()]);
        $query->leftJoin(['post' => Post::tableName()], 'media.post_id = post.id');
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        $dataProvider->setSort([
            'attributes' => ArrayHelper::merge($dataProvider->sort->attributes, [
                'username' => [
                    'asc' => ['username' => SORT_ASC],
                    'desc' => ['username' => SORT_DESC],
                    'label' => 'Author',
                    'value' => 'username',
                ],
            ]),
            'defaultOrder' => ['id' => SORT_DESC],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            'media.id' => $this->id,
            'media.author' => $this->author,
            'post_id' => $this->post_id,
            'media.comment_count' => $this->comment_count,
        ]);
        $query->andFilterWhere(['like', 'media.title', $this->title])
            ->andFilterWhere(['like', 'media.excerpt', $this->excerpt])
            ->andFilterWhere(['like', 'media.content', $this->content])
            ->andFilterWhere(['like', 'media.password', $this->password])
            ->andFilterWhere(['like', 'media.slug', $this->slug])
            ->andFilterWhere(['like', 'mime_type', $this->mime_type])
            ->andFilterWhere(['like', 'media.comment_status', $this->comment_status])
            ->andFilterWhere(['like', 'media.date', $this->date])
            ->andFilterWhere(['like', 'media.modified', $this->modified])
            ->andFilterWhere(['like', 'post.title', $this->post_title])
            ->andFilterWhere(['like', 'user.username', $this->username]);
        return $dataProvider;
    }
public function search ( $ params ) { $ query = MediaModel :: find ( ) ; $ query -> innerJoinWith ( [ 'mediaAuthor' => function ( $ query ) { return $ query -> from ( [ 'user' => User :: tableName ( ) ] ) ; } , ] ) -> from ( [ 'media' => $ this -> tableName ( ) ] ) ; $ query -> leftJoin ( [ 'post' => Post :: tableName ( ) ] , 'media.post_id = post.id' ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , ] ) ; $ dataProvider -> setSort ( [ 'attributes' => ArrayHelper :: merge ( $ dataProvider -> sort -> attributes , [ 'username' => [ 'asc' => [ 'username' => SORT_ASC ] , 'desc' => [ 'username' => SORT_DESC ] , 'label' => 'Author' , 'value' => 'username' , ] , ] ) , 'defaultOrder' => [ 'id' => SORT_DESC ] , ] ) ; $ this -> load ( $ params ) ; if ( ! $ this -> validate ( ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'media.id' => $ this -> id , 'media.author' => $ this -> author , 'post_id' => $ this -> post_id , 'media.comment_count' => $ this -> comment_count , ] ) ; $ query -> andFilterWhere ( [ 'like' , 'media.title' , $ this -> title ] ) -> andFilterWhere ( [ 'like' , 'media.excerpt' , $ this -> excerpt ] ) -> andFilterWhere ( [ 'like' , 'media.content' , $ this -> content ] ) -> andFilterWhere ( [ 'like' , 'media.password' , $ this -> password ] ) -> andFilterWhere ( [ 'like' , 'media.slug' , $ this -> slug ] ) -> andFilterWhere ( [ 'like' , 'mime_type' , $ this -> mime_type ] ) -> andFilterWhere ( [ 'like' , 'media.comment_status' , $ this -> comment_status ] ) -> andFilterWhere ( [ 'like' , 'media.date' , $ this -> date ] ) -> andFilterWhere ( [ 'like' , 'media.modified' , $ this -> modified ] ) -> andFilterWhere ( [ 'like' , 'post.title' , $ this -> post_title ] ) -> andFilterWhere ( [ 'like' , 'user.username' , $ this -> username ] ) ; return $ dataProvider ; }
Creates data provider instance with search query applied
 @param array $params
 @return ActiveDataProvider
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
/* @var $query \yii\db\ActiveQuery */