php yii-data-ActiveDataProvider类(方法)实例源码

下面列出了php yii-data-ActiveDataProvider 类(方法)源码代码实例,从而了解它的用法。

作者:marianturchy    项目:hom   
public function existUser($post)
 {
     $model = new $this->modelClass();
     $query = $model::find()->orFilterWhere(['login' => $post['login']])->orFilterWhere(['email' => $post['email']]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     return $dataProvider->getCount() === 0 ? false : true;
 }

作者:kmareno    项目:yii2-app-tes   
/**
  * Список учителей, с которыми занимаются только ученики, родившиеся в апреле.
  * @return mixed
  */
 public function actionApril()
 {
     $title = 'Список учителей, с которыми занимаются только ученики, родившиеся в апреле';
     $dataProvider = new ActiveDataProvider(['query' => Teacher::teachsOnlyAprilBornStudents()]);
     $dataProvider->setSort(['defaultOrder' => ['name' => SORT_ASC], 'attributes' => ['name', 'gender', 'phone', 'students_count' => ['asc' => ['stud_cnt' => SORT_ASC], 'desc' => ['stud_cnt' => SORT_DESC]]]]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'title' => $title]);
 }

作者:mrhat2    项目:site-for-p   
/** 
  * Creates data provider instance with search query applied 
  * 
  * @param array $params 
  * 
  * @return ActiveDataProvider 
  */
 public function search($params)
 {
     $query = Lesson::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'groupName' => ['asc' => ['group.name' => SORT_ASC], 'desc' => ['group.name' => SORT_DESC], 'label' => 'groupName'], 'disciplineName' => ['asc' => ['discipline.name' => SORT_ASC], 'desc' => ['discipline.name' => SORT_DESC], 'label' => 'disciplineName'], 'teacherFullname' => ['asc' => ['user.last_name' => SORT_ASC, 'user.first_name' => SORT_ASC, 'user.middle_name' => SORT_ASC], 'desc' => ['user.last_name' => SORT_DESC, 'user.first_name' => SORT_DESC, 'user.middle_name' => SORT_DESC], 'label' => 'teacherFullname'], 'lessonTypeName' => ['asc' => ['lesson_type.name' => SORT_ASC], 'desc' => ['lesson_type.name' => SORT_DESC], 'label' => 'lessonTypeName'], 'week', 'day', 'time', 'auditory']]);
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'ghd_id' => $this->ghd_id, 'lesson_type_id' => $this->lesson_type_id, 'week' => $this->week, 'day' => $this->day, 'time' => $this->time, 'date' => $this->date]);
     $query->andFilterWhere(['like', 'auditory', $this->auditory]);
     $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.group' => function ($q) {
         $q->where('group.name LIKE "%' . $this->groupName . '%" ');
     }]);
     $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.discipline' => function ($q) {
         $q->where('discipline.name LIKE "%' . $this->disciplineName . '%" ');
     }]);
     $query->joinWith('teacherHasDiscipline')->joinWith('teacherHasDiscipline.teacher')->joinWith(['teacherHasDiscipline.teacher.user' => function ($q) {
         $q->where('user.first_name LIKE "%' . $this->teacherFullname . '%" ' . 'OR user.last_name LIKE "%' . $this->teacherFullname . '%"' . 'OR user.middle_name LIKE "%' . $this->teacherFullname . '%"');
     }]);
     $query->joinWith(['lessonType' => function ($q) {
         $q->where('lesson_type.name LIKE "%' . $this->lessonTypeName . '%" ');
     }]);
     return $dataProvider;
 }

