reports/src/Features/Reports/ReportsApi.php

71 lines
2.1 KiB
PHP
Raw Normal View History

2026-06-19 17:23:25 +03:00
<?php declare(strict_types=1);
namespace Nechaev\Reports\Features\Reports;
use Nechaev\Reports\Core\App;
use Nechaev\Reports\Framework\Database\Database;
final class ReportsApi {
private Database $db;
public function __construct(?Database $db = null) {
$this->db = $db ?? App::getDb();
}
/**
* @return array<int, array{id: int, name: string}>
*/
public function getTeams(): array {
$rows = $this->db->getRowset(
'SELECT id, TRIM(team_name) AS name FROM teams ORDER BY TRIM(team_name)'
);
return array_map(
static fn (array $row): array => [
'id' => (int) $row['id'],
'name' => $row['name'],
],
$rows
);
}
/**
* @return array<int, array{
* id: int,
* jira_sprint_id: int,
* sprint_name: string,
* sprint_activate_datetime: string,
* sprint_complete_datetime: string,
* sprint_completion_percentage: float|null
* }>
*/
public function getSprintsByTeamId(int $teamId): array {
$rows = $this->db->getRowset(
'SELECT id,
jira_sprint_id,
sprint_name,
sprint_activate_datetime,
sprint_complete_datetime,
sprint_completion_percentage
FROM sprints
WHERE team_id = :team_id
ORDER BY sprint_activate_datetime ASC',
['team_id' => $teamId]
);
return array_map(
static fn (array $row): array => [
'id' => (int) $row['id'],
'jira_sprint_id' => (int) $row['jira_sprint_id'],
'sprint_name' => $row['sprint_name'],
'sprint_activate_datetime' => $row['sprint_activate_datetime'],
'sprint_complete_datetime' => $row['sprint_complete_datetime'],
'sprint_completion_percentage' => $row['sprint_completion_percentage'] !== null
? (float) $row['sprint_completion_percentage']
: null,
],
$rows
);
}
}