Pouvoir filtrer les utilisateurs par nom, prenom, telephone, email dans la section "Utilisateurs".prodstable
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$dataProvider = new ActiveDataProvider([ | |||||
'query' => | |||||
(new \yii\db\Query()) | |||||
$params = Yii::$app->request->queryParams; | |||||
$query = (new \yii\db\Query()) | |||||
->select('*') | ->select('*') | ||||
->from('user, user_etablissement') | ->from('user, user_etablissement') | ||||
->where('user.id = user_etablissement.id_user') | ->where('user.id = user_etablissement.id_user') | ||||
->andWhere('user_etablissement.actif = 1') | ->andWhere('user_etablissement.actif = 1') | ||||
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) | |||||
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) ; | |||||
if(isset($params['nom'])) | |||||
$query->andFilterWhere(['like', 'nom', $params['nom']]); | |||||
if(isset($params['prenom'])) | |||||
$query->andFilterWhere(['like', 'prenom', $params['prenom']]) ; | |||||
if(isset($params['email'])) | |||||
$query->andFilterWhere(['like', 'email', $params['email']]) ; | |||||
if(isset($params['telephone'])) | |||||
$query->andFilterWhere(['like', 'telephone', $params['telephone']]) ; | |||||
$dataProvider = new ActiveDataProvider([ | |||||
'query' => $query | |||||
]); | ]); | ||||
$etablissement = Etablissement::find() | $etablissement = Etablissement::find() |
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'filterModel' => true, | |||||
'columns' => [ | 'columns' => [ | ||||
'nom', | |||||
'prenom', | |||||
'telephone', | |||||
'email', | |||||
[ | |||||
'attribute' => 'nom', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'nom', | |||||
isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '', | |||||
[ 'class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | |||||
'attribute' => 'prenom', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'prenom', | |||||
isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | |||||
'attribute' => 'telephone', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'telephone', | |||||
isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | |||||
'attribute' => 'email', | |||||
'filter' => Html::input( | |||||
'string', | |||||
'email', | |||||
isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '', | |||||
['class' => 'form-control'] | |||||
) | |||||
], | |||||
[ | [ | ||||
'attribute' => 'credit', | 'attribute' => 'credit', | ||||
'format' => 'raw', | 'format' => 'raw', |