This commit is contained in:
2026-09-15 12:30:58 +02:00
parent f992ca1ec9
commit 1358b6a7e9
5 changed files with 1140 additions and 531 deletions
+123
View File
@@ -331,6 +331,82 @@ function jira_fetch_statuses(string $domain, string $email, string $apiToken): a
return $statuses;
}
/**
* Haalt project-specifieke statussen op uit Jira Cloud voor een specifiek project
*/
function jira_fetch_project_statuses(string $domain, string $email, string $apiToken, string $projectKey): array {
$cleanDomain = jira_normalize_domain($domain);
$pKey = strtoupper(trim($projectKey));
if (empty($cleanDomain) || empty($email) || empty($apiToken) || empty($pKey)) {
return [];
}
$cacheKey = "jira_proj_statuses_" . $pKey . "_" . md5($cleanDomain);
$cached = fociz_cache_get($cacheKey);
if (is_array($cached) && !empty($cached)) {
return $cached;
}
$authHeader = jira_get_auth_header($email, $apiToken);
$url = $cleanDomain . '/rest/api/3/project/' . rawurlencode($pKey) . '/statuses';
$response = fociz_http_request($url, [
'method' => 'GET',
'headers' => [
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 8,
]);
if ($response['status'] === 404 || $response['status'] === 405) {
$urlV2 = $cleanDomain . '/rest/api/2/project/' . rawurlencode($pKey) . '/statuses';
$response = fociz_http_request($urlV2, [
'method' => 'GET',
'headers' => [
'Authorization' => $authHeader,
'Accept' => 'application/json',
],
'timeout' => 8,
]);
}
$statuses = [];
if ($response['status'] === 200 && is_array($response['json'])) {
foreach ($response['json'] as $issueType) {
if (!empty($issueType['statuses']) && is_array($issueType['statuses'])) {
foreach ($issueType['statuses'] as $st) {
$sName = trim($st['name'] ?? '');
if (empty($sName)) continue;
$sKey = strtolower($sName);
$catKey = strtolower($st['statusCategory']['key'] ?? 'indeterminate');
$catName = $st['statusCategory']['name'] ?? 'In uitvoering';
$statuses[$sKey] = [
'id' => (string)($st['id'] ?? ''),
'name' => $sName,
'description' => $st['description'] ?? '',
'status_category' => $catKey,
'category_name' => $catName,
'color' => $st['statusCategory']['colorName'] ?? '',
];
}
}
}
$statuses = array_values($statuses);
usort($statuses, function($a, $b) {
$order = ['new' => 1, 'indeterminate' => 2, 'done' => 3];
$oa = $order[$a['status_category']] ?? 2;
$ob = $order[$b['status_category']] ?? 2;
if ($oa !== $ob) return $oa - $ob;
return strcasecmp($a['name'], $b['name']);
});
fociz_cache_set($cacheKey, $statuses, 3600);
}
return $statuses;
}
/**
* Haalt issues op via een flexibele JQL query via Atlassian REST API
*/
@@ -974,6 +1050,34 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
],
];
$demoProjectStatuses = [
'SD' => [
['id' => '1', 'name' => 'To Do', 'status_category' => 'new', 'category_name' => 'Nieuw'],
['id' => '2', 'name' => 'In behandeling', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '3', 'name' => 'Wachten op klant', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '4', 'name' => 'Gesloten', 'status_category' => 'done', 'category_name' => 'Gereed'],
],
'IN' => [
['id' => '10', 'name' => 'Nieuw', 'status_category' => 'new', 'category_name' => 'Nieuw'],
['id' => '11', 'name' => 'In behandeling', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '12', 'name' => 'In Review', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '13', 'name' => 'Gereed', 'status_category' => 'done', 'category_name' => 'Gereed'],
['id' => '14', 'name' => 'Gesloten', 'status_category' => 'done', 'category_name' => 'Gereed'],
],
'AAN' => [
['id' => '20', 'name' => 'Nieuw', 'status_category' => 'new', 'category_name' => 'Nieuw'],
['id' => '21', 'name' => 'In behandeling', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '22', 'name' => 'Goedgekeurd', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '23', 'name' => 'Afgewezen', 'status_category' => 'done', 'category_name' => 'Gereed'],
['id' => '24', 'name' => 'Gesloten', 'status_category' => 'done', 'category_name' => 'Gereed'],
],
'GEN' => [
['id' => '30', 'name' => 'To Do', 'status_category' => 'new', 'category_name' => 'Nieuw'],
['id' => '31', 'name' => 'In Progress', 'status_category' => 'indeterminate', 'category_name' => 'In uitvoering'],
['id' => '32', 'name' => 'Done', 'status_category' => 'done', 'category_name' => 'Gereed'],
],
];
return [
'is_demo' => true,
'success' => true,
@@ -987,6 +1091,7 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
'default_queue_filter' => $userQueuePref,
'user_queue_filters' => $userQueuePrefs,
'available_statuses' => $demoStatuses,
'project_statuses' => $demoProjectStatuses,
];
}
@@ -1041,6 +1146,23 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
$assignedIssues = $assignedRes['success'] ? $assignedRes['issues'] : [];
$teamIssues = $teamRes['success'] ? $teamRes['issues'] : [];
// Project-specifieke statussen ophalen voor gebruikte projecten
$activeProjKeys = ['SD', 'IN', 'AAN', 'GEN'];
$allLoaded = array_merge($assignedIssues, $teamIssues);
foreach ($allLoaded as $iss) {
$pk = strtoupper(trim($iss['project_key'] ?? ''));
if (!empty($pk) && !in_array($pk, $activeProjKeys, true)) {
$activeProjKeys[] = $pk;
}
}
$projectStatusesMap = [];
foreach ($activeProjKeys as $pk) {
$pStats = jira_fetch_project_statuses($domain, $email, $apiToken, $pk);
if (!empty($pStats)) {
$projectStatusesMap[$pk] = $pStats;
}
}
$data = [
'is_demo' => false,
'success' => true,
@@ -1054,6 +1176,7 @@ function jira_get_dashboard_data(int $userId, bool $forceRefresh = false): array
'default_queue_filter' => $userQueuePref,
'user_queue_filters' => $userQueuePrefs,
'available_statuses' => $availableStatuses,
'project_statuses' => $projectStatusesMap,
];
fociz_cache_set($cacheKey, $data, 60);