31 lines
995 B
PHP
31 lines
995 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
function push_queue_notification(
|
|
PDO $pdo,
|
|
array $target, // ['compte_id'=>?, 'role'=>?, 'reference_id'=>?] (tu peux passer 1 ou 2 champs)
|
|
string $type,
|
|
string $title,
|
|
string $body,
|
|
?string $url = null,
|
|
?array $data = null
|
|
): int {
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO push_notifications
|
|
(target_role, target_reference_id, target_compte_id, type, title, body, url, data_json, status, created_at)
|
|
VALUES
|
|
(:role, :ref, :cid, :type, :title, :body, :url, :data, 'pending', NOW())
|
|
");
|
|
$stmt->execute([
|
|
':role' => (string)($target['role'] ?? 'client'),
|
|
':ref' => isset($target['reference_id']) ? (int)$target['reference_id'] : null,
|
|
':cid' => isset($target['compte_id']) ? (int)$target['compte_id'] : null,
|
|
':type' => $type,
|
|
':title'=> $title,
|
|
':body' => $body,
|
|
':url' => $url,
|
|
':data' => $data ? json_encode($data, JSON_UNESCAPED_UNICODE) : null,
|
|
]);
|
|
return (int)$pdo->lastInsertId();
|
|
}
|