Brainstorm huge refactor

This commit is contained in:
2026-09-14 11:10:54 +02:00
parent 5a31f0948a
commit 24fbfb9d82
9 changed files with 747 additions and 41 deletions
+55 -5
View File
@@ -72,6 +72,7 @@ try {
$data = json_decode(file_get_contents('php://input'), true);
$sessionId = (int)($data['session_id'] ?? 0);
$count = min(6, max(2, (int)($data['count'] ?? 4)));
$fullBoard = !empty($data['full_board']); // Genereren over alle 4 categorieën o.b.v. briefing
if (!$sessionId) {
echo json_encode(['error' => 'Sessie ID ontbreekt']);
@@ -87,7 +88,59 @@ try {
exit;
}
$aiRes = fociz_ai_generate_ideas($session['title'], $session['theme'] ?? 'Algemeen', $count, $user['id']);
$authorName = 'AI Co-Pilot';
$createdCards = [];
$colorMap = [
'Ideeën' => 'amber',
'Knelpunten' => 'rose',
'Oplossingen' => 'teal',
'Quick Wins' => 'indigo',
];
if ($fullBoard || !empty($session['description'])) {
// Gebruik de volledige board generator die alle 4 categorieën vult aan de hand van de briefing
$aiRes = fociz_ai_generate_session_board(
$session['title'],
$session['theme'] ?? 'Algemeen',
$session['description'] ?? '',
$user['id']
);
if ($aiRes['success'] && !empty($aiRes['cards'])) {
$insertStmt = $db->prepare("
INSERT INTO brainstorm_cards (session_id, content, category, color, author_name, votes)
VALUES (?, ?, ?, ?, ?, 1)
");
foreach ($aiRes['cards'] as $cardItem) {
$cText = trim($cardItem['content'] ?? '');
$cCat = trim($cardItem['category'] ?? 'Ideeën');
if (!isset($colorMap[$cCat])) {
$cCat = 'Ideeën';
}
$cColor = $colorMap[$cCat];
if (!empty($cText)) {
$insertStmt->execute([$sessionId, $cText, $cCat, $cColor, $authorName]);
$createdCards[] = [
'id' => (int)$db->lastInsertId(),
'content' => $cText,
'category' => $cCat,
'color' => $cColor,
'author_name' => $authorName,
'votes' => 1,
];
}
}
echo json_encode(['success' => true, 'cards' => $createdCards, 'mode' => 'full_board']);
exit;
}
}
// Fallback: reguliere generatie
$aiRes = fociz_ai_generate_ideas($session['title'], $session['theme'] ?? 'Algemeen', $count, $user['id'], $session['description'] ?? '');
if (!$aiRes['success']) {
echo json_encode(['error' => $aiRes['error']]);
@@ -99,9 +152,6 @@ try {
VALUES (?, ?, 'Ideeën', 'amber', ?, 1)
");
$createdCards = [];
$authorName = 'AI Co-Pilot';
foreach ($aiRes['ideas'] as $ideaText) {
$ideaText = trim($ideaText);
if (!empty($ideaText)) {
@@ -117,7 +167,7 @@ try {
}
}
echo json_encode(['success' => true, 'cards' => $createdCards]);
echo json_encode(['success' => true, 'cards' => $createdCards, 'mode' => 'ideas']);
exit;
}