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

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

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

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

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

$('#calendar').fullCalendar({
    theme: true,header: {
        left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'
    },buttonIcons: {
        prev: 'circle-triangle-w',next: 'circle-triangle-e'
    },<?PHP if($jsonEvents !='') { ?>
    dayClick: function(date,allDay,jsEvent,view) {
      allday:false;
      var selectDate = "";
      var selectTime = "";
      if(view.name !="month") {
        if(allDay) {
          selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
        }
        else {
          selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
          selectTime = $.fullCalendar.formatDate( date,'hh:mm TT');
        }
      }
      else {
        selectDate = $.fullCalendar.formatDate( date,'yyyy-MM-dd');
      }

      if( selectDate !="") {
        $("#startDate").val(selectDate);
        $('#startDate').datepicker('setValue',selectDate);
        $("#endDate").val(selectDate);
        $('#endDate').datepicker('setValue',selectDate);
      }

      if(selectTime !="")   {
        $("#startTime").val(selectTime);
        $('#startTime').timepicker({'timeFormat': 'h:i A','scrollDefaultNow': true,'forceRoundTime': true }).on('change',function(ev){
          $('#endTime').val(Add30Min($(this).val()));
          $('#endTime').timepicker({'timeFormat': 'h:i A','forceRoundTime': true,'minTime': selectTime});
        });
        $("#endTime").val(Add30Min(selectTime));
        $('#endTime').timepicker({'timeFormat': 'h:i A','minTime': selectTime});
      }
      $("#eventId").val("");
      $("#mainModalHead").text("Add Event");
      $("#hidEditEventId").val("");
      $("#EventModal").modal();
    },eventClick: function(calEvent,view) {

      var startDayName = $.fullCalendar.formatDate( calEvent.start,'ddd');
      var startMonthName = $.fullCalendar.formatDate( calEvent.start,'MMM dd');
      var startTime = $.fullCalendar.formatDate( calEvent.start,'hh:mm TT');
      var startDetails = startDayName+","+startMonthName+","+startTime;

      var endDayName = $.fullCalendar.formatDate( calEvent.end,'ddd');
      var endMonthName = $.fullCalendar.formatDate( calEvent.end,'MMM dd');
      var endTime = $.fullCalendar.formatDate( calEvent.end,'hh:mm TT');
      var endDetails = endDayName+","+endMonthName+","+endTime;

      var eventDetails = startDetails+" - "+endDetails;
      $("#googleEventTitle").text(calEvent.title);
      $("#googleEventBody").text(eventDetails);
      $("#eventId").val(calEvent.id);
      $("#hidEventName").val(calEvent.title);
      $("#hidStartDate").val($.fullCalendar.formatDate( calEvent.start,'yyyy-MM-dd'));
      $("#hidStartTime").val($.fullCalendar.formatDate( calEvent.start,'hh:mm TT'));
      $("#hidEndDate").val($.fullCalendar.formatDate( calEvent.end,'yyyy-MM-dd'));
      $("#hidEndTime").val($.fullCalendar.formatDate( calEvent.end,'hh:mm TT'));
      $("#eventDelete").attr("disabled",false);
      $("#eventEdit").attr("disabled",false);
      $("#EditDeleteOperationModal").modal();
    },<?PHP } ?>
    weekNumbers : false,weekMode : 'fixed',editable: false,<?PHP if($jsonEvents !='') { ?>
      events: <?PHP echo $jsonEvents; ?>,<?PHP } ?>
    timeFormat: 'hh:mm tt',eventColor: '#3c8dbc',eventTextColor: '#ffffff'
});

这是json事件列表.

$eventItems = $eventList['items']; //From Google        
$x=0;
$events   = array();
$startDateTime ='';
$endDateTime ='';
$summary = '';
$start = array();
$end = array();

foreach($eventItems as $item) {
    if(isset($item['summary'])) {

         $summary = $item['summary'];

    }
    $start = $item['start'];
    if(isset($start['dateTime'])) { 

        $startDateTime = $start['dateTime'];

    }
    else if(isset($start['date'])) {

        $startDateTime = $start['date'];

    }
    $end = $item['end'];
    if(isset($end['dateTime'])) {

        $endDateTime = $end['dateTime'];

    }
    else if(isset($end['date'])) {

        $endDateTime = $end['date'];

    }

    $events[$x]['id']               = $item['id'];          
    $events[$x]['title']            = $summary;
    $events[$x]['start']            = $startDateTime;
    $events[$x]['end']              = $endDateTime;
    $events[$x]['allDay']           = true;
    $events[$x]['backgroundColor']  = '#0092D0';
    $x++;
}
$jsonEvents = json_encode($events);

}

$jsonEvents返回以下内容;

string(3742) "[{
    "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就像构建一样

$eventList  = $cal->events->listEvents(
    'primary',array(
        'timeMin' =>''.$pastEvents.'T01:00:00Z','timeMax' =>''.$futureEvents.'T23:59:59Z','singleEvents' => true
    )
);
$eventItems = $eventList['items']; //From Google        
$x=0;
$events   = array();
$startDateTime ='';
$endDateTime ='';
$summary = '';
$start = array();
$end = array();

foreach($eventItems as $item) {
    if(isset($item['summary'])) {

         $summary = $item['summary'];

    }
    $start = $item['start'];
    if(isset($start['dateTime'])) { 

        $startDateTime = $start['dateTime'];

    }
    else if(isset($start['date'])) {

        $startDateTime = $start['date'];

    }
    $end = $item['end'];
    if(isset($end['dateTime'])) {

        $endDateTime = $end['dateTime'];

    }
    else if(isset($end['date'])) {

        $endDateTime = $end['date'];

    }

    $events[$x]['id']               = $item['id'];          
    $events[$x]['title']            = $summary;
    $events[$x]['start']            = $startDateTime;
    $events[$x]['end']              = $endDateTime;
    $events[$x]['allDay']           = true;
    $events[$x]['backgroundColor']  = '#0092D0';
    $x++;
}
$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 …因为没有抛出错误.
至少有一个错误会有所帮助.
我建议你提交一份错误报告,看看他们的答案. 原文链接:https://www.f2er.com/php/134241.html

猜你在找的PHP相关文章