I am almost in a Karate Kid position with the notebook because of the Fullcalendar: /
This is the following, I'm trying to get the data from a table through FullCalendar. As I use the procedural mode, it looks like this:
FullCalendar
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: Date(),
navLinks: true,
editable: true,
eventLimit: true,
eventClick: function(event) {
$('#visualizar #id').text(event.id);
$('#visualizar #title').text(event.title);
$('#visualizar #start').text(event.start.format('DD/MM/YYYY HH:mm:ss'));
$('#visualizar #end').text(event.end.format('DD/MM/YYYY HH:mm:ss'));
$('#visualizar').modal('show');
return false;
},
selectable: true,
selectHelper: true,
select: function(start, end){
$('#cadastrar #start').val(moment(start).format('DD/MM/YYYY HH:mm:ss'));
$('#cadastrar #end').val(moment(end).format('DD/MM/YYYY HH:mm:ss'));
$('#cadastrar').modal('show');
},
events:<?php echo $metodos->visualizarAgenda($idEmpresa,$idUsuario); ?>,
eventDrop:function(event)
{
var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
var title = event.title;
var id = event.id;
$.ajax({
url:"editar.php",
type:"POST",
data:{title:title, start:start, end:end, id:id},
success:function()
{
$('#confirmar').modal('show');
setTimeout(function() {
$('.modal').modal('hide');
}, 2000);
calendar.fullCalendar('refetchEvents');
}
});
}
});
});
Method viewAgenda ()
<?php
...
public function visualizarAgenda($idEmpresa,$idUsuario){
$sqlVisualizar = mysqli_query($this->conexao,"SELECT * FROM pe_agenda WHERE IdEmpresa = '".mysqli_real_escape_string($this->conexao,$idEmpresa)."' AND IdUsuarios = '".mysqli_real_escape_string($this->conexao,$idUsuario)."';");
$data = array();
$peVisualizar = mysqli_fetch_array($sqlVisualizar);
foreach($peVisualizar as $listar){
$data[] = array(
'id' => $listar["IdAgenda"],
'title' => $listar["Titulo"],
'start' => $listar["DataAgendamento"]
);
}
return json_encode($data);
}
The problem is that events do not appear in the calendar, but if I put them directly:
events: [
id: '11',
title: 'Vamos testar',
start: '2018-06-11'
],
They appear normally and when I give a print in the query and I ask directly in the DB, I see that there is nothing wrong with it.
The return appears this way:
[{"id:":"3","title:":"3","start:":"3"},{"id:":"3","title:":"3","start:":"3"},{"id:":"1","title:":"1","start:":"1"},{"id:":"1","title:":"1","start:":"1"},{"id:":"9","title:":"9","start:":"9"},{"id:":"9","title:":"9","start:":"9"},{"id:":"1","title:":"1","start:":"1"},{"id:":"1","title:":"1","start:":"1"},{"id:":"R","title:":"R","start:":"R"},{"id:":"R","title:":"R","start:":"R"},{"id:":"#","title:":"#","start:":"#"},{"id:":"#","title:":"#","start:":"#"},{"id:":"0","title:":"0","start:":"0"},{"id:":"0","title:":"0","start:":"0"},{"id:":"1","title:":"1","start:":"1"},{"id:":"1","title:":"1","start:":"1"},{"id:":"F","title:":"F","start:":"F"},{"id:":"F","title:":"F","start:":"F"},{"id:":"2","title:":"2","start:":"2"},{"id:":"2","title:":"2","start:":"2"}]
When I use it this way:
...
$data = array();
while($listar = mysqli_fetch_array($sqlVisualizar)) {
$data[] .= "id:" .$listar["IdAgenda"].",";
$data[] .= "title:" .$listar["Titulo"].",";
$data[] .= "start:" .$listar["DataAgenda"].",";
}
return json_encode($data);
It returns this way:
"id:3","title:Reuni\u00e3o da diretoria","start:07\/06\/2018","id:4","title:Testes dos candidatos","start:08\/06\/2018","id:5","title:Festa Junina","start:09\/06\/2018"