瀏覽代碼

Améliorations / adaptations user

refactoring
Guillaume Bourgeois 5 年之前
父節點
當前提交
ca04822637
共有 11 個檔案被更改,包括 189 行新增91 行删除
  1. +16
    -17
      backend/controllers/UserController.php
  2. +1
    -1
      backend/views/user/create.php
  3. +2
    -2
      backend/views/user/credit.php
  4. +3
    -3
      backend/views/user/emails.php
  5. +39
    -63
      backend/views/user/index.php
  6. +1
    -1
      backend/views/user/update.php
  7. 二進制
      backend/web/.sass-cache/2a0ffb00578c9d5a537db16d14c734a22b18f35c/screen.scssc
  8. +2
    -2
      backend/web/css/screen.css
  9. +1
    -1
      backend/web/sass/_adminlte.scss
  10. +1
    -1
      backend/web/sass/screen.scss
  11. +123
    -0
      common/models/UserSearch.php

+ 16
- 17
backend/controllers/UserController.php 查看文件

@@ -76,21 +76,19 @@ class UserController extends BackendController
*/
public function actionIndex(
$idPointSale = 0, $sectionInactiveUsers = false)
{
$params = Yii::$app->request->queryParams;
if($idPointSale) {
$params['id_point_sale'] = $idPointSale ;
}
if($sectionInactiveUsers) {
$params['inactive'] = true ;
}
$query = User::findBy($params);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['attributes' => ['lastname','name']],
]);
{
$searchModel = new UserSearch ;
$dataProvider = $searchModel->search([
'UserSearch' => array_merge(
[
'id_point_sale' => $idPointSale,
'inactive' => (int) $sectionInactiveUsers
],
isset(Yii::$app->request->queryParams['UserSearch']) ?
Yii::$app->request->queryParams['UserSearch'] :
[]
)
]) ;
$producer = Producer::searchOne([
'id' => Producer::getId()
@@ -99,6 +97,7 @@ class UserController extends BackendController
$pointsSaleArray = PointSale::searchAll() ;

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'producer' => $producer,
'idPointSaleActive' => $idPointSale,
@@ -224,7 +223,7 @@ class UserController extends BackendController
])->all() ;

$usersArray = [];
foreach ($usersArray as $user) {
foreach ($users as $user) {
if (isset($user['email']) && strlen($user['email']))
$usersArray[] = $user['email'];
}
@@ -233,7 +232,7 @@ class UserController extends BackendController
$pointSale = null ;
if($idPointSale) {
$pointSale = PointSale::findOne(['id' => $idPointSale, 'id_producer' => Producer::getId()]) ;
$pointSale = PointSale::findOne(['id' => $idPointSale]) ;
}

return $this->render('emails', [

+ 1
- 1
backend/views/user/create.php 查看文件

@@ -39,7 +39,7 @@ termes.
use yii\helpers\Html;

$this->setTitle('Ajouter un client') ;
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ;
$this->addBreadcrumb('Ajouter') ;

?>

+ 2
- 2
backend/views/user/credit.php 查看文件

@@ -42,7 +42,7 @@ use common\models\CreditHistory;
use common\models\Producer;

$this->setTitle('Créditer <small>'.Html::encode($user->lastname.' '.$user->name).'</small>', 'Créditer '.Html::encode($user->lastname.' '.$user->name)) ;
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => Html::encode($user->lastname.' '.$user->name)]) ;
$this->addBreadcrumb('Créditer') ;

@@ -58,7 +58,7 @@ $this->addBreadcrumb('Créditer') ;
if(!$producer->credit)
{
echo '<div class="alert alert-warning">Attention, la fonctionnalité <strong>Crédit</strong> est désactivée dans vos <a href="'.Yii::$app->urlManager->createurl(['producer/update']).'">paramètres</a>.'
. ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos clients.</div>' ;
. ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos utilisateurs.</div>' ;
}
?>

+ 3
- 3
backend/views/user/emails.php 查看文件

@@ -49,9 +49,9 @@ $this->addBreadcrumb($this->getTitle()) ;
<li class="<?php if(!isset($pointSale)): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail']); ?>">Tous</a>
</li>
<?php foreach($pointsSaleArray as $pointSale): ?>
<li class="<?php if(isset($pointSale) && $pointSale->id == $pointSale->id): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale'=>$pointSale->id]); ?>"><?= Html::encode($pointSale->name) ?></a>
<?php foreach($pointsSaleArray as $thePointSale): ?>
<li class="<?php if(isset($pointSale) && $pointSale->id == $thePointSale->id): ?>active<?php endif; ?>">
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale'=>$thePointSale->id]); ?>"><?= Html::encode($thePointSale->name) ?></a>
</li>
<?php endforeach; ?>
</ul>

+ 39
- 63
backend/views/user/index.php 查看文件

@@ -66,43 +66,32 @@ $this->addButton(['label' => '+', 'url' => 'user/create', 'class' => 'btn btn-pr
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => true,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'lastname',
'filter' => Html::input(
'string',
'lastname',
isset(Yii::$app->request->queryParams['lastname']) ? Html::encode(Yii::$app->request->queryParams['lastname']) : '',
[ 'class' => 'form-control']
)
],
[
'attribute' => 'name',
'filter' => Html::input(
'string',
'name',
isset(Yii::$app->request->queryParams['name']) ? Html::encode(Yii::$app->request->queryParams['name']) : '',
['class' => 'form-control']
)
],
[
'attribute' => 'phone',
'filter' => Html::input(
'string',
'phone',
isset(Yii::$app->request->queryParams['phone']) ? Html::encode(Yii::$app->request->queryParams['phone']) : '',
['class' => 'form-control']
)
'attribute' => 'username',
'label' => 'Nom',
'value' => function($model) {
return $model['lastname'].' '.$model['name'] ;
}
],
[
'attribute' => 'email',
'filter' => Html::input(
'string',
'email',
isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '',
['class' => 'form-control']
)
'attribute' => 'contacts',
'header' => 'Contacts',
'format' => 'raw',
'value' => function($model) {
$html = '' ;
if(strlen($model['phone'])) {
$html .= $model['phone'] ;
}
if(strlen($model['phone']) && strlen($model['email'])) {
$html .= '<br />' ;
}
if(strlen($model['email'])) {
$html .= $model['email'] ;
}
return $html ;
}
],
[
'attribute' => 'created_at',
@@ -112,32 +101,21 @@ $this->addButton(['label' => '+', 'url' => 'user/create', 'class' => 'btn btn-pr
return date('m/d/Y à H:i', $model['created_at']);
}
],
[
'attribute' => 'date_last_connection',
'label' => 'Dernière connexion',
'value' => function($model) {
if(isset($model['date_last_connection']))
return date('d/m/Y à H:i', strtotime($model['date_last_connection']));
else
return '' ;
}
],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Commandes',
'template' => '{orders}',
'headerOptions' => ['class' => 'actions'],
'buttons' => [
'orders' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/orders','id' => $model['user_id']]) ;
$url = Yii::$app->urlManager->createUrl(['user/orders','id' => $model['id']]) ;
$countOrders = Order::searchCount([
'id_user' => $model['user_id']
'id_user' => $model['id']
], ['conditions' => 'date_delete IS NULL']) ;
$html = '' ;
if($countOrders) {
$s = '' ;
if($countOrders > 1) $s = 's' ;
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$countOrders.' commande'.$s, $url, [
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$countOrders, $url, [
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
]); ;
}
@@ -153,14 +131,13 @@ $this->addButton(['label' => '+', 'url' => 'user/create', 'class' => 'btn btn-pr
'attribute' => 'credit',
'format' => 'raw',
'value' => function($model) use($producer) {
if(!isset($model['credit'])) $model['credit'] = 0 ;
$user = User::findOne($model['user_id']) ;
$user = User::findOne($model->id) ;
$html = '<div class="input-group">
<input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($producer->id),2).' €" placeholder="">
<span class="input-group-btn">
'.Html::a(
'<span class="glyphicon glyphicon-euro"></span> Crédit',
Yii::$app->urlManager->createUrl(['user/credit','id' => $model['user_id']]),
'<span class="glyphicon glyphicon-euro"></span>',
Yii::$app->urlManager->createUrl(['user/credit','id' => $model->id]),
[
'title' => 'Crédit',
'class' => 'btn btn-default'
@@ -174,27 +151,26 @@ $this->addButton(['label' => '+', 'url' => 'user/create', 'class' => 'btn btn-pr
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'actions'],
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ;
$user = User::find()->with('userProducer')->where(['id' => $model['user_id']])->one() ;
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model->id]) ;
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one() ;
if(count($user->userProducer) <= 1)
{
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
]);
}
else {
return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les clients qui sont liés à plusieurs producteurs."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ;
return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les utilisateurs qui sont liés à plusieurs producteurs."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ;
}
},
'delete' => function($url, $model) {
if($model['active']) {
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model['user_id']], Yii::$app->getRequest()->getQueryParams())), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}
'delete' => function($url, $model) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model->id], Yii::$app->getRequest()->getQueryParams())), [
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default'
]);
}
],
],

