1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
$stmt = $dbh->prepare("
/*SELECT
t.*,
slots.user_soc,
TIMEDIFF(max, min) AS diff,
TIME_TO_SEC(TIMEDIFF(max, min)) DIV TIME_TO_SEC(TIMEDIFF('09:30:00', '09:00:00')) AS x
FROM (*/
SELECT
MIN(TIME(debut)) AS min,
MAX(TIME(fin)) AS max
FROM slots
WHERE
TRUE
AND debut >= :from
AND debut <= :to
/*) t*/
"
);
$stmt->execute(
[
'to' => $to->format('Y-m-d H:i:s'),
'from' => $from->format('Y-m-d H:i:s'),
//'user_soc' => $userid,
]
);
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $dbh->prepare("
SELECT
DATE(debut) AS date,
slots.*,
slots.user_soc,
appointments.*,
slots.id AS slot_id,
appointments.id AS appointment_id,
TIME_TO_SEC(TIMEDIFF(TIME(debut), :min)) DIV TIME_TO_SEC(TIMEDIFF(fin, debut)) AS row
FROM slots
LEFT JOIN appointments_slots ON slots.id = appointments_slots.slot_id
LEFT JOIN appointments ON appointments_slots.appointment_id = appointments.id
WHERE
TRUE
AND debut >= :from
AND debut <= :to
AND user_soc = :user_soc
ORDER BY debut
"
);
$stmt->execute(
[
'min' => $stats['min'],
'to' => $to->format('Y-m-d H:i:s'),
'from' => $from->format('Y-m-d H:i:s'),
'user_soc' => $userid,
]
);
$slots = $stmt->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_ASSOC); |
Partager