Przeglądaj źródła

Merge branch 'dev'

prodstable
keun 6 lat temu
rodzic
commit
eaeec1f2ac
3 zmienionych plików z 62 dodań i 49 usunięć
  1. +28
    -42
      backend/controllers/UserController.php
  2. +9
    -4
      backend/views/user/index.php
  3. +25
    -3
      common/models/User.php

+ 28
- 42
backend/controllers/UserController.php Wyświetl plik

@@ -21,17 +21,8 @@ class UserController extends BackendController {
'allow' => true,
'roles' => ['@'],
'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;
}
]
],
@@ -43,18 +34,22 @@ class UserController extends BackendController {
* Lists all User models.
* @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;
if($id_point_vente)
$params['id_point_vente'] = $id_point_vente ;
if($section_clients_inactifs)
$params['inactifs'] = true ;
$query = User::findBy($params);
$dataProvider = new ActiveDataProvider([
'query' => $query
'query' => $query,
'sort' => ['attributes' => ['nom','prenom']],
]);
$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() ;

@@ -62,21 +57,11 @@ class UserController extends BackendController {
'dataProvider' => $dataProvider,
'etablissement' => $etablissement,
'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.
* If creation is successful, the browser will be redirected to the 'view' page.
@@ -106,22 +91,12 @@ class UserController extends BackendController {
$user_etablissement->actif = 1;
$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']);
} else {
return $this->render('create', [
'model' => $model,
'model' => $model,
]);
}
}
@@ -135,14 +110,25 @@ class UserController extends BackendController {
public function actionUpdate($id) {
$model = $this->findModel($id);

$previous_mail = $model->email ;
$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]);
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()) {
// 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']);
} else {
return $this->render('update', [
'model' => $model,
'model' => $model,
]);
}
} else {

+ 9
- 4
backend/views/user/index.php Wyświetl plik

@@ -20,7 +20,7 @@ $this->params['breadcrumbs'][] = $this->title;
</h1>
<ul id="tabs-points-vente" class="nav nav-tabs" role="tablist">
<li class="<?php if(!$id_point_vente_active): ?>active<?php endif; ?>">
<li class="<?php if(!$id_point_vente_active && !$section_clients_inactifs): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a>
</li>
<?php foreach($points_vente as $pv): ?>
@@ -28,6 +28,9 @@ $this->params['breadcrumbs'][] = $this->title;
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a>
</li>
<?php endforeach; ?>
<li class="<?php if($section_clients_inactifs): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','section_clients_inactifs' => 1]); ?>">Inactifs</a>
</li>
</ul>

<?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail', 'id_point_vente' => $id_point_vente_active], ['class' => 'btn btn-default btn-liste-emails']) ?>
@@ -161,9 +164,11 @@ $this->params['breadcrumbs'][] = $this->title;
}
},
'delete' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(['user/delete','id' => $model['user_id']]), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
if($model['actif']) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(['user/delete','id' => $model['user_id']]), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}
}
],
],

+ 25
- 3
common/models/User.php Wyświetl plik

@@ -161,9 +161,10 @@ class User extends ActiveRecord implements IdentityInterface {
$query = (new \yii\db\Query())
->select(['user.id AS user_id', 'user.prenom', 'user.nom', 'user.telephone', 'user.email', 'user.created_at', 'user.date_derniere_connexion', 'user_etablissement.*'])
->from('user')
->innerJoin('user_etablissement','user.id = user_etablissement.id_user AND user_etablissement.actif = 1 AND user_etablissement.id_etablissement = :id_etablissement', [':id_etablissement' => $params['id_etablissement']])
;
->from('user');
$actif = (isset($params['inactifs']) && $params['inactifs']) ? 0 : 1 ;
$query->innerJoin('user_etablissement','user.id = user_etablissement.id_user AND user_etablissement.actif = '.$actif.' AND user_etablissement.id_etablissement = :id_etablissement', [':id_etablissement' => $params['id_etablissement']]) ;
if(isset($params['id_point_vente']) && $params['id_point_vente']) {
$point_vente = PointVente::findOne(['id' => $params['id_point_vente']]) ;
@@ -179,6 +180,13 @@ class User extends ActiveRecord implements IdentityInterface {
}
}
if(isset($params['inactifs']) && $params['inactifs']) {
$query->innerJoin(
'commande',
'user.id = commande.id_user'
)
->groupBy('user.id');
}
if (isset($params['nom']))
$query->andFilterWhere(['like', 'nom', $params['nom']]);
@@ -355,5 +363,19 @@ class User extends ActiveRecord implements IdentityInterface {
$this->date_derniere_connexion = date('Y-m-d H:i:s');
$this->save();
}
public function sendMailWelcome($password) {
if (strlen($this->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' => $this, 'etablissement' => $etablissement, 'password' => $password]
)
->setTo($this->email)
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain'])
->setSubject('[La boîte à pain] Inscription')
->send();
}
}

}

Ładowanie…
Anuluj
Zapisz