|
|
|
|
|
|
|
|
'allow' => true, |
|
|
'allow' => true, |
|
|
'roles' => ['@'], |
|
|
'roles' => ['@'], |
|
|
'matchCallback' => function ($rule, $action) { |
|
|
'matchCallback' => function ($rule, $action) { |
|
|
if ($action->actionMethod == 'actionIndex' || |
|
|
|
|
|
$action->actionMethod == 'actionCreate' || |
|
|
|
|
|
$action->actionMethod == 'actionUpdate' || |
|
|
|
|
|
$action->actionMethod == 'actionCredit' || |
|
|
|
|
|
$action->actionMethod == 'actionMail' || |
|
|
|
|
|
$action->actionMethod == 'actionCommandes') { |
|
|
|
|
|
return Yii::$app->user->identity->status == User::STATUS_ADMIN |
|
|
|
|
|
|| Yii::$app->user->identity->status == User::STATUS_BOULANGER; |
|
|
|
|
|
} else { |
|
|
|
|
|
return Yii::$app->user->identity->status == User::STATUS_ADMIN; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return Yii::$app->user->identity->status == USER::STATUS_ADMIN |
|
|
|
|
|
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
], |
|
|
], |
|
|
|
|
|
|
|
|
* Lists all User models. |
|
|
* Lists all User models. |
|
|
* @return mixed |
|
|
* @return mixed |
|
|
*/ |
|
|
*/ |
|
|
public function actionIndex($id_point_vente = 0) { |
|
|
|
|
|
|
|
|
public function actionIndex($id_point_vente = 0, $section_clients_inactifs = false) { |
|
|
$params = Yii::$app->request->queryParams; |
|
|
$params = Yii::$app->request->queryParams; |
|
|
if($id_point_vente) |
|
|
if($id_point_vente) |
|
|
$params['id_point_vente'] = $id_point_vente ; |
|
|
$params['id_point_vente'] = $id_point_vente ; |
|
|
|
|
|
if($section_clients_inactifs) |
|
|
|
|
|
$params['inactifs'] = true ; |
|
|
|
|
|
|
|
|
$query = User::findBy($params); |
|
|
$query = User::findBy($params); |
|
|
$dataProvider = new ActiveDataProvider([ |
|
|
$dataProvider = new ActiveDataProvider([ |
|
|
'query' => $query |
|
|
|
|
|
|
|
|
'query' => $query, |
|
|
|
|
|
'sort' => ['attributes' => ['nom','prenom']], |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$etablissement = Etablissement::find() |
|
|
$etablissement = Etablissement::find() |
|
|
->where(['id' => Yii::$app->user->identity->id_etablissement]) |
|
|
|
|
|
->one(); |
|
|
|
|
|
|
|
|
->where(['id' => Yii::$app->user->identity->id_etablissement]) |
|
|
|
|
|
->one(); |
|
|
|
|
|
|
|
|
$points_vente = PointVente::find()->where(['id_etablissement' => $etablissement->id])->all() ; |
|
|
$points_vente = PointVente::find()->where(['id_etablissement' => $etablissement->id])->all() ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'dataProvider' => $dataProvider, |
|
|
'dataProvider' => $dataProvider, |
|
|
'etablissement' => $etablissement, |
|
|
'etablissement' => $etablissement, |
|
|
'id_point_vente_active' => $id_point_vente, |
|
|
'id_point_vente_active' => $id_point_vente, |
|
|
'points_vente' => $points_vente |
|
|
|
|
|
]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Displays a single User model. |
|
|
|
|
|
* @param integer $id |
|
|
|
|
|
* @return mixed |
|
|
|
|
|
*/ |
|
|
|
|
|
public function actionView($id) { |
|
|
|
|
|
return $this->render('view', [ |
|
|
|
|
|
'model' => $this->findModel($id), |
|
|
|
|
|
|
|
|
'points_vente' => $points_vente, |
|
|
|
|
|
'section_clients_inactifs' => $section_clients_inactifs, |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Creates a new User model. |
|
|
* Creates a new User model. |
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
|
|
|
|
|
|
|
|
$user_etablissement->actif = 1; |
|
|
$user_etablissement->actif = 1; |
|
|
$user_etablissement->save(); |
|
|
$user_etablissement->save(); |
|
|
|
|
|
|
|
|
// send mail |
|
|
|
|
|
if (strlen($model->email)) { |
|
|
|
|
|
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement); |
|
|
|
|
|
Yii::$app->mailer->compose(); |
|
|
|
|
|
$mail = Yii::$app->mailer->compose( |
|
|
|
|
|
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $model, 'etablissement' => $etablissement, 'password' => $password]) |
|
|
|
|
|
->setTo($model->email) |
|
|
|
|
|
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain']) |
|
|
|
|
|
->setSubject('[La boîte à pain] Inscription') |
|
|
|
|
|
->send(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$model->sendMailWelcome($password) ; |
|
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
return $this->redirect(['index']); |
|
|
} else { |
|
|
} else { |
|
|
return $this->render('create', [ |
|
|
return $this->render('create', [ |
|
|
'model' => $model, |
|
|
|
|
|
|
|
|
'model' => $model, |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function actionUpdate($id) { |
|
|
public function actionUpdate($id) { |
|
|
$model = $this->findModel($id); |
|
|
$model = $this->findModel($id); |
|
|
|
|
|
|
|
|
|
|
|
$previous_mail = $model->email ; |
|
|
|
|
|
|
|
|
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one(); |
|
|
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one(); |
|
|
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); |
|
|
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); |
|
|
if (($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { |
|
|
if (($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { |
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
|
|
|
|
|
|
|
|
|
|
// on envoie le mail de bienvenue si le mail vient d'être défini |
|
|
|
|
|
if(!strlen($previous_mail) && strlen($model->email)) { |
|
|
|
|
|
$password = Password::generate(); |
|
|
|
|
|
$model->setPassword($password); |
|
|
|
|
|
$model->username = $model->email; |
|
|
|
|
|
$model->sendMailWelcome($password) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
return $this->redirect(['index']); |
|
|
} else { |
|
|
} else { |
|
|
return $this->render('update', [ |
|
|
return $this->render('update', [ |
|
|
'model' => $model, |
|
|
|
|
|
|
|
|
'model' => $model, |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |