Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -72,6 +72,171 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2b. Jira Dashboard Data Ophalen (Toegewezen + Team issues + Stats)
|
||||
if ($action === 'get_jira_dashboard') {
|
||||
$force = !empty($_GET['force']) || !empty($_POST['force']);
|
||||
$res = jira_get_dashboard_data($user['id'], $force);
|
||||
echo json_encode($res);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2c. Jira Issue inplannen in Dagplanner
|
||||
if ($action === 'plan_jira_task') {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$key = trim($input['key'] ?? '');
|
||||
$summary = trim($input['summary'] ?? '');
|
||||
$url = trim($input['url'] ?? '');
|
||||
$planDate = !empty($input['plan_date']) ? trim($input['plan_date']) : date('Y-m-d');
|
||||
$priority = in_array($input['priority'] ?? '', ['P1', 'P2', 'P3']) ? $input['priority'] : 'P2';
|
||||
$timeBlockStart = !empty($input['time_block_start']) ? trim($input['time_block_start']) : null;
|
||||
$timeBlockEnd = !empty($input['time_block_end']) ? trim($input['time_block_end']) : null;
|
||||
$durationMinutes = !empty($input['duration_minutes']) ? (int)$input['duration_minutes'] : 45;
|
||||
|
||||
if (empty($key) || empty($summary)) {
|
||||
echo json_encode(['error' => 'Ticket key en titel zijn verplicht']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$title = "[{$key}] {$summary}";
|
||||
|
||||
// Zoek of maak daily plan aan voor deze datum
|
||||
$stmtPlan = $db->prepare("SELECT id FROM daily_plans WHERE user_id = ? AND plan_date = ?");
|
||||
$stmtPlan->execute([$user['id'], $planDate]);
|
||||
$planId = $stmtPlan->fetchColumn();
|
||||
|
||||
if (!$planId) {
|
||||
$stmtCreatePlan = $db->prepare("INSERT INTO daily_plans (user_id, plan_date) VALUES (?, ?)");
|
||||
$stmtCreatePlan->execute([$user['id'], $planDate]);
|
||||
$planId = (int)$db->lastInsertId();
|
||||
}
|
||||
|
||||
// Voeg taak toe
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO tasks (user_id, daily_plan_id, title, priority, time_block_start, time_block_end, duration_minutes, status, source, external_id, external_url)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, 'TODO', 'JIRA', ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$user['id'],
|
||||
$planId,
|
||||
$title,
|
||||
$priority,
|
||||
$timeBlockStart,
|
||||
$timeBlockEnd,
|
||||
$durationMinutes,
|
||||
$key,
|
||||
$url
|
||||
]);
|
||||
$taskId = (int)$db->lastInsertId();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'task_id' => $taskId,
|
||||
'message' => "Ticket {$key} is succesvol ingepland voor " . date('d-m-Y', strtotime($planDate)) . "!",
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2d. Jira Issue toevoegen aan een Kanban Bord kolom
|
||||
if ($action === 'board_jira_card') {
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?: $_POST;
|
||||
$boardId = (int)($input['board_id'] ?? 0);
|
||||
$laneId = (int)($input['lane_id'] ?? 0);
|
||||
$key = trim($input['key'] ?? '');
|
||||
$summary = trim($input['summary'] ?? '');
|
||||
$description = trim($input['description'] ?? '');
|
||||
$url = trim($input['url'] ?? '');
|
||||
$priority = in_array($input['priority'] ?? '', ['P1', 'P2', 'P3']) ? $input['priority'] : 'P2';
|
||||
$color = in_array($input['color'] ?? '', ['yellow', 'blue', 'green', 'purple', 'red', 'pink', 'indigo', 'orange']) ? $input['color'] : 'blue';
|
||||
|
||||
if (empty($boardId) || empty($laneId) || empty($key) || empty($summary)) {
|
||||
echo json_encode(['error' => 'Bord, kolom, ticket key en titel zijn verplicht']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Controleer toegang tot bord
|
||||
$isAdmin = ($user['role'] ?? '') === 'ADMIN';
|
||||
if (!$isAdmin) {
|
||||
$stmtCheck = $db->prepare("SELECT role FROM board_members WHERE board_id = ? AND user_id = ?");
|
||||
$stmtCheck->execute([$boardId, $user['id']]);
|
||||
if (!$stmtCheck->fetchColumn()) {
|
||||
echo json_encode(['error' => 'Geen toegang tot dit bord']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Controleer of lane bij bord hoort
|
||||
$stmtLane = $db->prepare("SELECT id FROM board_lanes WHERE id = ? AND board_id = ?");
|
||||
$stmtLane->execute([$laneId, $boardId]);
|
||||
if (!$stmtLane->fetchColumn()) {
|
||||
echo json_encode(['error' => 'Kolom hoort niet bij dit bord']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$title = "[{$key}] {$summary}";
|
||||
$descFull = trim(($url ? "🔗 Jira: {$url}\n\n" : "") . $description);
|
||||
|
||||
$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 (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$boardId,
|
||||
$laneId,
|
||||
$title,
|
||||
$descFull,
|
||||
$user['id'],
|
||||
$priority,
|
||||
$color,
|
||||
$maxPos + 1,
|
||||
$user['id']
|
||||
]);
|
||||
$cardId = (int)$db->lastInsertId();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'card_id' => $cardId,
|
||||
'message' => "Ticket {$key} is succesvol als kaart op het bord geplaatst!",
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 2e. Beschikbare borden en kolommen ophalen voor selectiedialoog
|
||||
if ($action === 'get_boards_and_lanes') {
|
||||
$isAdmin = ($user['role'] ?? '') === 'ADMIN';
|
||||
if ($isAdmin) {
|
||||
$boards = $db->query("SELECT id, title FROM boards WHERE is_archived = 0 ORDER BY id ASC")->fetchAll();
|
||||
} else {
|
||||
$stmt = $db->prepare("
|
||||
SELECT b.id, b.title
|
||||
FROM boards b
|
||||
JOIN board_members bm ON b.id = bm.board_id
|
||||
WHERE bm.user_id = ? AND b.is_archived = 0
|
||||
ORDER BY b.id ASC
|
||||
");
|
||||
$stmt->execute([$user['id']]);
|
||||
$boards = $stmt->fetchAll();
|
||||
}
|
||||
|
||||
$boardIds = array_column($boards, 'id');
|
||||
$lanesByBoard = [];
|
||||
if (!empty($boardIds)) {
|
||||
$inClause = implode(',', array_map('intval', $boardIds));
|
||||
$lanes = $db->query("SELECT id, board_id, title, color FROM board_lanes WHERE board_id IN ({$inClause}) ORDER BY position ASC")->fetchAll();
|
||||
foreach ($lanes as $lane) {
|
||||
$lanesByBoard[$lane['board_id']][] = $lane;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($boards as &$b) {
|
||||
$b['lanes'] = $lanesByBoard[$b['id']] ?? [];
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'boards' => $boards]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. Outlook Agenda Afspraken Ophalen
|
||||
if ($action === 'get_outlook_events') {
|
||||
$date = $_GET['date'] ?? date('Y-m-d');
|
||||
|
||||
Reference in New Issue
Block a user