2026-01-30 11:27:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'pattern' => '/toggle-hidden-project.json',
|
|
|
|
|
'method' => 'POST',
|
|
|
|
|
'action' => function() {
|
|
|
|
|
$json = file_get_contents("php://input");
|
|
|
|
|
$data = json_decode($json);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$user = kirby()->user();
|
|
|
|
|
$projectUuid = $data->projectUuid;
|
|
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
// Récupérer la collection des projets masqués actuels
|
2026-01-30 11:27:27 +01:00
|
|
|
$hiddenProjects = $user->hiddenProjects()->toPages();
|
|
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
// Trouver le projet à toggle
|
2026-01-30 11:27:27 +01:00
|
|
|
$projectPage = Find::page($projectUuid);
|
|
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
if (!$projectPage) {
|
|
|
|
|
throw new Exception('Projet introuvable');
|
|
|
|
|
}
|
2026-01-30 11:27:27 +01:00
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
// Toggle: ajouter ou retirer le projet de la collection
|
|
|
|
|
if ($hiddenProjects->has($projectPage)) {
|
|
|
|
|
$hiddenProjects->remove($projectPage);
|
2026-01-30 11:27:27 +01:00
|
|
|
$action = 'shown';
|
|
|
|
|
} else {
|
2026-01-30 11:48:53 +01:00
|
|
|
$hiddenProjects->add($projectPage);
|
2026-01-30 11:27:27 +01:00
|
|
|
$action = 'hidden';
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
// Convertir la collection en array puis en YAML
|
|
|
|
|
$array = $hiddenProjects->toArray();
|
|
|
|
|
$yaml = Data::encode($array, 'yaml');
|
2026-01-30 11:27:27 +01:00
|
|
|
|
|
|
|
|
// Mettre à jour l'utilisateur
|
|
|
|
|
$user->update([
|
|
|
|
|
'hiddenProjects' => $yaml
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-30 11:48:53 +01:00
|
|
|
// Retourner les UUIDs pour le frontend
|
|
|
|
|
$hiddenProjectsUuids = [];
|
|
|
|
|
foreach ($hiddenProjects as $project) {
|
|
|
|
|
$hiddenProjectsUuids[] = $project->uuid();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 11:27:27 +01:00
|
|
|
return [
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'action' => $action,
|
2026-01-30 11:48:53 +01:00
|
|
|
'hiddenProjects' => $hiddenProjectsUuids
|
2026-01-30 11:27:27 +01:00
|
|
|
];
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return [
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Impossible de modifier les projets masqués : ' . $th->getMessage() . ' in file ' . $th->getFile() . ' line ' . $th->getLine()
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|