<?php

namespace App\Services;

use App\Core\Database;

class HomepageStrategyService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'objectives'=>

"

SELECT COUNT(*)

FROM conference_home_objectives

WHERE conference_id=?

",

'completed'=>

"

SELECT COUNT(*)

FROM conference_home_objectives

WHERE conference_id=?

AND objective_status='completed'

",

'deployments'=>

"

SELECT COUNT(*)

FROM conference_home_deployments

WHERE conference_id=?

",

'branches'=>

"

SELECT COUNT(*)

FROM conference_home_branches

WHERE conference_id=?

"

];

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

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

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'execution'
]=

$out[
'objectives'
]

?

round(

(
$out[
'completed'
]
/
max(
1,
$out[
'objectives'
]
)

)
*
100

)

:

0;

$out[
'state'
]=

$out[
'execution'
]>=70

?

'on_track'

:

'focus';

return
$out;

}

}
