php – 显示全天活动的完整日历

前端之家收集整理的这篇文章主要介绍了php – 显示全天活动的完整日历前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用完整的日历,日历正在使用Google Calendar API来引入事件.

我在议程周刊和agendaDay中查看时间显示为全天的活动时遇到问题.这可以防止用户正确显示他们的事件,并且他们很难确定他们在一天或一周内的可用性.

我已经确认事件有时间从早上8点到早上10点.

任何想法?很难将这个排序.

  1. $('#calendar').fullCalendar({
  2. theme: true,header: {
  3. left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'
  4. },buttonIcons: {
  5. prev: 'circle-triangle-w',next: 'circle-triangle-e'
  6. },<?PHP if($jsonEvents !='') { ?>
  7. dayClick: function(date,allDay,jsEvent,view) {
  8. allday:false;
  9. var selectDate = "";
  10. var selectTime = "";
  11. if(view.name !="month") {
  12. if(allDay) {
  13. selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
  14. }
  15. else {
  16. selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
  17. selectTime = $.fullCalendar.formatDate( date,'hh:mm TT');
  18. }
  19. }
  20. else {
  21. selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
  22. }
  23.  
  24. if( selectDate !="") {
  25. $("#startDate").val(selectDate);
  26. $('#startDate').datepicker('setValue',selectDate);
  27. $("#endDate").val(selectDate);
  28. $('#endDate').datepicker('setValue',selectDate);
  29. }
  30.  
  31. if(selectTime !="") {
  32. $("#startTime").val(selectTime);
  33. $('#startTime').timepicker({'timeFormat': 'h:i A','scrollDefaultNow': true,'forceRoundTime': true }).on('change',function(ev){
  34. $('#endTime').val(Add30Min($(this).val()));
  35. $('#endTime').timepicker({'timeFormat': 'h:i A','forceRoundTime': true,'minTime': selectTime});
  36. });
  37. $("#endTime").val(Add30Min(selectTime));
  38. $('#endTime').timepicker({'timeFormat': 'h:i A','minTime': selectTime});
  39. }
  40. $("#eventId").val("");
  41. $("#mainModalHead").text("Add Event");
  42. $("#hidEditEventId").val("");
  43. $("#EventModal").modal();
  44. },eventClick: function(calEvent,view) {
  45.  
  46. var startDayName = $.fullCalendar.formatDate( calEvent.start,'ddd');
  47. var startMonthName = $.fullCalendar.formatDate( calEvent.start,'MMM dd');
  48. var startTime = $.fullCalendar.formatDate( calEvent.start,'hh:mm TT');
  49. var startDetails = startDayName+","+startMonthName+","+startTime;
  50.  
  51. var endDayName = $.fullCalendar.formatDate( calEvent.end,'ddd');
  52. var endMonthName = $.fullCalendar.formatDate( calEvent.end,'MMM dd');
  53. var endTime = $.fullCalendar.formatDate( calEvent.end,'hh:mm TT');
  54. var endDetails = endDayName+","+endMonthName+","+endTime;
  55.  
  56. var eventDetails = startDetails+" - "+endDetails;
  57. $("#googleEventTitle").text(calEvent.title);
  58. $("#googleEventBody").text(eventDetails);
  59. $("#eventId").val(calEvent.id);
  60. $("#hidEventName").val(calEvent.title);
  61. $("#hidStartDate").val($.fullCalendar.formatDate( calEvent.start,'yyyy-MM-dd'));
  62. $("#hidStartTime").val($.fullCalendar.formatDate( calEvent.start,'hh:mm TT'));
  63. $("#hidEndDate").val($.fullCalendar.formatDate( calEvent.end,'yyyy-MM-dd'));
  64. $("#hidEndTime").val($.fullCalendar.formatDate( calEvent.end,'hh:mm TT'));
  65. $("#eventDelete").attr("disabled",false);
  66. $("#eventEdit").attr("disabled",false);
  67. $("#EditDeleteOperationModal").modal();
  68. },<?PHP } ?>
  69. weekNumbers : false,weekMode : 'fixed',editable: false,<?PHP if($jsonEvents !='') { ?>
  70. events: <?PHP echo $jsonEvents; ?>,<?PHP } ?>
  71. timeFormat: 'hh:mm tt',eventColor: '#3c8dbc',eventTextColor: '#ffffff'
  72. });

