<?php

namespace App\Services;

use App\Core\Database;

class HomepagePolicyService
{

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

$db=
Database::getInstance();

$p=
$db
->prepare("

SELECT
policy_value

FROM
conference_home_policies

WHERE org_id=?

AND policy_key='required_sections'

LIMIT 1

");

$p
->execute([

$orgId

]);

$required=

explode(
',',
(string)
$p
->fetchColumn()
);

$s=
$db
->prepare("

SELECT
section_key

FROM
conference_home_sections

WHERE conference_id=?

");

$s
->execute([

$conferenceId

]);

$existing=

$s
->fetchAll(
\PDO::FETCH_COLUMN
);

$missing=

array_values(

array_diff(

$required,

$existing

)

);

return [

'passed'=>

empty(
$missing
),

'missing'=>

$missing

];

}

}
