<?php

namespace App\Services;

use App\Core\Database;

class HomepagePresenceService
{

public static function ping(
int $conferenceId,
int $userId,
string $name
): void
{

$db=
Database::getInstance();

$db
->prepare("

INSERT INTO
conference_home_presence(

conference_id,

user_id,

editor_name,

page_key

)

VALUES(

?,

?,

?,

'studio'

)

ON DUPLICATE KEY UPDATE

last_seen=NOW(),

is_editing=1

")

->execute([

$conferenceId,

$userId,

$name

]);

}

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

$db=
Database::getInstance();

$stmt=
$db
->prepare("

SELECT

editor_name,

last_seen

FROM
conference_home_presence

WHERE

conference_id=?

AND

last_seen>

DATE_SUB(
NOW(),
INTERVAL 90 SECOND
)

ORDER BY last_seen DESC

");

$stmt
->execute([

$conferenceId

]);

return
$stmt
->fetchAll();

}

}
