mirror of
https://github.com/janickiy/yii2-nomer
synced 2025-03-09 15:39:59 +00:00
add files to project
This commit is contained in:
commit
5cac498444
3729 changed files with 836998 additions and 0 deletions
58
models/search/UserContactSearch.php
Normal file
58
models/search/UserContactSearch.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace app\models\search;
|
||||
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\UserContact;
|
||||
|
||||
class UserContactSearch extends UserContact
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $phone;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['phone', 'name'], 'string']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search(array $params)
|
||||
{
|
||||
$query = UserContact::find()->where(['user_id' => Yii::$app->getUser()->getIdentity()->id]);
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => ['defaultOrder' => ['name' => SORT_ASC]]
|
||||
]);
|
||||
|
||||
if (!($this->load($params) && $this->validate())) {
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
if ($this->phone) {
|
||||
$query->andFilterWhere(['like', 'phone', $this->phone]);
|
||||
}
|
||||
|
||||
if ($this->name) {
|
||||
$query->andFilterWhere(['like', 'name', $this->name]);
|
||||
}
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue