Pārlūkot izejas kodu

[Administration] Utilisateurs > liste : filtres de recherche #1270

feature/souke
Guillaume Bourgeois pirms 1 gada
vecāks
revīzija
e91bb4d165
3 mainītis faili ar 70 papildinājumiem un 44 dzēšanām
  1. +36
    -36
      backend/views/user/index.php
  2. +24
    -8
      common/logic/User/User/Model/UserSearch.php
  3. +10
    -0
      common/logic/User/User/Service/UserSolver.php

+ 36
- 36
backend/views/user/index.php Parādīt failu

@@ -36,14 +36,12 @@
* termes.
*/

use common\components\PageSizer;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use yii\helpers\Html;
use yii\grid\GridView;
use common\logic\User\User\Wrapper\UserModule;
use common\logic\Order\Order\Model\Order;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\User\Model\User;

$userModule = UserModule::getInstance();
$producerManager = ProducerManager::getInstance();
@@ -75,9 +73,8 @@ $this->render('_menu', [
[
'attribute' => 'username',
'label' => 'Nom',
'value' => function ($model) {
$userModule = UserModule::getInstance();
return $userModule->getUsername($model);
'value' => function ($user) use ($userModule) {
return $userModule->getUsername($user);
}
],
[
@@ -87,13 +84,8 @@ $this->render('_menu', [
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'filter' => $userModule->getTypeChoicesArray(),
'value' => function ($model) {
$userModule = UserModule::getInstance();
$typeArray = $userModule->getTypeChoicesArray();
if(isset($typeArray[$model['type']])) {
return $typeArray[$model['type']];
}
return '';
'value' => function ($user) use ($userModule) {
return $userModule->getTypeLabel($user['type']);
}
],
[
@@ -103,16 +95,16 @@ $this->render('_menu', [
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function ($model) {
'value' => function ($user) {
$html = '';
if (strlen($model['phone'])) {
$html .= $model['phone'];
if (strlen($user['phone'])) {
$html .= $user['phone'];
}
if (strlen($model['phone']) && strlen($model['email'])) {
if (strlen($user['phone']) && strlen($user['email'])) {
$html .= '<br />';
}
if (strlen($model['email'])) {
$html .= $model['email'];
if (strlen($user['email'])) {
$html .= $user['email'];
}
return $html;
}
@@ -124,12 +116,14 @@ $this->render('_menu', [
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function ($model) {
$userModule = UserModule::getInstance();
if($userModule->isUserSubscribedNewsletter($model)) {
'filter' => [
0 => 'Non',
1 => 'Oui'
],
'value' => function ($user) use ($userModule) {
if($userModule->isUserSubscribedNewsletter($user)) {
return '<span class="label label-success">Oui</span>';
}

return '<span class="label label-danger">Non</span>';
}
],
@@ -193,24 +187,30 @@ $this->render('_menu', [
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
$url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]);
$user = User::find()->with('userProducer')->where(['id' => $model->id])->one();
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
'update' => function ($url, $user) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>',
Yii::$app->urlManager->createUrl(['user/update', 'id' => $user->id]),
[
'title' => 'Modifier',
'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' => 'Supprimer', 'class' => 'btn btn-default btn-confirm-delete'
]);
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' => 'Supprimer',
'class' => 'btn btn-default btn-confirm-delete'
]);
},
'switch' => function($url, $model) {
$userModule = UserModule::getInstance();
'switch' => function($url, $model) use ($userModule) {
if($userModule->isCurrentAdmin()) {
return Html::a('<span class="glyphicon glyphicon-user"></span>', Yii::$app->urlManager->createUrl(['user/switch-identity', 'id' => $model->id]), [
'title' => 'Prendre la main', 'class' => 'btn btn-default'
]);
return Html::a('<span class="glyphicon glyphicon-user"></span>',
Yii::$app->urlManager->createUrl(['user/switch-identity', 'id' => $model->id]),
[
'title' => 'Prendre la main',
'class' => 'btn btn-default'
]);
}
}
],

+ 24
- 8
common/logic/User/User/Model/UserSearch.php Parādīt failu

@@ -51,12 +51,13 @@ class UserSearch extends User
var $subscribers;
var $inactive;
var $username;
var $contacts;

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', 'type'], 'string'],
[['lastname', 'name', 'phone', 'address', 'type', 'newsletter', 'contacts'], 'string'],
[['id_point_sale', 'inactive', 'subscribers'], 'integer'],
[['date_last_connection', 'id_point_sale', 'username'], 'safe'],
];
@@ -145,18 +146,33 @@ class UserSearch extends User
]);
}

if (isset($this->newsletter) && is_numeric($this->newsletter)) {
$query->andWhere([
'user_producer.newsletter' => $this->newsletter
]);
}

if ($userModule->isTypeValid($this->type)) {
$query->andWhere(['user.type' => $this->type]);
}

$query->andFilterWhere([
'or',
['like', 'user.lastname', $this->username],
['like', 'user.name', $this->username],
['like', 'user.name_legal_person', $this->username],
]);
if(strlen($this->username)) {
$query->andFilterWhere([
'or',
['like', 'user.lastname', $this->username],
['like', 'user.name', $this->username],
['like', 'user.name_legal_person', $this->username],
]);
}

if(strlen($this->contacts)) {
$query->andFilterWhere([
'or',
['like', 'user.email', $this->contacts],
['like', 'user.phone', $this->contacts],
]);
}

return $dataProvider;
}

}

+ 10
- 0
common/logic/User/User/Service/UserSolver.php Parādīt failu

@@ -20,6 +20,16 @@ class UserSolver extends AbstractService implements SolverInterface
];
}

public function getTypeLabel(string $type): string
{
$typesArray = $this->getTypeChoicesArray();
if(key_exists($type, $typesArray)) {
return $typesArray[$type];
}

return '';
}

public function isTypeValid(string $type = null): bool
{
return in_array($type, User::$types);

Notiek ielāde…
Atcelt
Saglabāt