Hi, I’m doing my college title project. For which I am using Fullcalendar (https://fullcalendar.io/) and Codeigniter. I need to select a teacher from a listboxt to display their schedule in the calendar, but I have not been able to do it. Investigate and you should use businessHours for this. So far I have the sql query of the database, but it complicates me to pass the data to fullcalendar. If anyone could help me, I would be very grateful. I leave my code:
PS: I hope you understand, use google translator, I’m Spanish speaking
Controller
public function monday(){
$rut_jc = $this->input->post('rut_jc');
$r = $this->M_Calendar->monday_($rut_jc);
echo json_encode($r);
}
Model
public function monday($rut_jc){
$this->db->select('MIN(horario.hrs_ini) AS hrs_ini, MAX(horario.hrs_ter) AS hrs_ter ');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu',$rut_jc );
$this->db->where('horario.lunes','ATTE. ESTUDIANTES');
$monday = $this->db->get();
if($monday->num_rows() > 0 ){
return $monday->result();
}
}
Fullcalendar Javascript
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
defaultDate: new Date(),
//navLinks: true, // can click day/week names to navigate views
businessHours: [ // specify an array instea
{
dow: [ 1], // Monday
start: '', // 8am
end: '16:00' // 6pm
},
{
dow: [2], // Tuesday
start: '10:00', // 10am
end: '16:00' // 4pm
},
{
dow: [3], // Wednesday
start: '10:00', // 10am
end: '16:00' // 4pm
},
{
dow: [4], // Thursday
start: '10:00', // 10am
end: '16:00' // 4pm
},
{
dow: [5], // Friday
start: '10:00', // 10am
end: '16:00' // 4pm
},
{
dow: [6], // Saturday
start: '10:00', //
end: '16:00',
},
],
events: function(start, end, timezone, callback) {
$.post('<?php echo base_url(); ?>C_Calendar/geteventos', {
//"start": start.format("YYYY-MM-DD"),
//"end": end.format("YYYY-MM-DD"),
"rut_jc": $("#rut_jc").val()
},
function(data) {
callback($.parseJSON(data));
}
);
},
dayClick: function(date, jsEvent, view, start, end, allDay) {
$('#modal_registrar').modal();
} ,
eventClick: function(event, jsEvent, view) {
$('#event_id').val(event.id);
$('#id_mot2').val(event.mot);
$('#nombre_estudiante').val(event.estudiante);
$('#jc2').val(event.jefe_c);
$('#rut_estudiante').val(event.rut_estudiante)
$('#start_f').val(moment(event.start).format('DD/MM/YYYY HH:mm:ss'));
$('#end_f').val(moment(event.end).format('DD/MM/YYYY HH:mm'));
$('#modal_editar').modal();
},
eventDrop: function(event, delta, revertFunc) {
if(event.start < currentDate) {
revertFunc();
}
},
minTime: "08:30:00",
maxTime: "23:00:00"
});
Select the teacher
$("#rut_jc").change(function(){
$("#calendar").fullCalendar('refetchEvents');
var op=document.getElementById("rut_jc");
if (op.selectedIndex > 0)$("#jc").val($( "#rut_jc option:selected" ).text()) ;
$("#rut_usu").val($("#rut_jc").val());
$.ajax({
data: parametros,
url: '<?php echo base_url();?>C_Calendar/monday',
type: 'post',
beforeSend: function () {
$("#rut_jc").val();
},
success: function (response) {
$("#rut_jc").val(response);
}
});
});
My table in the database