backend/models/search/UserFilesSearch.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($user_id, $params)
    {
        $query = self::find()
            ->select("*, extract(epoch from file_created) as file_created_t")
            ->where(['user_id' => $user_id]);
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> [
                'params' => array_merge($_GET, ['tab' => 'file-info', '#' => 'file-info']),
                'sortParam' => 'sort-p2',
                'defaultOrder' => ['file_id'=>SORT_DESC],
                'attributes' => [
                    'file_id',
                    'file_name',
                    'file_size',
                    'file_created_t',
                    'file_created',
                    'file_updated',
                    'file_lastatime',
                    'is_folder',
                    'share_hash',
                    'is_deleted',
                    'collaboration_id',
                ]
            ],
            'pagination' => [
                'params' => array_merge($_GET, ['tab' => 'file-info', '#' => 'file-info']),
                'pageParam' => 'p-fl-inf',
                'pageSizeParam' => 'per-p-fl-inf',
                'pageSize' => 100,
            ],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            'file_id'         => $this->file_id,
            'file_uuid'       => $this->file_uuid,
            'is_folder'       => $this->is_folder,
            'is_deleted'      => $this->is_deleted,
            'collaboration_id' => $this->collaboration_id,
        ]);
        if ($this->share_hash) {
            preg_match("/[a-z0-9]{32}/", $this->share_hash, $ma);
            if (isset($ma[0])) {
                $query->andWhere("((share_hash = :share_hash) OR (share_group_hash = :share_hash))", [
                    'share_hash' => $ma[0],
                ]);
            } else {
                $query->andFilterWhere(['share_hash' => $this->share_hash]);
            }
        }
        if (!$this->show_deleted) {
            $query->andFilterWhere([
                'is_deleted' => UserFiles::FILE_UNDELETED,
            ]);
        }
        if(!empty($this->file_created) && strpos($this->file_created, '-') !== false) {
            $tmp = explode(' - ', $this->file_created);
            if (isset($tmp[0], $tmp[1])) {
                $start_date = $tmp[0];
                $end_date = $tmp[1];
                $query->andFilterWhere([
                    'between',
                    'file_created',
                    date(SQL_DATE_FORMAT, Functions::getTimestampBeginOfDayByTimestamp(strtotime($start_date))),
                    date(SQL_DATE_FORMAT, Functions::getTimestampEndOfDayByTimestamp(strtotime($end_date))),
                ]);
            }
        }
        if(!empty($this->file_lastatime) && strpos($this->file_lastatime, '-') !== false) {
            $tmp = explode(' - ', $this->file_lastatime);
            if (isset($tmp[0], $tmp[1])) {
                $start_date = $tmp[0];
                $end_date = $tmp[1];
                $query->andFilterWhere([
                    'between',
                    'file_lastatime',
                    Functions::getTimestampBeginOfDayByTimestamp(strtotime($start_date)),
                    Functions::getTimestampEndOfDayByTimestamp(strtotime($end_date)),
                ]);
            }
        }
        $query->andFilterWhere(['like', 'file_name', $this->file_name]);
        return $dataProvider;
    }
public function search ( $ user_id , $ params ) { $ query = self :: find ( ) -> select ( " *, extract(epoch from file_created) as file_created_t " ) -> where ( [ 'user_id' => $ user_id ] ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'sort' => [ 'params' => array_merge ( $ _GET , [ 'tab' => 'file-info' , '#' => 'file-info' ] ) , 'sortParam' => 'sort-p2' , 'defaultOrder' => [ 'file_id' => SORT_DESC ] , 'attributes' => [ 'file_id' , 'file_name' , 'file_size' , 'file_created_t' , 'file_created' , 'file_updated' , 'file_lastatime' , 'is_folder' , 'share_hash' , 'is_deleted' , 'collaboration_id' , ] ] , 'pagination' => [ 'params' => array_merge ( $ _GET , [ 'tab' => 'file-info' , '#' => 'file-info' ] ) , 'pageParam' => 'p-fl-inf' , 'pageSizeParam' => 'per-p-fl-inf' , 'pageSize' => 100 , ] , ] ) ; $ this -> load ( $ params ) ; if ( ! $ this -> validate ( ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'file_id' => $ this -> file_id , 'file_uuid' => $ this -> file_uuid , 'is_folder' => $ this -> is_folder , 'is_deleted' => $ this -> is_deleted , 'collaboration_id' => $ this -> collaboration_id , ] ) ; if ( $ this -> share_hash ) { preg_match ( " /[a-z0-9]{32}/ " , $ this -> share_hash , $ ma ) ; if ( isset ( $ ma [ 0 ] ) ) { $ query -> andWhere ( " ((share_hash = :share_hash) OR (share_group_hash = :share_hash)) " , [ 'share_hash' => $ ma [ 0 ] , ] ) ; } else { $ query -> andFilterWhere ( [ 'share_hash' => $ this -> share_hash ] ) ; } } if ( ! $ this -> show_deleted ) { $ query -> andFilterWhere ( [ 'is_deleted' => UserFiles :: FILE_UNDELETED , ] ) ; } if ( ! empty ( $ this -> file_created ) && strpos ( $ this -> file_created , '-' ) !== false ) { $ tmp = explode ( ' - ' , $ this -> file_created ) ; if ( isset ( $ tmp [ 0 ] , $ tmp [ 1 ] ) ) { $ start_date = $ tmp [ 0 ] ; $ end_date = $ tmp [ 1 ] ; $ query -> andFilterWhere ( [ 'between' , 'file_created' , date ( SQL_DATE_FORMAT , Functions :: getTimestampBeginOfDayByTimestamp ( strtotime ( $ start_date ) ) ) , date ( SQL_DATE_FORMAT , Functions :: getTimestampEndOfDayByTimestamp ( strtotime ( $ end_date ) ) ) , ] ) ; } } if ( ! empty ( $ this -> file_lastatime ) && strpos ( $ this -> file_lastatime , '-' ) !== false ) { $ tmp = explode ( ' - ' , $ this -> file_lastatime ) ; if ( isset ( $ tmp [ 0 ] , $ tmp [ 1 ] ) ) { $ start_date = $ tmp [ 0 ] ; $ end_date = $ tmp [ 1 ] ; $ query -> andFilterWhere ( [ 'between' , 'file_lastatime' , Functions :: getTimestampBeginOfDayByTimestamp ( strtotime ( $ start_date ) ) , Functions :: getTimestampEndOfDayByTimestamp ( strtotime ( $ end_date ) ) , ] ) ; } } $ query -> andFilterWhere ( [ 'like' , 'file_name' , $ this -> file_name ] ) ; 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
//'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, //'file_created'    => $this->file_created, //'file_updated'    => $this->file_updated, //'node_name'       => $this->node_name, // do we have values? if so, add a filter to our query // do we have values? if so, add a filter to our query