作者:santonil200    项目:yi   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find()->select('comment.*, video.title, user.username')->innerJoin('video', '`video`.`id` = `comment`.`video_id`')->innerJoin('user', '`user`.`id` = `comment`.`user_id`');
     // echo $query->createCommand()->sql;exit;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['pageSize']]]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params) 
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'text' => ['asc' => ['comment.text' => SORT_ASC], 'desc' => ['comment.text' => SORT_DESC]], 'videoTitle' => ['asc' => ['video.title' => SORT_ASC], 'desc' => ['video.title' => SORT_DESC]], 'username' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]], 'created_at' => ['asc' => ['comment.created_at' => SORT_ASC], 'desc' => ['comment.created_at' => SORT_DESC]]]]);
     $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;
     }
     /* ---------------------------------------------------------------------/
      * Filter
      * --------------------------------------------------------------------- */
     $query->andFilterWhere(['comment.id' => $this->id, 'comment.video_id' => $this->video_id, 'comment.user_id' => $this->user_id, 'comment.created_at' => $this->created_at, 'comment.modified_at' => $this->modified_at]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     /**
      * for related column
      */
     $query->andFilterWhere(['like', 'video.title', $this->videoTitle]);
     $query->andFilterWhere(['like', 'user.username', $this->username]);
     return $dataProvider;
 }

作者:rajanishtime    项目:basicyi   
public function search($params)
 {
     $query = group::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['defaultOrder' => ['parentId' => SORT_ASC, 'name' => SORT_ASC]]);
     $query->andFilterWhere([group::tableName() . '.status' => '1']);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['parent']);
         return $dataProvider;
     }
     /*$query->andFilterWhere([
           'Id' => $this->Id,
           'createdon' => $this->createdon,
       ]);//*/
     $query->andFilterWhere(['like', group::tableName() . '.name', $this->name]);
     //->andFilterWhere(['like', 'parentId', $this->ParentGroup])
     //->andFilterWhere(['like', 'status', $this->status]);
     if ($this->parentGroup != '' && strtolower($this->parentGroup) != 'root') {
         $query->joinWith(['parent' => function ($q) {
             $q->where('parent.name LIKE "%' . $this->parentGroup . '%" ');
         }]);
     } else {
         if (strtolower($this->parentGroup) == 'root') {
             $query->andFilterWhere([group::tableName() . '.parentId' => 0]);
         }
     }
     return $dataProvider;
 }

作者:mrhat2    项目:site-for-p   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $newquery = null)
 {
     $query = GroupHasDiscipline::find();
     if ($newquery) {
         $query = $newquery;
     }
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'semester_number', 'semesterNumber' => ['asc' => ['group_semesters.semester_number' => SORT_ASC], 'desc' => ['group_semesters.semester_number' => SORT_DESC]], 'groupName' => ['asc' => ['group.name' => SORT_ASC], 'desc' => ['group.name' => SORT_DESC]], 'disciplineName' => ['asc' => ['discipline.name' => SORT_ASC], 'desc' => ['discipline.name' => SORT_DESC]]]]);
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'discipline_id' => $this->discipline_id, 'group_id' => $this->group_id, 'group_has_discipline.semester_number' => $this->semester_number]);
     $query->joinWith(['semester' => function ($q) {
         $q->where('group_semesters.semester_number LIKE "%' . $this->semesterNumber . '%" ');
     }]);
     $query->joinWith(['group' => function ($q) {
         $q->where('group.name LIKE "%' . $this->groupName . '%" ');
     }]);
     $query->joinWith(['discipline' => function ($q) {
         $q->where('discipline.name LIKE "%' . $this->disciplineName . '%" ');
     }]);
     return $dataProvider;
 }

作者:mrhat2    项目:site-for-p   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Work::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'studentFullname' => ['asc' => ['user.last_name' => SORT_ASC], 'desc' => ['user.last_name' => SORT_DESC], 'label' => 'studentFullname'], 'groupName' => ['asc' => ['student.group.name' => SORT_ASC], 'desc' => ['student.group.name' => SORT_DESC], 'label' => 'groupName'], 'disciplineName' => ['asc' => ['groupHasDiscipline.discipline.name' => SORT_ASC], 'desc' => ['groupHasDiscipline.discipline.name' => SORT_DESC]]]]);
     $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(['id' => $this->id, 'work_type_id' => $this->work_type_id, 'name' => $this->name, 'student_id' => $this->student_id, 'teacher_id' => $this->teacher_id, 'date' => $this->date, 'approve_status' => $this->approve_status]);
     $query->joinWith('student')->joinWith(['student.user' => function ($q) {
         $q->where('user.first_name LIKE "%' . $this->studentFullname . '%" ' . 'OR user.last_name LIKE "%' . $this->studentFullname . '%"' . 'OR user.middle_name LIKE "%' . $this->studentFullname . '%"');
     }]);
     $query->joinWith('student')->joinWith(['student.group' => function ($q) {
         $q->where('group.name LIKE "%' . $this->groupName . '%" ');
     }]);
     if ($this->work_type_id == Work::TYPE_TERM) {
         $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.discipline' => function ($q) {
             $q->where('discipline.name LIKE "%' . $this->disciplineName . '%" ');
         }]);
     }
     return $dataProvider;
 }

