-2

I'm creating a scheduling web application and I'm trying to load in my resources from my SQL database. It is showing that it is running my php file to retrieve the resources, but none of them are being displayed on the calendar. I'm not really sure why they aren't showing, i looked through fullcalendar's docs and it seemed to me that I am playing by the rules. Anyone know why?

Here is the code for fullcalendar:

   var calendar = $('#calendar').fullCalendar({
    schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
    header:{
      left:'promptResource, prev, next, today',
      center:'title',
      right: 'month, agendaDay, timelineThreeDays, listDay'
    },
    views: {
      timelineThreeDays: {
        type: 'timeline',
        duration: { days: 3 },
        slotWidth: 75,
      }
    },
    businessHours: {
      dow: [1, 2, 3, 4, 5],
      start: "09:00",
      end: "17:00",
    },
    resources: "resourceGetScript.php",
    events: [
      { id: '1', resourceId: '1', start: '2017-04-05T10:00:00', end: '2017-04-05T11:00:00', title: 'event 1', doctor: 'Habib Habib'},
    ],
    defaultView: "timelineDay",
    minTime: "09:00",
    maxTime: "17:00",
    weekends: false,
    slotDuration: "01:00:00",
    allDaySlot: false,
    selectable: true,
    theme: true,
    contentHeight: 800,
    eventOverlap: false,
    resourceAreaWidth: "12%",
    slotWidth: 200,
    resourceLabelText: 'Rooms',
    select: function(start, end, allDay, jsEvent, view) {
      alert("test");
    },
    eventClick: function(calEvent, jsEvent, view){
      var myResource = calendar.fullCalendar('getEventResource', calEvent);
      myResource.title = "Change";
      calendar.fullCalendar('refetchResources');
      alert('Event: ' + calEvent.title + " " + calEvent.resourceId + " " + myResource.title);
    },
    resourceRender: function(resourceObj, labelTds, bodyTds){
      labelTds.on('click', function(){alert("clicked" + resourceObj.id + resourceObj.title);});
    }
  })

and here is the code for resourceGetScript.php where I retrieve my resources from the database:

<?php
  session_start();
  include("includes/databaseHandler.inc.php");
  if(!isset($_SESSION['name'])){
    header("Location: ../index.php");
  }

  if($stmt = mysqli_prepare($conn, "SELECT * FROM rooms")){
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $resources = array();
    while ($row = mysqli_fetch_assoc($result)){
      $resourceArray['id'] = $row['id'];
      $resourceArray['title'] = $row['title'];
      $resources[] = $resourceArray;
    }

    echo json_encode($resources);
  }
 ?>
Frank
  • 99
  • 13

1 Answers1

0

Have not fully used the resources function of FullCalendar. But to eliminate the issue, first try to hard code in some resources using this documantation: https://fullcalendar.io/docs/resource_data/resources_array/.

You could use this demo to manually construct a resource and test your PHP file: https://github.com/StarterSquad/fullcalendar-resource/blob/master/demos/json-resource-events.php.

If it works correctly, run the resourceGetScript.php file and print_r($resources) right before the jscon_encode($resources) to ensure that you have structured the resource correctly. Also check the format of the text by using mb_detect_encoding() and if need be, convert to UTF-8 if anything but that using mb_convert_encoding().

I hope this helps you debug your issue. Sorry that I could give you a straight answer.