backend/models/search/UserNodeSearch.php
/**
     * Creates data provider instance with search query applied
     *
     * @param integer $user_id
     * @param array $params
     *
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param integer $user_id
@param array $params


Creates data provider instance with search query applied @param integer $user_id @param array $params
public function search($params, $user_id=null)
    {
        if ($user_id) {
            $query->where(['user_id' => $user_id]);
        }
        $query = self::find()
            ->alias("t1")
            ->select("t1.*, t2.user_email as _user_email")
            ->innerJoin('{{%users}} as t2', 't2.user_id = t1.user_id');
        if ($user_id) {
            $query->where(['t1.user_id' => $user_id]);
        } else {
            if (!isset($_GET['showBrowsers'])) {
                $query->where('t1.node_devicetype != :DEVICE_BROWSER', ['DEVICE_BROWSER' => self::DEVICE_BROWSER]);
            }
        }
        if ($user_id) {
            $params = array_merge($_GET, ['tab' => 'node-info', '#' => 'node-info']);
        } else {
            $params = $_GET;
        }
        var_dump($params);exit;
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> [
                'params' => $params,
                'sortParam' => 'sort-p1',
                'defaultOrder' => ['node_id'=>SORT_DESC],
                'attributes' => [
                    'node_id',
                    '_user_email' => [
                        'asc' => ['t2.user_email' => SORT_ASC],
                        'desc' => ['t2.user_email' => SORT_DESC],
                    ],
                    'node_status',
                    'node_prev_status',
                    'node_created',
                    'node_updated',
                    'node_ostype',
                    'node_devicetype',
                    'node_name',
                    'node_disk_usage',
                    'node_osname',
                    'node_online',
                    'is_server',
                ]
            ],
            'pagination' => [
                'params' => $params,
                'pageParam' => 'p-nd-inf',
                'pageSizeParam' => 'per-p-nd-inf',
                'pageSize' => 100,
                'route' => \yii\helpers\Url::current(['tab' => 'node-info', 'id' => $user_id])
            ],
        ]);
        $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([
            'user_id'         => $this->user_id,
            'node_id'         => $this->node_id,
            'node_status'     => $this->node_status,
            'node_created'    => $this->node_created,
            'node_updated'    => $this->node_updated,
            'node_ostype'     => $this->node_ostype,
            'node_devicetype' => $this->node_devicetype,
            'node_online'     => $this->node_online,
            'node_name'       => $this->node_name,
            'is_server'       => $this->is_server,
        ]);
        if (!$this->node_devicetype && !$user_id) {
            $query->andWhere('t1.node_devicetype != :DEVICE_BROWSER', ['DEVICE_BROWSER' => self::DEVICE_BROWSER]);
        } else {
            $query->andFilterWhere(['node_devicetype' => $this->node_devicetype]);
        }
        $query->andFilterWhere(['like', 'node_name', $this->node_name]);
        $query->andFilterWhere(['like', 'node_osname', $this->node_osname]);
        if (($ip = ip2long($this->node_last_ip)) !== false) {
            $query->andFilterWhere(['node_last_ip' => $ip]);
        }
        $query->andFilterWhere(['like', 't2.user_email', $this->_user_email]);
        return $dataProvider;
    }
public function search ( $ params , $ user_id = null ) { $ query = self :: find ( ) -> alias ( " t1 " ) -> select ( " t1.*, t2.user_email as _user_email " ) -> innerJoin ( '{{%users}} as t2' , 't2.user_id = t1.user_id' ) ; if ( $ user_id ) { $ query -> where ( [ 't1.user_id' => $ user_id ] ) ; } else { } if ( $ user_id ) { $ params = array_merge ( $ _GET , [ 'tab' => 'node-info' , '#' => 'node-info' ] ) ; } else { $ params = $ _GET ; } $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'sort' => [ 'params' => $ params , 'sortParam' => 'sort-p1' , 'defaultOrder' => [ 'node_id' => SORT_DESC ] , 'attributes' => [ 'node_id' , '_user_email' => [ 'asc' => [ 't2.user_email' => SORT_ASC ] , 'desc' => [ 't2.user_email' => SORT_DESC ] , ] , 'node_status' , 'node_prev_status' , 'node_created' , 'node_updated' , 'node_ostype' , 'node_devicetype' , 'node_name' , 'node_disk_usage' , 'node_osname' , 'node_online' , 'is_server' , ] ] , 'pagination' => [ 'params' => $ params , 'pageParam' => 'p-nd-inf' , 'pageSizeParam' => 'per-p-nd-inf' , 'pageSize' => 100 , ] , ] ) ; $ this -> load ( $ params ) ; if ( ! $ this -> validate ( ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'node_id' => $ this -> node_id , 'node_status' => $ this -> node_status , 'node_ostype' => $ this -> node_ostype , 'node_online' => $ this -> node_online , 'is_server' => $ this -> is_server , ] ) ; if ( ! $ this -> node_devicetype && ! $ user_id ) { $ query -> andWhere ( 't1.node_devicetype != :DEVICE_BROWSER' , [ 'DEVICE_BROWSER' => self :: DEVICE_BROWSER ] ) ; } else { $ query -> andFilterWhere ( [ 'node_devicetype' => $ this -> node_devicetype ] ) ; } $ query -> andFilterWhere ( [ 'like' , 'node_name' , $ this -> node_name ] ) ; $ query -> andFilterWhere ( [ 'like' , 'node_osname' , $ this -> node_osname ] ) ; if ( ( $ ip = ip2long ( $ this -> node_last_ip ) ) !== false ) { $ query -> andFilterWhere ( [ 'node_last_ip' => $ ip ] ) ; } $ query -> andFilterWhere ( [ 'like' , 't2.user_email' , $ this -> _user_email ] ) ; return $ dataProvider ; }
Creates data provider instance with search query applied
 @param integer $user_id
 @param array $params
Creates data provider instance with search query applied @param integer $user_id @param array $params
//        $query = self::find(); //            //->where(['user_id' => $user_id]); // //        if ($user_id) { //            $query->where(['user_id' => $user_id]); //        } //            if (!isset($_GET['showBrowsers'])) { //                $query->where('t1.node_devicetype != :DEVICE_BROWSER', ['DEVICE_BROWSER' => self::DEVICE_BROWSER]); //            } //var_dump($params);exit; //'route' => \yii\helpers\Url::current(['tab' => 'node-info', 'id' => $user_id]) // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); //'user_id'         => $this->user_id, //'node_created'    => $this->node_created, //'node_updated'    => $this->node_updated, //'node_devicetype' => $this->node_devicetype, //'node_name'       => $this->node_name,