作者:rvence    项目:tu3_yii   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params)
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'ID'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'perfilLink' => ['asc' => ['perfil.id' => SORT_ASC], 'desc' => ['perfil.id' => SORT_DESC], 'label' => 'Perfil'], 'rolNombre' => ['asc' => ['rol.rol_name' => SORT_ASC], 'desc' => ['rol.rol_name' => SORT_DESC], 'label' => 'Rol'], 'estadoNombre' => ['asc' => ['estado.estado_nombre' => SORT_ASC], 'desc' => ['estado.estado_nombre' => SORT_DESC], 'label' => 'Estado'], 'created_at' => ['asc' => ['created_at' => SORT_ASC], 'desc' => ['created_at' => SORT_DESC], 'label' => 'Created At'], 'email' => ['asc' => ['email' => SORT_ASC], 'desc' => ['email' => SORT_DESC], 'label' => 'Email']]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['rol'])->joinWith(['estado'])->joinWith(['perfil']);
         return $dataProvider;
     }
     $this->addSearchParameter($query, 'id');
     $this->addSearchParameter($query, 'username', true);
     $this->addSearchParameter($query, 'email', true);
     $this->addSearchParameter($query, 'rol_id');
     $this->addSearchParameter($query, 'estado_id');
     $this->addSearchParameter($query, 'created_at');
     $this->addSearchParameter($query, 'updated_at');
     // filter by role
     $query->joinWith(['rol' => function ($q) {
         $q->andFilterWhere(['=', 'rol.rol_nombre', $this->rolNombre]);
     }])->joinWith(['estado' => function ($q) {
         $q->andFilterWhere(['=', 'estado.estado_nombre', $this->estadoNombre]);
     }])->joinWith(['perfil' => function ($q) {
         $q->andFilterWhere(['=', 'perfil.id', $this->perfilId]);
     }]);
     return $dataProvider;
 }

作者:maxxe    项目:yii2-translate-manage   
/**
  * @param array $params Search conditions.
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $translateLanguage = Yii::$app->request->get('language_id', Yii::$app->sourceLanguage);
     $sourceLanguage = $this->_getSourceLanguage();
     $query = LanguageSource::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'category', 'message', 'translation' => ['asc' => ['lt.translation' => SORT_ASC], 'desc' => ['lt.translation' => SORT_DESC], 'label' => Yii::t('language', 'Translation')]]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['languageTranslate' => function ($query) use($translateLanguage) {
             $query->from(['lt' => LanguageTranslate::tableName()])->onCondition(['lt.language' => $translateLanguage]);
         }]);
         $query->joinWith(['languageTranslateByLanguage' => function ($query) use($sourceLanguage) {
             $query->from(['ts' => LanguageTranslate::tableName()])->onCondition(['ts.language' => $sourceLanguage]);
         }]);
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category' => $this->category]);
     $query->andFilterWhere(['or', $this->createLikeExpression('message', $this->message), $this->createLikeExpression('ts.translation', $this->message)]);
     $query->joinWith(['languageTranslate' => function ($query) use($translateLanguage) {
         $query->from(['lt' => LanguageTranslate::tableName()])->onCondition(['lt.language' => $translateLanguage])->andFilterWhere($this->createLikeExpression('lt.translation', $this->translation));
     }]);
     $query->joinWith(['languageTranslateByLanguage' => function ($query) use($sourceLanguage) {
         $query->from(['ts' => LanguageTranslate::tableName()])->onCondition(['ts.language' => $sourceLanguage]);
     }]);
     return $dataProvider;
 }

作者:kirill-g-    项目:humhu   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find()->joinWith('profile');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $dataProvider->setSort(['attributes' => ['id', 'username', 'email', 'super_admin', 'last_login', 'profile.firstname', 'profile.lastname', 'created_at']]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     if (strtolower($this->last_login) == 'yes') {
         $query->andWhere(['not', ['last_login' => null]]);
     } else {
         if (strtolower($this->last_login) == 'no') {
             $query->andWhere(['last_login' => null]);
         }
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['super_admin' => $this->super_admin]);
     $query->andFilterWhere(['like', 'id', $this->id]);
     $query->andFilterWhere(['like', 'username', $this->username]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     $query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('profile.firstname')]);
     $query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('profile.lastname')]);
     return $dataProvider;
 }

作者:stance    项目:biz-referral-clu   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     //$query = REFERRALGIVEN::find();
     $query = REFERRALGIVEN::find()->joinWith(['rEFERRAL']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params) 
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['GIVEN_ID', 'MEMBER_ID', 'referralName' => ['asc' => ['REFERRAL.REFERRAL_NAME' => SORT_ASC], 'desc' => ['REFERRAL.REFERRAL_NAME' => SORT_DESC], 'label' => 'Referral Name'], 'MEETING_ID']]);
     if (!($this->load($params) && $this->validate())) {
         //Brad
         //$query->joinWith(['rEFERRAL']);
         return $dataProvider;
     }
     $query->andFilterWhere(['GIVEN_ID' => $this->GIVEN_ID, 'MEMBER_ID' => $this->MEMBER_ID, 'REFERRAL_ID' => $this->REFERRAL_ID, 'MEETING_ID' => $this->MEETING_ID]);
     $query->andFilterWhere(['like', 'GIVEN_YOUR_CARD', $this->GIVEN_YOUR_CARD])->andFilterWhere(['like', 'TOLD_THEM_YOU_WOULD_CALL', $this->TOLD_THEM_YOU_WOULD_CALL])->andFilterWhere(['like', 'COMMENTS', $this->COMMENTS]);
     // filter by Referral name - Brad
     //        $query->joinWith(['rEFERRAL'=>function ($q) {
     //            $q->where('rEFERRAL.REFERRAL_NAME LIKE "%' .
     //                $this->referralName . '%"');
     //        }]);
     return $dataProvider;
 }

作者:SimonBaeume    项目:humhu   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find()->joinWith('profile');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]);
     $dataProvider->setSort(['attributes' => ['id', 'username', 'email', 'super_admin', 'last_login', 'profile.firstname', 'profile.lastname', 'created_at']]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['super_admin' => $this->super_admin]);
     $query->andFilterWhere(['like', 'id', $this->id]);
     $query->andFilterWhere(['like', 'username', $this->username]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     $query->andFilterWhere(['like', 'profile.firstname', $this->getAttribute('profile.firstname')]);
     $query->andFilterWhere(['like', 'profile.lastname', $this->getAttribute('profile.lastname')]);
     if ($this->getAttribute('last_login') != "") {
         try {
             $last_login = Yii::$app->formatter->asDate($this->getAttribute('last_login'), 'php:Y-m-d');
             $query->andWhere(['=', new \yii\db\Expression("DATE(last_login)"), new \yii\db\Expression("DATE(:last_login)", [':last_login' => $last_login])]);
         } catch (InvalidParamException $e) {
             // do not change the query if the date is wrong formatted
         }
     }
     return $dataProvider;
 }

作者:sfedosimo    项目:TestTas   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Books::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Настройка параметров сортировки
      * Важно: должна быть выполнена раньше $this->load($params)
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'name', 'author' => ['asc' => ['lastname' => SORT_ASC, 'firstname' => SORT_ASC], 'desc' => ['lastname' => SORT_DESC, 'firstname' => SORT_DESC], 'default' => SORT_ASC], 'date', 'date_create']]);
     $query->joinWith(['authors']);
     if (!($this->load($params) && $this->validate())) {
         /**
          * Жадная загрузка данных модели Страны
          * для работы сортировки.
          */
         return $dataProvider;
     }
     $query->andFilterWhere(['books.id' => $this->id, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     // Фильтр по полному имени
     $query->andWhere('authors.firstname LIKE "%' . $this->author . '%" ' . 'OR authors.lastname LIKE "%' . $this->author . '%"');
     // Фильтр по дате
     /*
     // Если на форме нужно воодить как на плейсхолдере
     $myDateTime= DateTime::createFromFormat('d/m/Y', $this->date_begin);
     $myDateTime->format('Y-m-d');
     */
     $query->andFilterWhere(['>=', 'date', $this->date_begin]);
     $query->andFilterWhere(['<=', 'date', $this->date_end]);
     return $dataProvider;
 }

作者:rajanishtime    项目:partnerap   
/**
  * Prepares the data provider that should return the requested collection of the models.
  * @return ActiveDataProvider
  */
 protected function prepareDataProvider()
 {
     if ($this->prepareDataProvider !== null) {
         return call_user_func($this->prepareDataProvider, $this);
     }
     /**
      * @var \yii\db\BaseActiveRecord $modelClass
      */
     $modelClass = $this->modelClass;
     $searchClass = new EventSearch();
     $query = $modelClass::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['defaultOrder' => ['updatedOn' => SORT_DESC]]);
     $query->andWhere("not ((`state`=" . AppActiveRecord::STATUS_DRAFT . ") AND (`createdBy`!=" . \yii::$app->user->id . "))");
     if (!($searchClass->load(Yii::$app->request->queryParams, '') && $searchClass->validate())) {
         $query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]);
         return $dataProvider;
     }
     if ($searchClass->state !== null) {
         if ($searchClass->state == AppActiveRecord::STATUS_DRAFT) {
             $query->andFilterWhere(['state' => $this->state, 'createdBy' => \yii::$app->user->id]);
         } else {
             $query->andFilterWhere(['state' => $searchClass->state]);
         }
     } else {
         $query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]);
     }
     $query->andFilterWhere(['Id' => $searchClass->Id, 'sourceId' => $searchClass->sourceId, 'cityId' => $searchClass->cityId, 'zoneId' => $searchClass->zoneId, 'localityId' => $searchClass->localityId, 'gpsLat' => $searchClass->gpsLat, 'gpsLong' => $searchClass->gpsLong, 'startDate' => $searchClass->startDate, 'endDate' => $searchClass->endDate, 'startTime' => $searchClass->startTime, 'endTime' => $searchClass->endTime, 'status' => $searchClass->status, 'isRecursive' => $searchClass->isRecursive, 'healthStatus' => $searchClass->healthStatus, 'createdOn' => $searchClass->createdOn, 'createdBy' => $searchClass->createdBy, 'updatedOn' => $searchClass->updatedOn, 'updatedBy' => $searchClass->updatedBy]);
     $query->andFilterWhere(['like', 'categoryId', $searchClass->categoryId])->andFilterWhere(['like', 'name', $searchClass->name])->andFilterWhere(['like', 'description', $searchClass->description])->andFilterWhere(['like', 'address', $searchClass->address])->andFilterWhere(['like', 'landmark', $searchClass->landmark])->andFilterWhere(['like', 'pincode', $searchClass->pincode])->andFilterWhere(['like', 'tollfree', $searchClass->tollfree])->andFilterWhere(['like', 'contactName', $searchClass->contactName])->andFilterWhere(['like', 'email', $searchClass->email])->andFilterWhere(['like', 'url', $searchClass->url])->andFilterWhere(['like', 'shopurl', $searchClass->shopurl])->andFilterWhere(['like', 'price', $searchClass->price])->andFilterWhere(['like', 'ip', $searchClass->ip])->andFilterWhere(['like', 'recursionData', $searchClass->recursionData])->andFilterWhere(['like', 'oldGuid', $searchClass->oldGuid])->andFilterWhere(['like', 'guid', $searchClass->guid])->andFilterWhere(['like', 'multipleTimings', $searchClass->multipleTimings])->andFilterWhere(['like', 'weekdaysChecklist', $searchClass->weekdaysChecklist]);
     /*$query->joinWith('eventMap')->andFilterWhere(['like', 'phone', $this->phone])
       ->andFilterWhere(['like', 'mobile', $this->mobile]);//*/
     return $dataProvider;
 }

