feat: Permettre l'import d'enseignants via fichier CSV ou XLSX
L'établissement a besoin d'importer en masse ses enseignants depuis les exports des logiciels de vie scolaire (Pronote, EDT, etc.), comme c'est déjà possible pour les élèves. Le wizard en 4 étapes (upload → mapping → aperçu → import) réutilise l'architecture de l'import élèves tout en ajoutant la gestion des matières et des classes enseignées. Corrections de la review #2 intégrées : - La commande ImportTeachersCommand est routée en async via Messenger pour ne pas bloquer la requête HTTP sur les gros fichiers. - Le handler est protégé par un try/catch Throwable pour marquer le batch en échec si une erreur inattendue survient, évitant qu'il reste bloqué en statut "processing". - Les domain events (UtilisateurInvite) sont dispatchés sur l'event bus après chaque création d'utilisateur, déclenchant l'envoi des emails d'invitation. - L'option "mettre à jour les enseignants existants" (AC5) permet de choisir entre ignorer ou mettre à jour nom/prénom et ajouter les affectations manquantes pour les doublons détectés par email.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Administration\Application\Service\Import;
|
||||
|
||||
use App\Administration\Domain\Model\Import\KnownImportFormat;
|
||||
use App\Administration\Domain\Model\Import\TeacherImportField;
|
||||
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Suggère un mapping automatique des colonnes pour l'import enseignants.
|
||||
*
|
||||
* @see AC2: Mapping spécifique enseignants
|
||||
*/
|
||||
final readonly class TeacherColumnMappingSuggester
|
||||
{
|
||||
/**
|
||||
* Mapping générique par mots-clés pour les enseignants.
|
||||
*
|
||||
* @var array<string, TeacherImportField>
|
||||
*/
|
||||
private const array GENERIC_KEYWORDS = [
|
||||
'nom' => TeacherImportField::LAST_NAME,
|
||||
'last' => TeacherImportField::LAST_NAME,
|
||||
'family' => TeacherImportField::LAST_NAME,
|
||||
'surname' => TeacherImportField::LAST_NAME,
|
||||
'prénom' => TeacherImportField::FIRST_NAME,
|
||||
'prenom' => TeacherImportField::FIRST_NAME,
|
||||
'first' => TeacherImportField::FIRST_NAME,
|
||||
'given' => TeacherImportField::FIRST_NAME,
|
||||
'email' => TeacherImportField::EMAIL,
|
||||
'mail' => TeacherImportField::EMAIL,
|
||||
'courriel' => TeacherImportField::EMAIL,
|
||||
'matière' => TeacherImportField::SUBJECTS,
|
||||
'matiere' => TeacherImportField::SUBJECTS,
|
||||
'matières' => TeacherImportField::SUBJECTS,
|
||||
'matieres' => TeacherImportField::SUBJECTS,
|
||||
'subject' => TeacherImportField::SUBJECTS,
|
||||
'discipline' => TeacherImportField::SUBJECTS,
|
||||
'classe' => TeacherImportField::CLASSES,
|
||||
'classes' => TeacherImportField::CLASSES,
|
||||
'class' => TeacherImportField::CLASSES,
|
||||
'groupe' => TeacherImportField::CLASSES,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param list<string> $columns Colonnes détectées dans le fichier
|
||||
* @param KnownImportFormat $detectedFormat Format détecté
|
||||
*
|
||||
* @return array<string, TeacherImportField> Mapping suggéré (colonne → champ)
|
||||
*/
|
||||
public function suggerer(array $columns, KnownImportFormat $detectedFormat): array
|
||||
{
|
||||
return $this->mapperGenerique($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $columns
|
||||
*
|
||||
* @return array<string, TeacherImportField>
|
||||
*/
|
||||
private function mapperGenerique(array $columns): array
|
||||
{
|
||||
$mapping = [];
|
||||
$usedFields = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$normalized = $this->normaliser($column);
|
||||
|
||||
foreach (self::GENERIC_KEYWORDS as $keyword => $field) {
|
||||
if (str_contains($normalized, $keyword) && !in_array($field, $usedFields, true)) {
|
||||
$mapping[$column] = $field;
|
||||
$usedFields[] = $field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
private function normaliser(string $column): string
|
||||
{
|
||||
$normalized = mb_strtolower(trim($column));
|
||||
$normalized = str_replace(['_', '-', "'"], [' ', ' ', ' '], $normalized);
|
||||
|
||||
/** @var string $result */
|
||||
$result = preg_replace('/\s+/', ' ', $normalized);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user