-
Notifications
You must be signed in to change notification settings - Fork 0
/
listar_evento_calendario.php
70 lines (56 loc) · 2.1 KB
/
listar_evento_calendario.php
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
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include_once './config/constantes.php';
include_once './config/conexao.php';
include_once './func/dashboard.php';
try {
// Obtém a conexão
$conn = conectar();
// QUERY para recuperar os eventos da tabela 'events'
$query_events = "SELECT id, title, color, DATE_FORMAT(start, '%Y-%m-%dT%H:%i:%s') AS start, DATE_FORMAT(end, '%Y-%m-%dT%H:%i:%s') AS end FROM events";
// Prepara o QUERY
$result_events = $conn->prepare($query_events);
// Executa o QUERY
$result_events->execute();
// Criar o array que recebe os eventos
$eventos = [];
// Percorre a lista de registros retornados do banco de dados para a tabela 'events'
while ($row_events = $result_events->fetch(PDO::FETCH_ASSOC)) {
// Extrai o array
extract($row_events);
$eventos[] = [
'id' => $id,
'title' => $title,
'color' => $color,
'start' => $start,
'end' => $end,
];
}
// QUERY para recuperar os eventos da tabela 'pedidos'
$query_pedidos = "SELECT idpedidos as id, pedido as title, cor_pedidos as color, DATE_FORMAT(dataEntrega, '%Y-%m-%dT%H:%i:%s') AS start, DATE_FORMAT(dataEntrega, '%Y-%m-%dT%H:%i:%s') AS end FROM pedidos";
// Prepara o QUERY
$result_pedidos = $conn->prepare($query_pedidos);
// Executa o QUERY
$result_pedidos->execute();
// Percorre a lista de registros retornados do banco de dados para a tabela 'pedidos'
while ($row_pedidos = $result_pedidos->fetch(PDO::FETCH_ASSOC)) {
// Extrai o array
extract($row_pedidos);
$eventos[] = [
'id' => $id,
'title' => $title,
'color' => $color,
'start' => $start,
'end' => $end,
'tipo' => 'pedido'
];
}
// Configurar cabeçalho
header('Content-Type: application/json');
// Saída JSON
echo json_encode($eventos);
} catch (Exception $e) {
// Verificação de erro >.<
header('HTTP/1.1 500 Internal Server Error');
echo json_encode(['error' => 'Erro ao recuperar eventos: ' . $e->getMessage()]);
}
?>