作者:jiaweizho    项目:allianc   
/**
  * Lists all Applyjobs models.
  * @return mixed
  */
 public function actionSearch()
 {
     $data = Yii::$app->request->post();
     $longitude = $data['longitude'];
     $latitude = $data['latitude'];
     $query = (new \yii\db\Query())->select('daters.*,users.phone,users.nickname,users.thumb,hobbies.hobby')->from('daters')->orderBy(sprintf('abs(daters.longitude - %f) + abs(daters.latitude - %f)', $longitude, $latitude))->join('INNER JOIN', 'users', 'daters.userid = users.id')->join('INNER JOIN', 'hobbies', 'daters.hobbyid = hobbies.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //$this->load($params);
     //$value = 0;
     if (!empty($data)) {
         if (isset($data['phone'])) {
             $query->andFilterWhere(['users.phone' => $data['phone']]);
         }
         if (isset($data['hobbyid'])) {
             $query->andFilterWhere(['hobbyid' => $data['hobbyid']]);
         }
         if (isset($data['content'])) {
             $query->andFilterWhere(['like', 'content', $data['content']]);
         }
     }
     $daters = $dataProvider->getModels();
     //$result = array ();
     //$result ['item'] = array ();
     //$tbreplys = (new \yii\db\Query ())->select('tbreplys.*,users.phone,users.nickname,users.thumb')->orderBy ( "tbreplys.created_at desc" )->join ( 'INNER JOIN', 'users', ' tbmessages.userid =users.id ')->where('tbreplys.messageid in ');
     foreach ($daters as $i => $dater) {
         $info = $dater;
         $info["distance"] = $this->getDistance($latitude, $longitude, $info['latitude'], $info['longitude']);
         $daters[$i] = $info;
     }
     $dataProvider->setModels($daters);
     return $dataProvider;
 }

作者:adem-tea    项目:advance   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Grandchild::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params) 
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['parent_id', 'ParentsName' => ['asc' => ['fr001.parent' => SORT_ASC], 'desc' => ['fr001.parent' => SORT_DESC], 'label' => 'Parent Name'], 'ChildName' => ['asc' => ['fr000.CHILD_NAME' => SORT_ASC], 'desc' => ['fr000.CHILD_NAME' => SORT_DESC], 'label' => 'Child Name']]]);
     if (!($this->load($params) && $this->validate())) {
         /**
          * The following line will allow eager loading with country data 
          * to enable sorting by country on initial loading of the grid.
          */
         $query->joinWith(['parents']);
         $query->joinWith(['child']);
         return $dataProvider;
     }
     /* Add your filtering criteria */
     // filter by parent name
     $query->joinWith(['parents' => function ($q) {
         $q->where('fr001.parent LIKE "%' . $this->ParentsName . '%"');
     }]);
     return $dataProvider;
 }

