frontend/models/search/ColleaguesReportsSearch.php
/**
     * Creates data provider instance with search query applied
     * @param array|null $params
     *
     * @return ActiveDataProvider
     */
Creates data provider instance with search query applied
@param array|null $params


Creates data provider instance with search query applied @param array|null $params
public function search($params)
    {
        $query = self::find()
            ->where(['owner_user_id' => Yii::$app->user->identity->getId()]);
        if (!isset($params['tab']) || $params['tab'] != 3) { $params['tab'] = 3; }
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort'=> [
                'defaultOrder' => ['report_date'=>SORT_DESC],
                'attributes' => [
                    'report_date',
                    'colleague_user_email',
                ]
            ],
            'pagination' => [
                'params' => $params,
                'pageSize' => 50,
            ],
        ]);
        if ($params) {
            $this->load($params);
        }
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'colleague_user_email', $this->colleague_user_email]);
        $query->andFilterWhere(['event_type' => $this->event_type]);
        if(!empty($this->created_at_range) && strpos($this->created_at_range, '-') !== false) {
            $tmp = explode(' - ', $this->created_at_range);
            if (isset($tmp[0], $tmp[1])) {
                $start_date = $tmp[0];
                $end_date   = $tmp[1];
                $query->andFilterWhere([
                    'between',
                    'report_date',
                    date(SQL_DATE_FORMAT, Functions::getTimestampBeginOfDayByTimestamp(strtotime($start_date)) - Yii::$app->session->get('UserTimeZoneOffset', 0)),
                    date(SQL_DATE_FORMAT, Functions::getTimestampEndOfDayByTimestamp(strtotime($end_date)) - Yii::$app->session->get('UserTimeZoneOffset', 0)),
                ]);
            }
        }
        return $dataProvider;
    }
public function search ( $ params ) { $ query = self :: find ( ) -> where ( [ 'owner_user_id' => Yii :: $ app -> user -> identity -> getId ( ) ] ) ; if ( ! isset ( $ params [ 'tab' ] ) || $ params [ 'tab' ] != 3 ) { $ params [ 'tab' ] = 3 ; } $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'sort' => [ 'defaultOrder' => [ 'report_date' => SORT_DESC ] , 'attributes' => [ 'report_date' , 'colleague_user_email' , ] ] , 'pagination' => [ 'params' => $ params , 'pageSize' => 50 , ] , ] ) ; if ( $ params ) { $ this -> load ( $ params ) ; } if ( ! $ this -> validate ( ) ) { return $ dataProvider ; } $ query -> andFilterWhere ( [ 'like' , 'colleague_user_email' , $ this -> colleague_user_email ] ) ; $ query -> andFilterWhere ( [ 'event_type' => $ this -> event_type ] ) ; if ( ! empty ( $ this -> created_at_range ) && strpos ( $ this -> created_at_range , '-' ) !== false ) { $ tmp = explode ( ' - ' , $ this -> created_at_range ) ; if ( isset ( $ tmp [ 0 ] , $ tmp [ 1 ] ) ) { $ start_date = $ tmp [ 0 ] ; $ end_date = $ tmp [ 1 ] ; $ query -> andFilterWhere ( [ 'between' , 'report_date' , date ( SQL_DATE_FORMAT , Functions :: getTimestampBeginOfDayByTimestamp ( strtotime ( $ start_date ) ) - Yii :: $ app -> session -> get ( 'UserTimeZoneOffset' , 0 ) ) , date ( SQL_DATE_FORMAT , Functions :: getTimestampEndOfDayByTimestamp ( strtotime ( $ end_date ) ) - Yii :: $ app -> session -> get ( 'UserTimeZoneOffset' , 0 ) ) , ] ) ; } } return $ dataProvider ; }
Creates data provider instance with search query applied
 @param array|null $params
Creates data provider instance with search query applied @param array|null $params
/**
        SELECT
            max(report_date) as report_date,
            concat(
                extract(YEAR FROM report_date), '-',
                extract(MONTH FROM report_date), '-',
                extract(DAY FROM report_date), '-',
                extract(HOUR FROM report_date), '-',
                extract(MINUTE FROM report_date)
            ) as group_date_field,
            CASE WHEN extract(SECOND FROM report_date) > 15 THEN 2
                WHEN extract(SECOND FROM report_date) > 30 THEN 3
                WHEN extract(SECOND FROM report_date) > 45 THEN 4
                ELSE 1
            END as group_seconds_field,
            report_isnew,
            file_id,
            file_parent_id,
            file_parent_id_before_event,
            file_name_after_event,
            file_name_before_event,
            parent_folder_name_after_event,
            parent_folder_name_before_event,
            file_renamed,
            file_moved,
            is_folder,
            event_type,
            owner_user_id,
            colleague_user_id,
            colleague_user_email,
            colleague_node_id
        FROM {{%colleagues_reports}} WHERE owner_user_id=5420
        GROUP BY
            group_date_field,
            group_seconds_field,
            report_isnew,
            file_id,
            file_parent_id,
            file_parent_id_before_event,
            file_name_after_event,
            file_name_before_event,
            parent_folder_name_after_event,
            parent_folder_name_before_event,
            file_renamed,
            file_moved,
            is_folder,
            event_type,
            owner_user_id,
            colleague_user_id,
            colleague_user_email,
            colleague_node_id
         */ // add conditions that should always apply here //var_dump($params); // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); /*
        $query->andFilterWhere([
            'colleague_user_email' => $this->colleague_user_email,
        ]);
        */ // do we have values? if so, add a filter to our query