本文整理汇总了PHP中yii\data\ActiveDataProvider::setSort方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::setSort方法的具体用法?PHP ActiveDataProvider::setSort怎么用?PHP ActiveDataProvider::setSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\data\ActiveDataProvider
的用法示例。
在下文中一共展示了ActiveDataProvider::setSort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Number::find();
$query->with('owner', 'documents');
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 30]]);
$dataProvider->setSort(['attributes' => ['number', 'destination', 'comment'], 'defaultOrder' => ['number' => SORT_ASC]]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if (is_numeric($this->searchText)) {
$query->andFilterWhere(['like', 'number', $this->searchText]);
} elseif (!empty($this->searchText)) {
$ownerId = [];
foreach (Employee::findByName($this->searchText, true)->all() as $owner) {
$ownerId[] = $owner->getPrimaryKey();
}
$query->andWhere(['in', 'ownerId', $ownerId]);
}
if ($this->operatorId !== self::OPERATOR_ANY) {
$query->andFilterWhere(['operatorId' => $this->operatorId]);
}
if ($this->destination !== self::DESTINATION_ANY) {
$query->andFilterWhere(['destination' => $this->destination]);
}
$query->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
示例2: search
public function search($params)
{
$query = Profile::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['id', 'first_name', 'last_name', 'birthdate', 'genderName' => ['asc' => ['gender.gender_name' => SORT_ASC], 'desc' => ['gender.gender_name' => SORT_DESC], 'label' => 'Gender'], 'profileIdLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'ID'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User']]]);
if (!($this->load($params) && $this->validate())) {
$query->joinWith(['gender'])->joinWith(['user']);
return $dataProvider;
}
$this->addSearchParameter($query, 'id');
$this->addSearchParameter($query, 'first_name', true);
$this->addSearchParameter($query, 'last_name', true);
$this->addSearchParameter($query, 'birthdate');
$this->addSearchParameter($query, 'gender_id');
$this->addSearchParameter($query, 'created_at');
$this->addSearchParameter($query, 'updated_at');
$this->addSearchParameter($query, 'user_id');
// filter by gender name
$query->joinWith(['gender' => function ($q) {
$q->andFilterWhere(['=', 'gender.gender_name', $this->genderName]);
}])->joinWith(['user' => function ($q) {
$q->andFilterWhere(['=', 'user.id', $this->user]);
}]);
return $dataProvider;
}
示例3: search
/**
* 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;
}
示例4: search
/**
* 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' => 'User'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'profileLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'Profile'], 'roleName' => ['asc' => ['role.role_name' => SORT_ASC], 'desc' => ['role.role_name' => SORT_DESC], 'label' => 'Role'], 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status'], 'userTypeName' => ['asc' => ['user_type.user_type_name' => SORT_ASC], 'desc' => ['user_type.user_type_name' => SORT_DESC], 'label' => 'User Type'], '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(['role'])->joinWith(['status'])->joinWith(['profile'])->joinWith(['userType']);
return $dataProvider;
}
$this->addSearchParameter($query, 'id');
$this->addSearchParameter($query, 'username', true);
$this->addSearchParameter($query, 'email', true);
$this->addSearchParameter($query, 'role_id');
$this->addSearchParameter($query, 'status_id');
$this->addSearchParameter($query, 'user_type_id');
$this->addSearchParameter($query, 'created_at');
$this->addSearchParameter($query, 'updated_at');
// filter by role
$query->joinWith(['role' => function ($q) {
$q->andFilterWhere(['=', 'role.role_name', $this->roleName]);
}])->joinWith(['status' => function ($q) {
$q->andFilterWhere(['=', 'status.status_name', $this->statusName]);
}])->joinWith(['userType' => function ($q) {
$q->andFilterWhere(['=', 'user_type.user_type_name', $this->userTypeName]);
}])->joinWith(['profile' => function ($q) {
$q->andFilterWhere(['=', 'profile.id', $this->profileId]);
}]);
return $dataProvider;
}
示例5: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Users::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$sort = $dataProvider->getSort();
$sort->attributes['officeName'] = ['asc' => ['questionlist_office.name' => SORT_ASC], 'desc' => ['questionlist_office.name' => SORT_DESC], 'label' => 'Имя офиса'];
$dataProvider->setSort($sort);
$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');
$query->joinWith(['questionlist_office']);
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
if ($this->roleName) {
$this->profile_office_role = $this->roleName;
}
$query->andFilterWhere(['like', 'profile_id', $this->profile_id])->andFilterWhere(['like', 'profile_office_role', 'manager']);
$query->joinWith(['office' => function ($q) {
$q->andFilterWhere(['like', 'questionlist_office.name', $this->officeName]);
}]);
$query->joinWith(['region' => function ($q) {
$q->andFilterWhere(['like', 'questionlist_region.name', $this->regionName]);
}]);
return $dataProvider;
}
示例6: search
/**
* 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;
}
示例7: search
/**
* 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;
}
示例8: search
/**
* 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;
}
示例9: search
/**
* 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;
}
示例10: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Restaurant::find();
if ($params['id']) {
$query = Restaurant::find()->where('status!=0 and state !=4');
}
$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 (!($this->load($params) && $this->validate())) {
$query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]);
return $dataProvider;
}
if ($this->state !== null) {
if ($this->state == AppActiveRecord::STATUS_DRAFT) {
$query->andFilterWhere(['state' => $this->state, 'createdBy' => \yii::$app->user->id]);
} else {
$query->andFilterWhere(['state' => $this->state]);
}
} else {
$query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]);
}
$query->andFilterWhere(['Id' => $this->Id, 'sourceId' => $this->sourceId, 'chainId' => $this->chainId, 'cityId' => $this->cityId, 'localityId' => $this->localityId, 'zoneId' => $this->zoneId, 'pin' => $this->pin, 'entityType' => $this->entityType, 'gpsLat' => $this->gpsLat, 'gpsLong' => $this->gpsLong, 'priceForTwo' => $this->priceForTwo, 'capacity' => $this->capacity, 'coverFee' => $this->coverFee, 'entryFee' => $this->entryFee, 'ladiesFee' => $this->ladiesFee, 'hotelId' => $this->hotelId, 'status' => $this->status, 'healthStatus' => $this->healthStatus, 'popularityScore' => $this->popularityScore, 'popularityScroreParams' => $this->popularityScroreParams, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy, 'createdOn' => $this->createdOn, 'updatedOn' => $this->updatedOn, 'popularpubs' => $this->popularpubs, 'launchdate' => $this->launchdate]);
$query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'landmark', $this->landmark])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'tollfree', $this->tollfree])->andFilterWhere(['like', 'phoneAlias', $this->phoneAlias])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'facebook', $this->facebook])->andFilterWhere(['like', 'owner', $this->owner])->andFilterWhere(['like', 'manager', $this->manager])->andFilterWhere(['like', 'tips', $this->tips])->andFilterWhere(['like', 'famousFor', $this->famousFor])->andFilterWhere(['like', 'guid', $this->guid])->andFilterWhere(['like', 'old_guid', $this->old_guid])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'specialities', $this->specialities]);
return $dataProvider;
}
示例11: prepareDataProvider
/**
* 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;
}
示例12: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Pengguna::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['nama_pengguna', 'nama_penuh', 'status', 'namaJabatan' => ['asc' => ['jabatan.nama_jabatan' => SORT_ASC], 'desc' => ['jabatan.nama_jabatan' => SORT_DESC], 'label' => 'Jabatan'], 'namaBahagian' => ['asc' => ['bahagian.nama_bahagian' => SORT_ASC], 'desc' => ['bahagian.nama_bahagian' => SORT_DESC], 'label' => 'Bahagian'], 'namaUnit' => ['asc' => ['unit.nama_unit' => SORT_ASC], 'desc' => ['unit.nama_unit' => SORT_DESC], 'label' => 'Unit']]]);
$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(['like', 'nama_pengguna', $this->nama_pengguna]);
$query->andFilterWhere(['like', 'nama_penuh', $this->nama_penuh]);
// filter by Jabatan
$query->joinWith(['jabatan' => function ($q) {
$q->where('jabatan.nama_jabatan LIKE "%' . $this->namaJabatan . '%"');
}]);
// filter by Bahagian
$query->joinWith(['bahagian' => function ($q) {
$q->where('bahagian.nama_bahagian LIKE "%' . $this->namaBahagian . '%"');
}]);
// filter by Unit
$query->joinWith(['unit' => function ($q) {
$q->where('unit.nama_unit LIKE "%' . $this->namaUnit . '%"');
}]);
return $dataProvider;
}
示例13: search
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['id', 'userIdLink' => ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC], 'label' => 'User'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User'], 'profileLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['profile.id' => SORT_DESC], 'label' => 'Profile'], 'roleName' => ['asc' => ['role.role_name' => SORT_ASC], 'desc' => ['role.role_name' => SORT_DESC], 'label' => 'Role'], 'statusName' => ['asc' => ['status.status_name' => SORT_ASC], 'desc' => ['status.status_name' => SORT_DESC], 'label' => 'Status'], 'userTypeName' => ['asc' => ['user_type.user_type_name' => SORT_ASC], 'desc' => ['user_type.user_type_name' => SORT_DESC], 'label' => 'User Type'], '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(['role'])->joinWith(['status'])->joinWith(['profile'])->joinWith(['userType']);
return $dataProvider;
}
$this->addSearchParameter($query, 'user.id');
$this->addSearchParameter($query, 'username', true);
$this->addSearchParameter($query, 'email', true);
$this->addSearchParameter($query, 'role_id');
$this->addSearchParameter($query, 'status_id');
$this->addSearchParameter($query, 'user_type_id');
$this->addSearchParameter($query, 'created_at');
$this->addSearchParameter($query, 'updated_at');
$query->joinWith(['role' => function ($q) {
$q->where('role.role_name LIKE "%' . $this->roleName . '%"');
}])->joinWith(['status' => function ($q) {
$q->where('status.status_name LIKE "%' . $this->statusName . '%"');
}])->joinWith(['userType' => function ($q) {
$q->where('user_type.user_type_name LIKE "%' . $this->userTypeName . '%"');
}]);
return $dataProvider;
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Book::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['id', 'name', 'authorFullName' => ['asc' => ['authors.firstname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC], 'label' => Yii::t('book', 'authorFullName')], 'date', 'date_create']]);
$this->load($params);
if (!$this->validate()) {
$query->joinWith(['author']);
return $dataProvider;
}
$query->andFilterWhere(['author_id' => $this->author_id]);
$dateFromArray = explode("/", $this->date_from);
$dateForm = count($dateFromArray) == 3 ? $dateFromArray[2] . "-" . $dateFromArray[1] . "-" . $dateFromArray[0] : '';
$dateToArray = explode("/", $this->date_to);
$dateTo = count($dateToArray) == 3 ? $dateToArray[2] . "-" . $dateToArray[1] . "-" . $dateToArray[0] : '';
$query->andFilterWhere(['like', 'name', $this->name]);
if ($dateForm && $dateTo) {
$query->andFilterWhere(['BETWEEN', 'date', $dateForm, $dateTo]);
} else {
if ($dateForm && !$dateTo) {
$query->andFilterWhere(['>=', 'date', $dateForm]);
} else {
if (!$dateForm && $dateTo) {
$query->andFilterWhere(['<=', 'date', $dateTo]);
}
}
}
$query->joinWith(['author' => function ($q) {
}]);
return $dataProvider;
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Books::find()->with('author');
// add conditions that should always apply here
//$this->date_from = '21321';
$dataProvider = new ActiveDataProvider(['query' => $query]);
$dataProvider->setSort(['attributes' => ['id', 'author_id' => ['asc' => ['authors.firstname' => SORT_ASC, 'authors.lastname' => SORT_ASC], 'desc' => ['authors.firstname' => SORT_DESC, 'authors.lastname' => SORT_DESC], 'label' => 'Автор', 'default' => SORT_ASC], 'date', 'date_create', 'name']]);
if (!($this->load($params) && $this->validate())) {
$query->joinWith(['author']);
return $dataProvider;
}
$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, 'author_id' => $this->author_id]);
$query->andFilterWhere(['like', 'name', $this->name]);
if (!empty($this->dateFrom)) {
$query->andFilterWhere(['>=', 'date', $this->dateFrom]);
}
if (!empty($this->dateTo)) {
$query->andFilterWhere(['<=', 'date', $this->dateTo]);
}
return $dataProvider;
}