作者:AnduZhan    项目:nw   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = WeatherAlert::find();
     $query->joinWith(['userReadAlerts.weatherAlert']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'magnitude', 'event', 'date', 'severity', 'stormName' => ['asc' => ['id' => SORT_ASC], 'desc' => ['id' => SORT_DESC], 'label' => 'Storm Name', 'default' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'magnitude' => $this->magnitude, 'identifier' => $this->identifier]);
     $query->andFilterWhere(['like', 'severity', $this->severity]);
     $query->andFilterWhere(['=', 'WeatherAlert.type', $this->type]);
     $query->andFilterWhere(['=', 'WeatherAlert.event', $this->event]);
     $query->andFilterWhere(['=', 'WeatherAlert.status', WeatherAlert::STATUS_ACTUAL]);
     //        var_dump(time() - Yii::$app->params['timePeriodForRecentAlerts']*3600);die;
     $timePeriodForAlert = $this->type == 0 ? Yii::$app->params['timePeriodForRecentPreAlerts'] : Yii::$app->params['timePeriodForRecentPostAlerts'];
     //        if ($this->type == 1) {
     //            var_dump($timePeriodForAlert);die;
     //        }
     $query->andFilterWhere(['>', 'WeatherAlert.date', time() - $timePeriodForAlert * 3600]);
     //        $query->addSelect('COUNT(UserReadAlerts.User_id)');
     //        $query->andFilterWhere(['=', 'UserReadAlerts.User_id', Yii::$app->user->id]);
     //        $query->andFilterWhere(['=', 'UserReadAlerts.WeatherAlert_id', $this->id]);
     //        if (!Yii::$app->request->isPjax) {
     //
     //        }
     $query->orderBy(['WeatherAlert.date' => SORT_DESC]);
     //        $query->orderBy(['UserReadAlerts.User_id'=>'DESC']);
     $query->groupBy(['WeatherAlert.id']);
     return $dataProvider;
 }

