当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Fullcalendar - Events loading in allDay, suspected Time Formatting issue?

问题描述:

I have been digging at this issue for the better part of a fortnight - no joy, reading any and all terms i could think of searching on here and Google (this post is the last straw).

Essentially, I have the below code retrieving data via JSON from my database. Displays the event, but in the "allDay" slot. To help, i did a var_dump from the JSON file and it is also below.

Can anyone see where/why this isn't placing the events at their appropriate time slots?

var_dump from JSON:

object(PDOStatement)#2 (1) { ["queryString"]=> string(34) "SELECT * FROM heli_cal ORDER BY id" } [{"id":"000000000000001","title":"Test","start":"2014-10-19 16:30:00","end":"2014-10-19 17:00:00","url":"","allDay":"false"},{"id":"000000000000002","title":"James","start":"2014-10-23 09:00:00","end":"2014-10-23 17:00:00","url":"","allDay":"true"}]

JQuery (Fullcalendar):

<script>

$(document).ready(function() {

var date = new Date();

var d = date.getDate();

var m = date.getMonth();

var y = date.getFullYear();

var calendar = $('#calendar').fullCalendar({

allDayDefault: false,

editable: true,

defaultView: 'agendaWeek',

header: {

left: 'prev,next today',

center: 'title',

right: 'basicDay,agendaDay,agendaWeek,month',

},

events: function(start, end, timezone, callback) {

JSON.parse($.ajax({

type: "GET",

url: "required/events.php",

async: false,

success: function(doc) {

var events = [];

$(doc).find('event').each(function() {

events.push({

id: $(this).attr('id'),

title: $(this).attr('title'),

start: $(this).attr('start'),

end: $(this).attr('end'),

allDay: $(this).attr('allDay')

});

});

callback(events);

}

}).responseText);

},

// Convert the allDay from string to boolean

eventRender: function(event, element, view) {

if (event.allDay === 'true') {

event.allDay = true;

} else {

event.allDay = false;

}

},

selectable: true,

selectHelper: true,

select: function(start, end, allDay) {

var title = prompt('Event Title:');

//var url = prompt('Type Event url, if exits:');

if (title) {

var start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");

var end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");

$.ajax({

url: 'actions/event_add.php',

data: 'title='+ title+'&start='+ start +'&end='+ end,

type: "POST",

success: function(json) {

alert('Added Successfully');

}

});

calendar.fullCalendar('renderEvent',

{

title: title,

start: start,

end: end,

allDay: allDay

},

true // make the event "stick"

);

}

calendar.fullCalendar('unselect');

},

editable: true,

eventDrop: function(event, delta) {

var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");

var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");

$.ajax({

url: 'actions/event_update.php',

data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,

type: "POST",

success: function(json) {

alert("Updated Successfully");

}

});

},

eventClick: function(calEvent, jsEvent, view) {

alert('Event: ' + calEvent.title + ' Start: ' + calEvent.start + ' Finish: ' + calEvent.end + ' allDay: ' + calEvent.allDay);

},

eventResize: function(event) {

var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");

var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");

$.ajax({

url: 'actions/event_update.php',

data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,

type: "POST",

success: function(json) {

alert("Updated Successfully");

}

});

}

});

});

</script>

JSON PHP:

<?php

// List of events

$json = array();

// Query that retrieves events

$query = "SELECT * FROM heli_cal ORDER BY id";

// connection to the database

try {

$bdd = new PDO('mysql:host=****;dbname=****', '****', '****');

} catch(Exception $e) {

exit('Unable to connect to database.');

}

// Execute the query

$result = $bdd->query($query) or die(print_r($bdd->errorInfo()));

// sending the encoded result to success page

echo json_encode($result->fetchAll(PDO::FETCH_ASSOC));

?>

Debugging:

 [Object, Object] 0: ObjectallDay: "false"

end: "2014-10-19 17:00:00"

id: "000000000000001"

start: "2014-10-19 16:30:00"

title: "Test"

url: ""

__proto__: Object__defineGetter__: function __defineGetter__() {

[native code]

}

__defineSetter__: function __defineSetter__() {

[native code]

}

__lookupGetter__: function __lookupGetter__() {

[native code]

}

__lookupSetter__: function __lookupSetter__() {

[native code]

}

constructor: function Object() {

[native code]

}

hasOwnProperty: function hasOwnProperty() {

[native code]

}

isPrototypeOf: function isPrototypeOf() {

[native code]

}

propertyIsEnumerable: function propertyIsEnumerable() {

[native code]

}

toLocaleString: function toLocaleString() {

[native code]

}

toString: function toString() {

[native code]

}

valueOf: function valueOf() {

[native code]

}

get __proto__: function __proto__() {

[native code]

}

set __proto__: function __proto__() {

[native code]

}

1: ObjectallDay: "true"

end: "2014-10-23 17:00:00"

id: "000000000000002"

start: "2014-10-23 09:00:00"

title: "James"

url: ""

__proto__: Object__defineGetter__: function __defineGetter__() {

[native code]

}

__defineSetter__: function __defineSetter__() {

[native code]

}

__lookupGetter__: function __lookupGetter__() {

[native code]

}

__lookupSetter__: function __lookupSetter__() {

[native code]

}

constructor: function Object() {

[native code]

}

hasOwnProperty: function hasOwnProperty() {

[native code]

}

isPrototypeOf: function isPrototypeOf() {

[native code]

}

propertyIsEnumerable: function propertyIsEnumerable() {

[native code]

}

toLocaleString: function toLocaleString() {

[native code]

}

toString: function toString() {

[native code]

}

valueOf: function valueOf() {

[native code]

}

get __proto__: function __proto__() {

[native code]

}

set __proto__: function __proto__() {

[native code]

}

length: 2 __proto__: Array[0]

分享给朋友:
您可能感兴趣的文章:
随机阅读: