28 lines
868 B
PHP
28 lines
868 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/../_bootstrap.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$role = $GLOBALS['MESSAGES_CTX']['role'];
|
|
$meId = $GLOBALS['MESSAGES_CTX']['me_id'];
|
|
|
|
if ($role === 'praticien') {
|
|
$sql = "SELECT COALESCE(SUM(cc.p_unread),0)
|
|
FROM conversations c
|
|
LEFT JOIN conversation_counters cc ON cc.conversation_id = c.id
|
|
WHERE c.praticien_id = ?
|
|
AND c.deleted_for_praticien = 0";
|
|
} else {
|
|
$sql = "SELECT COALESCE(SUM(cc.c_unread),0)
|
|
FROM conversations c
|
|
LEFT JOIN conversation_counters cc ON cc.conversation_id = c.id
|
|
WHERE c.client_id = ?
|
|
AND c.deleted_for_client = 0";
|
|
}
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$meId]);
|
|
$total = (int)$stmt->fetchColumn();
|
|
|
|
json_response(['total' => $total]);
|