Browse Source

[Administration] Utilisateurs > liste : pouvoir filtrer par groupe #1369

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
16a96cf693
4 changed files with 40 additions and 4 deletions
  1. +18
    -0
      backend/views/user/index.php
  2. +10
    -1
      common/logic/User/User/Model/UserSearch.php
  3. +6
    -3
      common/logic/User/UserGroup/Repository/UserGroupRepository.php
  4. +6
    -0
      common/logic/User/UserUserGroup/Model/UserUserGroup.php

+ 18
- 0
backend/views/user/index.php View File

@@ -38,6 +38,7 @@

use common\helpers\GlobalParam;
use common\logic\Producer\Producer\Module\ProducerModule;
use common\logic\User\UserGroup\Module\UserGroupModule;
use yii\helpers\Html;
use yii\grid\GridView;
use common\logic\User\User\Module\UserModule;
@@ -47,6 +48,7 @@ use common\logic\User\UserProducer\Model\UserProducer;
$userModule = UserModule::getInstance();
$producerModule = ProducerModule::getInstance();
$userCurrent = GlobalParam::getCurrentUser();
$userGroupModule = UserGroupModule::getInstance();

$this->setTitle('Utilisateurs');
$this->addBreadcrumb($this->getTitle());
@@ -113,6 +115,22 @@ $this->render('_menu', [
return $html;
}
],
[
'attribute' => 'id_user_user_group',
'header' => 'Groupes',
'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'filter' => $userGroupModule->getRepository()->populateUserGroupDropdownList(false),
'value' => function ($user) {
$html = '';
foreach($user->userUserGroup as $userUserGroup) {
$html .= '<span class="label label-default">'.$userUserGroup->userGroup->name.'</span> ';
}
return $html;
}
],
[
'attribute' => 'newsletter',
'header' => "Inscrit au bulletin<br/>d'information",

+ 10
- 1
common/logic/User/User/Model/UserSearch.php View File

@@ -50,13 +50,14 @@ class UserSearch extends User
var $inactive;
var $username;
var $contacts;
var $id_user_user_group;

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', 'newsletter', 'contacts'], 'string'],
[['id_point_sale', 'inactive', 'subscribers'], 'integer'],
[['id_point_sale', 'inactive', 'subscribers', 'id_user_user_group'], 'integer'],
[['date_last_connection', 'id_point_sale', 'username'], 'safe'],
];
}
@@ -150,6 +151,14 @@ class UserSearch extends User
]);
}

if (isset($this->id_user_user_group) && is_numeric($this->id_user_user_group)) {
$query->innerJoin(
'user_user_group',
'user.id = user_user_group.id_user AND user_user_group.id_user_group = :id_user_group',
['id_user_group' => $this->id_user_user_group]
)->groupBy('user.id');
}

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

+ 6
- 3
common/logic/User/UserGroup/Repository/UserGroupRepository.php View File

@@ -44,11 +44,14 @@ class UserGroupRepository extends AbstractRepository
return $this->createDefaultQuery()->find();
}

public function populateUserGroupDropdownList(): array
public function populateUserGroupDropdownList(bool $emptyOption = true): array
{
$userGroupsArrayDropdown = ['' => '--'];
$userGroupsArray = $this->findUserGroups();
$userGroupsArrayDropdown = [];
if($emptyOption) {
$userGroupsArrayDropdown = ['' => '--'];
}

$userGroupsArray = $this->findUserGroups();
foreach ($userGroupsArray as $userGroup) {
$userGroupsArrayDropdown[$userGroup['id']] = $userGroup['name'];
}

+ 6
- 0
common/logic/User/UserUserGroup/Model/UserUserGroup.php View File

@@ -39,6 +39,7 @@ termes.
namespace common\logic\User\UserUserGroup\Model;

use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\User\UserGroup\Model\UserGroup;
use Yii;
use common\components\ActiveRecordCommon ;

@@ -87,4 +88,9 @@ class UserUserGroup extends ActiveRecordCommon
{
$this->populateFieldObject('id_point_sale', 'pointSale', $pointSale);
}

public function getUserGroup()
{
return $this->hasOne(UserGroup::class, ['id' => 'id_user_group']);
}
}

Loading…
Cancel
Save