这是json事件列表.

  1. $eventItems = $eventList['items']; //From Google
  2. $x=0;
  3. $events = array();
  4. $startDateTime ='';
  5. $endDateTime ='';
  6. $summary = '';
  7. $start = array();
  8. $end = array();
  9.  
  10. foreach($eventItems as $item) {
  11. if(isset($item['summary'])) {
  12.  
  13. $summary = $item['summary'];
  14.  
  15. }
  16. $start = $item['start'];
  17. if(isset($start['dateTime'])) {
  18.  
  19. $startDateTime = $start['dateTime'];
  20.  
  21. }
  22. else if(isset($start['date'])) {
  23.  
  24. $startDateTime = $start['date'];
  25.  
  26. }
  27. $end = $item['end'];
  28. if(isset($end['dateTime'])) {
  29.  
  30. $endDateTime = $end['dateTime'];
  31.  
  32. }
  33. else if(isset($end['date'])) {
  34.  
  35. $endDateTime = $end['date'];
  36.  
  37. }
  38.  
  39. $events[$x]['id'] = $item['id'];
  40. $events[$x]['title'] = $summary;
  41. $events[$x]['start'] = $startDateTime;
  42. $events[$x]['end'] = $endDateTime;
  43. $events[$x]['allDay'] = true;
  44. $events[$x]['backgroundColor'] = '#0092D0';
  45. $x++;
  46. }
  47. $jsonEvents = json_encode($events);

}

$jsonEvents返回以下内容;

  1. string(3742) "[{
  2. "id":"32rsm3h04dsuoikk2r1arfc3m0_20170624T160000Z","title":"Car payment $330.00 28th","start":"2017-06-24T09:00:00-07:00","end":"2017-06-24T10:00:00-07:00","allDay":true,"backgroundColor":"#0092D0"},}]"

jsonEvents就像构建一样

  1. $eventList = $cal->events->listEvents(
  2. 'primary',array(
  3. 'timeMin' =>''.$pastEvents.'T01:00:00Z','timeMax' =>''.$futureEvents.'T23:59:59Z','singleEvents' => true
  4. )
  5. );
  6. $eventItems = $eventList['items']; //From Google
  7. $x=0;
  8. $events = array();
  9. $startDateTime ='';
  10. $endDateTime ='';
  11. $summary = '';
  12. $start = array();
  13. $end = array();
  14.  
  15. foreach($eventItems as $item) {
  16. if(isset($item['summary'])) {
  17.  
  18. $summary = $item['summary'];
  19.  
  20. }
  21. $start = $item['start'];
  22. if(isset($start['dateTime'])) {
  23.  
  24. $startDateTime = $start['dateTime'];
  25.  
  26. }
  27. else if(isset($start['date'])) {
  28.  
  29. $startDateTime = $start['date'];
  30.  
  31. }
  32. $end = $item['end'];
  33. if(isset($end['dateTime'])) {
  34.  
  35. $endDateTime = $end['dateTime'];
  36.  
  37. }
  38. else if(isset($end['date'])) {
  39.  
  40. $endDateTime = $end['date'];
  41.  
  42. }
  43.  
  44. $events[$x]['id'] = $item['id'];
  45. $events[$x]['title'] = $summary;
  46. $events[$x]['start'] = $startDateTime;
  47. $events[$x]['end'] = $endDateTime;
  48. $events[$x]['allDay'] = true;
  49. $events[$x]['backgroundColor'] = '#0092D0';
  50. $x++;
  51. }
  52. $jsonEvents = json_encode($events);

}

我找到了关于allDay的问题.

您使用start / end和allDay之间存在冲突.

documentation

If all else fails,FullCalendar will try to guess. If either the start or end value has a “T” as part of the ISO8601 date string,allDay will become false. Otherwise,it will be true.

当FullCalendar试图将其覆盖为false时,似乎将其“强制”为真,导致该问题.

也许这可以被报告为一个bug …因为没有抛出错误.
至少有一个错误会有所帮助.
我建议你提交一份错误报告,看看他们的答案.

猜你在找的PHP相关文章