Ajoute le filtre dans la liste des membres

This commit is contained in:
Fred Tempez 2023-10-09 19:10:48 +02:00
parent a99341aa82
commit b97d796715
5 changed files with 193 additions and 99 deletions

View File

@ -146,24 +146,24 @@ class common
public static $groups = [
self::GROUP_BANNED => 'Banni',
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Etudiant',
self::GROUP_MEMBER => 'Étudiant',
self::GROUP_EDITOR => 'Enseignant',
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupEdits = [
self::GROUP_BANNED => 'Banni',
self::GROUP_MEMBER => 'Etudiant',
self::GROUP_MEMBER => 'Étudiant',
self::GROUP_EDITOR => 'Enseignant',
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupNews = [
self::GROUP_MEMBER => 'Etudiant',
self::GROUP_MEMBER => 'Étudiant',
self::GROUP_EDITOR => 'Enseignant',
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupPublics = [
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Etudiant',
self::GROUP_MEMBER => 'Étudiant',
self::GROUP_EDITOR => 'Enseignant',
self::GROUP_ADMIN => 'Administrateur'
];

View File

@ -54,7 +54,7 @@ class course extends common
public static $alphabet = [];
public static $groups = [
public static $courseGroups = [
'all' => 'Tous'
];
@ -382,8 +382,8 @@ class course extends common
public function user()
{
// Liste des groupes et des profils
$groups = $this->getData(['profil']);
foreach ($groups as $groupId => $groupValue) {
$courseGroups = $this->getData(['profil']);
foreach ($courseGroups as $groupId => $groupValue) {
switch ($groupId) {
case "-1":
case "0":
@ -393,7 +393,7 @@ class course extends common
case "2":
foreach ($groupValue as $profilId => $profilValue) {
if ($profilId) {
self::$groups[$groupId . $profilId] = sprintf(helper::translate('Groupe %s - Profil %s'), self::$groupPublics[$groupId], $profilValue['name']);
self::$courseGroups[$groupId . $profilId] = sprintf(helper::translate('Groupe %s - Profil %s'), self::$groupPublics[$groupId], $profilValue['name']);
}
}
}

View File

@ -26,7 +26,7 @@
</h4>
<div class="row">
<div class="col2">
<?php echo template::select('courseFilterGroup', $module::$groups, [
<?php echo template::select('courseFilterGroup', $module::$courseGroups, [
'label' => 'Groupes / Profils',
'selected' => isset($_POST['courseFilterGroup']) ? $_POST['courseFilterGroup'] : 'all',
]); ?>

View File

@ -73,6 +73,12 @@ class user extends common
public static $profils = [];
public static $alphabet = [];
public static $courseGroups = [
'all' => 'Tous'
];
/**
* Ajout
*/
@ -430,10 +436,59 @@ class user extends common
*/
public function index()
{
// Liste des groupes et des profils
$courseGroups = $this->getData(['profil']);
foreach ($courseGroups as $groupId => $groupValue) {
switch ($groupId) {
case "-1":
case "0":
case "3":
break;
case "1":
case "2":
foreach ($groupValue as $profilId => $profilValue) {
if ($profilId) {
self::$courseGroups[$groupId . $profilId] = sprintf(helper::translate('Groupe %s - Profil %s'), self::$groupPublics[$groupId], $profilValue['name']);
}
}
}
}
// Liste alphabétique
self::$alphabet = range('A', 'Z');
$alphabet = range('A', 'Z');
self::$alphabet = array_combine($alphabet, self::$alphabet);
self::$alphabet = array_merge(['all' => 'Toute'], self::$alphabet);
$userIdsFirstnames = helper::arrayColumn($this->getData(['user']), 'firstname');
ksort($userIdsFirstnames);
foreach ($userIdsFirstnames as $userId => $userFirstname) {
if ($this->getData(['user', $userId, 'group'])) {
// Filtres
if ($this->isPost()) {
// Groupe et profils
$group = (string) $this->getData(['user', $userId, 'group']);
$profil = (string) $this->getData(['user', $userId, 'profil']);
$firstName = $this->getData(['user', $userId, 'firstname']);
$lastName = $this->getData(['user', $userId, 'lastname']);
if (
$this->getInput('userFilterGroup', helper::FILTER_INT) > 0
&& $this->getInput('userFilterGroup', helper::FILTER_STRING_SHORT) !== $group . $profil
)
continue;
// Première lettre du prénom
if (
$this->getInput('userFilterFirstName', helper::FILTER_STRING_SHORT) !== 'all'
&& $this->getInput('userFilterFirstName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($firstName, 0, 1))
)
continue;
// Première lettre du nom
if (
$this->getInput('userFilterLastName', helper::FILTER_STRING_SHORT) !== 'all'
&& $this->getInput('userFilterLastName', helper::FILTER_STRING_SHORT) !== strtoupper(substr($lastName, 0, 1))
)
continue;
}
// Formatage de la liste
$group = helper::translate(self::$groups[(int) $this->getData(['user', $userId, 'group'])]);
$profil = $this->getData(['profil', $this->getData(['user', $userId, 'group']), $this->getData(['user', $userId, 'profil']), 'name']);
self::$users[] = [
@ -545,7 +600,8 @@ class user extends common
// Gère le chemin
$fileManager = $this->getInput('profilEditFileManager', helper::FILTER_BOOLEAN);
$path = $this->getInput('profilEditPath');
if ($group <= self::GROUP_ADMIN
if (
$group <= self::GROUP_ADMIN
&& $fileManager
&& empty($path)
) {
@ -681,7 +737,8 @@ class user extends common
// Gère le chemin
$fileManager = $this->getInput('profilAddFileManager', helper::FILTER_BOOLEAN);
$path = $this->getInput('profilAddPath');
if ($group <= self::GROUP_ADMIN
if (
$group <= self::GROUP_ADMIN
&& $fileManager
&& empty($path)
) {

View File

@ -38,4 +38,41 @@
]); ?>
</div>
</div>
<?php echo template::formOpen('userFilterUserForm'); ?>
<div class="row">
<div class="col10 offset1">
<div class="block">
<h4>
<?php echo helper::translate('Filtres'); ?>
</h4>
<div class="row">
<div class="col2">
<?php echo template::select('userFilterGroup', $module::$courseGroups, [
'label' => 'Groupes / Profils',
'selected' => isset($_POST['userFilterGroup']) ? $_POST['userFilterGroup'] : 'all',
]); ?>
</div>
<div class="col2">
<?php echo template::select('userFilterFirstName', $module::$alphabet, [
'label' => 'Prénom commence par',
'selected' => isset($_POST['userFilterFirstName']) ? $_POST['userFilterFirstName'] : 'all',
]); ?>
</div>
<div class="col2">
<?php echo template::select('userFilterLastName', $module::$alphabet, [
'label' => 'Nom commence par',
'selected' => isset($_POST['userFilterLastName']) ? $_POST['userFilterLastName'] : 'all',
]); ?>
</div>
<div class="col2 offset4">
<?php echo template::submit('userFilterSubmit', [
'value' => 'Filtrer',
'uniqueSubmission' => true
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<?php echo template::table([2, 2 , 3, 3, 1, 1], $module::$users, ['Identifiant', 'Nom', 'Groupe', 'Profil', '', '']); ?>