作者:aekkapu    项目:yii2-podiu   
/**
  * Returns categories.
  * @return Category[]
  */
 public function show()
 {
     $query = self::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->defaultOrder = ['sort' => SORT_ASC, 'id' => SORT_ASC];
     return $dataProvider->getModels();
 }

作者:djc110361771    项目:WangY   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Manager::find();
     // add conditions that should always apply here
     $query = $query->innerJoinWith('user');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['user_id', 'status', 'created_at', 'updated_at', 'username' => ['asc' => ['wy_user.username' => SORT_ASC], 'desc' => ['wy_user.username' => SORT_DESC], 'label' => 'Username'], 'userStatus' => ['asc' => ['wy_user.status' => SORT_ASC], 'desc' => ['wy_user.status' => SORT_DESC], 'label' => 'User Status']]]);
     $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;
     }
     if ($this->status == '合法') {
         $this->status = 1;
     } elseif ($this->status == '冻结') {
         $this->status = 2;
     }
     if ($this->userStatus == '合法') {
         $this->userStatus = 1;
     } elseif ($this->userStatus == '冻结') {
         $this->userStatus = 2;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'wy_manager.status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'wy_user.status' => $this->userStatus]);
     $query->andFilterWhere(['like', 'wy_user.username', $this->username]);
     return $dataProvider;
 }

作者:robk    项目:t   
/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DataList::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Настройка параметров сортировки
      * Важно: должна быть выполнена раньше $this->load($params)
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'id_device', 'deviceName' => ['asc' => ['device.name_device' => SORT_ASC], 'desc' => ['device.name_device' => SORT_DESC], 'label' => 'Прибор'], 'dataRef' => ['asc' => ['data_ref.name_ref' => SORT_ASC], 'desc' => ['data_ref.name_ref' => SORT_DESC]], 'number', 'time_point', 'work_data', 'typeDataRef' => ['asc' => ['data_ref.type_data_ref' => SORT_ASC], 'desc' => ['data_ref.type_data_ref' => SORT_DESC]]]]);
     if (!($this->load($params) && $this->validate())) {
         /**
          * Жадная загрузка данных типа приборов
          * для работы сортировки.
          */
         $query->joinWith(['idDevice']);
         $query->joinWith(['idDataRef']);
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['data_list.id' => $this->id, 'id_device' => $this->id_device, 'id_data_ref' => $this->id_data_ref, 'number' => $this->number, 'time_point' => $this->time_point, 'work_data' => $this->work_data]);
     // Фильтр по типу прибора
     $query->joinWith(['idDevice' => function ($q) {
         $q->andFilterWhere(['like', 'device.name_device', $this->deviceName]);
     }]);
     // Фильтр по типу данных
     $query->joinWith(['idDataRef' => function ($q) {
         $q->andFilterWhere(['like', 'data_ref.name_ref', $this->dataRef]);
         $q->andFilterWhere(['like', 'data_ref.type_data_ref', $this->typeDataRef]);
     }]);
     return $dataProvider;
 }


问题


面经


文章

微信
公众号

扫码关注公众号