<?php

namespace App\Services;

use App\Core\Database;

class HomepageGraphService
{

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

$db=
Database::getInstance();

$out=[];

$tables=[

'nodes'=>

'conference_home_graph_nodes',

'edges'=>

'conference_home_graph_edges',

'blocks'=>

'conference_homepage_blocks',

'sections'=>

'conference_home_sections'

];

foreach(
$tables
as $k=>$table
){

$stmt=
$db
->prepare(

"

SELECT COUNT(*)

FROM {$table}

WHERE conference_id=?

"

);

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'density'
]=

$out[
'nodes'
]

?

round(

(
$out[
'edges'
]
/
max(
1,
$out[
'nodes'
]
)

)
*
100

)

:

0;

$out[
'state'
]=

$out[
'density'
]
>70

?

'connected'

:

'growing';

return
$out;

}

}
