<?php

namespace App\Services;

use App\Core\Database;

class HomepageFederationService
{

public static function catalog(
int $orgId
): array
{

$db=
Database::getInstance();

$stmt=
$db
->prepare("

SELECT

catalog_key,

catalog_type,

title_en,

title_ar,

created_at

FROM
conference_home_catalog

WHERE org_id=?

ORDER BY id DESC

LIMIT 50

");

$stmt
->execute([

$orgId

]);

return
$stmt
->fetchAll()

??

[];

}

public static function publish(
int $orgId,
array $payload,
int $userId
): bool
{

$db=
Database::getInstance();

return
$db
->prepare("

INSERT INTO
conference_home_catalog(

org_id,

catalog_key,

catalog_type,

title_en,

payload_json,

created_by

)

VALUES(

?,

?,

'homepage',

?,

?,

?

)

")

->execute([

$orgId,

'federated_'
.
date(
'YmdHis'
),

$payload[
'title'
]

??

'Homepage',

json_encode(
$payload,
JSON_UNESCAPED_UNICODE
),

$userId

]);

}

}
