fix(phonebook,ucp): v2.6.4 affichage des postes multi-groupes dans chaque onglet de groupe
This commit is contained in:
1 parent
8cb8f1cdf7
commit
f918c929f5
3 files changed
+69
-32
No files matched your search
+52
-27
@@ -48,14 +48,22 @@ class PhonebookManager
|
||||
CREATE INDEX IF NOT EXISTS idx_phonebook_group ON phonebook_contacts(group_name);
|
||||
");
|
||||
|
||||
// 1. Récupère la cartographie des groupes d'extensions
|
||||
$egRows = $db->query("SELECT id, name, members FROM extension_groups")->fetchAll();
|
||||
$extToGroup = [];
|
||||
// 1. Récupère la cartographie complète des groupes d'extensions (un poste peut appartenir à plusieurs groupes)
|
||||
$egRows = $db->query("SELECT id, name, members FROM extension_groups ORDER BY name COLLATE NOCASE ASC")->fetchAll();
|
||||
$extToGroups = [];
|
||||
foreach ($egRows as $eg) {
|
||||
$grpName = trim((string)($eg['name'] ?? ''));
|
||||
if ($grpName === '') {
|
||||
continue;
|
||||
}
|
||||
$members = json_decode((string)$eg['members'], true) ?: [];
|
||||
foreach ($members as $extNum) {
|
||||
if (!isset($extToGroup[(string)$extNum])) {
|
||||
$extToGroup[(string)$extNum] = trim((string)$eg['name']);
|
||||
$k = (string)$extNum;
|
||||
if (!isset($extToGroups[$k])) {
|
||||
$extToGroups[$k] = [];
|
||||
}
|
||||
if (!in_array($grpName, $extToGroups[$k], true)) {
|
||||
$extToGroups[$k][] = $grpName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +88,7 @@ class PhonebookManager
|
||||
$extNum = trim((string)$ext['extension']);
|
||||
$extName = trim((string)$ext['name']);
|
||||
$email = trim((string)($ext['voicemail_email'] ?? ''));
|
||||
$group = $extToGroup[$extNum] ?? 'Général';
|
||||
$group = !empty($extToGroups[$extNum]) ? implode(', ', $extToGroups[$extNum]) : 'Général';
|
||||
$activeExtIds[] = $extId;
|
||||
|
||||
$findStmt->execute([':ext_id' => $extId, ':num' => $extNum]);
|
||||
@@ -122,33 +130,48 @@ class PhonebookManager
|
||||
{
|
||||
self::syncExtensions($db);
|
||||
|
||||
$params = [];
|
||||
$sql = "SELECT * FROM phonebook_contacts";
|
||||
$stmt = $db->query("SELECT * FROM phonebook_contacts ORDER BY display_name COLLATE NOCASE ASC");
|
||||
$contacts = $stmt ? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
|
||||
|
||||
if ($group !== null && trim($group) !== '' && strtolower(trim($group)) !== 'all' && strtolower(trim($group)) !== 'tous') {
|
||||
$cleanGroup = trim($group);
|
||||
$sql .= " WHERE LOWER(group_name) = LOWER(:grp) OR LOWER(group_name) LIKE LOWER(:grp_like) OR LOWER(group_name) IN ('tous', 'all')";
|
||||
$params[':grp'] = $cleanGroup;
|
||||
$params[':grp_like'] = "%{$cleanGroup}%";
|
||||
}
|
||||
$cleanGroup = ($group !== null) ? trim($group) : '';
|
||||
$filterByGroup = ($cleanGroup !== '' && !in_array(mb_strtolower($cleanGroup), ['all', 'tous'], true));
|
||||
$targetLower = mb_strtolower($cleanGroup);
|
||||
|
||||
$sql .= " ORDER BY display_name COLLATE NOCASE ASC";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Vérification de la présence réelle du fichier sur le disque
|
||||
foreach ($contacts as &$c) {
|
||||
$result = [];
|
||||
foreach ($contacts as $c) {
|
||||
if (!empty($c['photo_url'])) {
|
||||
$filename = basename((string)$c['photo_url']);
|
||||
if (!file_exists(self::AVATARS_DIR . '/' . $filename)) {
|
||||
$c['photo_url'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($c);
|
||||
|
||||
return $contacts;
|
||||
$rawGroups = preg_split('/\s*,\s*/', trim((string)($c['group_name'] ?? ''))) ?: [];
|
||||
$groupsList = array_values(array_unique(array_filter($rawGroups, fn($g) => $g !== '')));
|
||||
if (empty($groupsList)) {
|
||||
$groupsList = ['Général'];
|
||||
}
|
||||
$c['groups'] = $groupsList;
|
||||
$c['group_name'] = implode(', ', $groupsList);
|
||||
|
||||
if ($filterByGroup) {
|
||||
$matched = false;
|
||||
foreach ($groupsList as $g) {
|
||||
$gLower = mb_strtolower($g);
|
||||
if ($gLower === $targetLower || in_array($gLower, ['tous', 'all'], true)) {
|
||||
$matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$matched) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$result[] = $c;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,9 +186,11 @@ class PhonebookManager
|
||||
if ($g !== '') $groups[$g] = true;
|
||||
}
|
||||
$pbRows = $db->query("SELECT DISTINCT group_name FROM phonebook_contacts WHERE group_name != ''")->fetchAll(PDO::FETCH_COLUMN);
|
||||
foreach ($pbRows as $g) {
|
||||
$g = trim((string)$g);
|
||||
if ($g !== '') $groups[$g] = true;
|
||||
foreach ($pbRows as $raw) {
|
||||
foreach (preg_split('/\s*,\s*/', trim((string)$raw)) ?: [] as $g) {
|
||||
$g = trim((string)$g);
|
||||
if ($g !== '') $groups[$g] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ajoute Issy-Les-Moulineaux si pas encore présent
|
||||
|
||||
Reference in new issue
Block a user