<?php

namespace App\Services;

use App\Core\Database;

class PlatformCabinetService
{

public static function dashboard(
int $orgId,
int $conferenceId
): array
{

$db=
Database::getInstance();

$out=[];

$queries=[

'sessions'=>

"

SELECT COUNT(*)

FROM platform_cabinet_sessions

WHERE org_id=?

",

'decisions'=>

"

SELECT COUNT(*)

FROM platform_executive_decisions

WHERE org_id=?

",

'approved'=>

"

SELECT COUNT(*)

FROM platform_executive_decisions

WHERE org_id=?

AND approval_state='approved'

",

'strategy'=>

"

SELECT COUNT(*)

FROM platform_strategy_map

WHERE org_id=?

"

];

foreach(
$queries
as $k=>$sql
){

$stmt=
$db
->prepare(
$sql
);

$stmt
->execute([

$orgId

]);

$out[$k]=
(int)
$stmt
->fetchColumn();

}

$out[
'execution'
]=

$out[
'decisions'
]

?

min(

100,

round(

(
$out[
'approved'
]
/
max(
1,
$out[
'decisions'
]
)

)
*
100

)

+

(
$out[
'strategy'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'execution'
]>=80

?

'governing'

:

'aligning';

return
$out;

}

}
