Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-09-09 22:31:19 +02:00
parent eda90dbba6
commit d4fd706eca
4 changed files with 1206 additions and 4 deletions
+95
View File
@@ -486,6 +486,101 @@ try {
exit;
}
// 10. Tijdlijn Datums Snel Bijwerken (Startdatum & Einddatum via Gantt drag)
if ($action === 'update_card_dates') {
$cardId = (int)($input['card_id'] ?? 0);
$startDate = trim($input['start_date'] ?? '');
$endDate = trim($input['end_date'] ?? $startDate);
if (!$cardId || !$startDate) {
echo json_encode(['success' => false, 'error' => 'Ongeldige parameters.']);
exit;
}
$stmtCard = $db->prepare("SELECT * FROM board_cards WHERE id = ?");
$stmtCard->execute([$cardId]);
$card = $stmtCard->fetch();
if (!$card) {
echo json_encode(['success' => false, 'error' => 'Taak niet gevonden.']);
exit;
}
if (!check_board_access($db, (int)$card['board_id'], $userId, $isAdmin)) {
http_response_code(403);
echo json_encode(['success' => false, 'error' => 'Geen toegang tot dit bord.']);
exit;
}
$stmtSched = $db->prepare("
INSERT INTO board_card_schedules (card_id, schedule_type, start_date, end_date, start_time, end_time, days_of_week)
VALUES (?, 'DAILY_RANGE', ?, ?, '09:00', '17:00', '1,2,3,4,5')
ON DUPLICATE KEY UPDATE
start_date = VALUES(start_date),
end_date = VALUES(end_date),
schedule_type = 'DAILY_RANGE'
");
$stmtSched->execute([$cardId, $startDate, $endDate]);
echo json_encode([
'success' => true,
'card_id' => $cardId,
'start_date' => $startDate,
'end_date' => $endDate,
'message' => 'Tijdlijn bijgewerkt!'
]);
exit;
}
// 11. Snelle Inline Taak Aanmaken (⚡ Wat moet er gedaan worden?)
if ($action === 'quick_create_card') {
$boardId = (int)($input['board_id'] ?? 0);
$title = trim($input['title'] ?? '');
$laneId = (int)($input['lane_id'] ?? 0);
$startDate = !empty($input['start_date']) ? trim($input['start_date']) : null;
$endDate = !empty($input['end_date']) ? trim($input['end_date']) : $startDate;
if (!$boardId || empty($title)) {
echo json_encode(['success' => false, 'error' => 'Vul een titel in voor de taak.']);
exit;
}
if (!check_board_access($db, $boardId, $userId, $isAdmin)) {
http_response_code(403);
echo json_encode(['success' => false, 'error' => 'Geen toegang tot dit bord.']);
exit;
}
// Als geen lane_id is meegegeven, pak de 1e lane van het bord
if ($laneId <= 0) {
$laneId = (int)$db->query("SELECT id FROM board_lanes WHERE board_id = {$boardId} ORDER BY position ASC, id ASC LIMIT 1")->fetchColumn();
}
$maxPos = (int)$db->query("SELECT COALESCE(MAX(position), -1) FROM board_cards WHERE lane_id = {$laneId}")->fetchColumn();
$stmt = $db->prepare("
INSERT INTO board_cards (board_id, lane_id, title, description, assignee_id, priority, color, position, created_by_id)
VALUES (?, ?, ?, '', NULL, 'P2', 'yellow', ?, ?)
");
$stmt->execute([$boardId, $laneId, $title, $maxPos + 1, $userId]);
$newCardId = (int)$db->lastInsertId();
// Optioneel datums toekennen
if ($startDate) {
$stmtSched = $db->prepare("
INSERT INTO board_card_schedules (card_id, schedule_type, start_date, end_date, start_time, end_time, days_of_week)
VALUES (?, 'DAILY_RANGE', ?, ?, '09:00', '17:00', '1,2,3,4,5')
");
$stmtSched->execute([$newCardId, $startDate, $endDate]);
}
echo json_encode([
'success' => true,
'card_id' => $newCardId,
'lane_id' => $laneId,
'message' => 'Taak direct toegevoegd!'
]);
exit;
}
echo json_encode(['success' => false, 'error' => 'Onbekende actie.']);
} catch (Throwable $e) {
error_log("Fociz Board API Fout: " . $e->getMessage());