Display holidays from JSON feed

This commit is contained in:
coolneng 2020-07-14 21:36:43 +02:00
parent 5e0285d608
commit d3e6b5a549
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
5 changed files with 44 additions and 6 deletions

View File

@ -11,7 +11,7 @@ function computeEndTime(&$data){
} }
function renameArray($data){ function formatArray($data){
computeEndTime($data); computeEndTime($data);
$events = array(); $events = array();
foreach($data as $row){ foreach($data as $row){
@ -36,7 +36,7 @@ function fetchDatabase(){
$result = fetchDatabase(); $result = fetchDatabase();
$events = renameArray($result); $events = formatArray($result);
echo json_encode($events); echo json_encode($events);
?> ?>

View File

@ -22,7 +22,7 @@ function listEvents($pdo){
function listHolidays($pdo){ function listHolidays($pdo){
$doctor = fetchDoctor($pdo); $doctor = fetchDoctor($pdo);
$holidays = fetchDoctorHolidays($pdo, $doctor); $holidays = fetchDoctorHolidays($pdo, $doctor);
return json_encode($holidays); return $holidays;
} }

View File

@ -10,10 +10,12 @@
right: 'month,agendaWeek,agendaDay' right: 'month,agendaWeek,agendaDay'
}, },
events: "appointment_feed.php" + queryString, eventSources: [
"appointment_feed.php" + queryString,
"holiday_feed.php" + queryString
],
selectable: true, selectable: true,
selectHelper: true, selectHelper: true,
select: function(start, end) { select: function(start, end) {

View File

@ -395,7 +395,9 @@ function fetchCalendarSettings($pdo, $doctor)
function fetchDoctorHolidays($pdo, $doctor) function fetchDoctorHolidays($pdo, $doctor)
{ {
$query = "SELECT * FROM festivo WHERE medico IS NULL OR medico=?"; $query = "SELECT festivo.id, fecha_festivo, tipo_festivo, medico, nombre FROM festivo
INNER JOIN usuario ON festivo.medico = usuario.id;
WHERE medico IS NULL OR medico=?";
$result = $pdo->prepare($query); $result = $pdo->prepare($query);
$result->execute([$doctor]); $result->execute([$doctor]);
$data = $result->fetchAll(PDO::FETCH_ASSOC); $data = $result->fetchAll(PDO::FETCH_ASSOC);

34
src/holiday_feed.php Normal file
View File

@ -0,0 +1,34 @@
<?php
include 'appointment_management.php';
function formatArray($data){
$events = array();
foreach($data as $row){
$events[] = array(
"id" => $row["id"],
"title" => "Festivo",
"start" => $row["fecha_festivo"],
"description" => $row["tipo_festivo"],
"doctor" => $row["nombre"],
"groupId" => "holidays",
"rendering" => "background",
"color" => "#ffa6a3",
);
}
return $events;
}
function fetchDatabase(){
$pdo = connectDatabase();
$data = listHolidays($pdo);
closeDatabase($pdo);
return $data;
}
$result = fetchDatabase();
$events = formatArray($result);
echo json_encode($events);
?>