+ 1
- 1
backend/views/user/update.php 查看文件

@@ -39,7 +39,7 @@ termes.
use yii\helpers\Html;

$this->setTitle('Modifier un client') ;
$this->addBreadcrumb(['label' => 'Clients', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => 'Utilisateurs', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => Html::encode($model->lastname.' '.$model->name)]) ;
$this->addBreadcrumb('Modifier') ;


二進制
backend/web/.sass-cache/2a0ffb00578c9d5a537db16d14c734a22b18f35c/screen.scssc 查看文件


+ 2
- 2
backend/web/css/screen.css 查看文件

@@ -1230,7 +1230,7 @@ a:hover, a:focus, a:active {
.user-index .btn-liste-emails {
float: right;
position: relative;
top: -8px;
top: 6px;
}

/* line 1213, ../sass/screen.scss */
@@ -1479,7 +1479,7 @@ body.skin-black .content-wrapper .table th {
}
/* line 127, ../sass/_adminlte.scss */
body.skin-black .content-wrapper .table th.column-actions, body.skin-black .content-wrapper .table td.column-actions {
width: 130px;
width: 150px;
text-align: right;
}
/* line 131, ../sass/_adminlte.scss */

+ 1
- 1
backend/web/sass/_adminlte.scss 查看文件

@@ -125,7 +125,7 @@ body.skin-black {
font-size: 13px ;
}
th.column-actions, td.column-actions {
width: 130px ;
width: 150px ;
text-align: right ;
}
td.text-small, th.text-small {

+ 1
- 1
backend/web/sass/screen.scss 查看文件

@@ -1205,7 +1205,7 @@ a {
.btn-liste-emails {
float: right ;
position: relative ;
top: -8px ;
top: 6px ;
}
}


+ 123
- 0
common/models/UserSearch.php 查看文件

@@ -0,0 +1,123 @@
<?php

/**
Copyright La boîte à pain (2018)

contact@laboiteapain.net

Ce logiciel est un programme informatique servant à aider les producteurs
à distribuer leur production en circuits courts.

Ce logiciel est régi par la licence CeCILL soumise au droit français et
respectant les principes de diffusion des logiciels libres. Vous pouvez
utiliser, modifier et/ou redistribuer ce programme sous les conditions
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
sur le site "http://www.cecill.info".

En contrepartie de l'accessibilité au code source et des droits de copie,
de modification et de redistribution accordés par cette licence, il n'est
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
seule une responsabilité restreinte pèse sur l'auteur du programme, le
titulaire des droits patrimoniaux et les concédants successifs.

A cet égard l'attention de l'utilisateur est attirée sur les risques
associés au chargement, à l'utilisation, à la modification et/ou au
développement et à la reproduction du logiciel par l'utilisateur étant
donné sa spécificité de logiciel libre, qui peut le rendre complexe à
manipuler et qui le réserve donc à des développeurs et des professionnels
avertis possédant des connaissances informatiques approfondies. Les
utilisateurs sont donc invités à charger et tester l'adéquation du
logiciel à leurs besoins dans des conditions permettant d'assurer la
sécurité de leurs systèmes et ou de leurs données et, plus généralement,
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.

Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

namespace common\models ;

use common\models\User ;

class UserSearch extends User
{
var $id_point_sale ;
var $inactive ;
var $username ;
public function rules()
{
return [
[['no_mail', 'mail_distribution_monday', 'mail_distribution_tuesday', 'mail_distribution_wednesday', 'mail_distribution_thursday', 'mail_distribution_friday', 'mail_distribution_saturday', 'mail_distribution_sunday'], 'boolean'],
[['lastname', 'name', 'phone', 'address'], 'string'],
[['id_point_sale', 'inactive'],'integer'],
[['date_last_connection', 'id_point_sale', 'username'], 'safe'],
];
}

public function search($params)
{
$optionsSearch = self::defaultOptionsSearch() ;
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => ['attributes' => ['username','credit','orders']],
'pagination' => [
'pageSize' => 20,
],
]);
$dataProvider->sort->attributes['username'] = [
'asc' => ['user.lastname' => SORT_ASC, 'user.name' => SORT_ASC],
'desc' => ['user.lastname' => SORT_DESC, 'user.name' => SORT_DESC],
];
$dataProvider->sort->attributes['credit'] = [
'asc' => ['user_producer.credit' => SORT_ASC],
'desc' => ['user_producer.credit' => SORT_DESC],
];
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$active = (isset($this->inactive) && $this->inactive) ? 0 : 1 ;
$query->innerJoin('user_producer','user.id = user_producer.id_user AND user_producer.active = '.$active.' AND user_producer.id_producer = :id_producer', [':id_producer' => Producer::getId()]) ;
if(isset($this->id_point_sale) && $this->id_point_sale) {
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ;
if($pointSale->restricted_access) {
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
else {
$query->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $this->id_point_sale]
)->groupBy('user.id') ;
}
}
if(isset($this->inactive) && $this->inactive) {
$query->innerJoin(
'order',
'user.id = order.id_user'
)
->groupBy('user.id');
}
$query->andFilterWhere([
'or',
['like', 'user.lastname', $this->username],
['like', 'user.name', $this->username]
]);
return $dataProvider;
}
}

Loading…
取消
儲存