完整日历中3个月的事件颜色显示错误

时间:2017-11-21 09:11:31

标签: php json ajax fullcalendar

我正在使用FullCalendar v3.5.1。对于事件显示,我有以下代码。 但它适用于短期活动。从长远来看,比如三个月,着色是在第一个月和上个月进行,而不是在中间月进行。我知道它绘制了月份有开始日期或结束日期的事件颜色。

事件颜色显示从9月25日到11月到12日。但是10月份没有颜色。

在我的index.php文件中:

$(document).ready(function() {  
    $('#travelCalendarBlock').fullCalendar({        
        height:400,      
        editable: true,
        defaultView: 'month',
        eventLimit: true,         
        events: modJs.getTravel(),      
        loading: function(bool) {
            if (bool) $('#loadingTravelCalendarBlock').show();
            else $('#loadingTravelCalendarBlock').hide();
        }

     // I tested using below commented code, it works fine
    /*  height:400,
        defaultView: 'month',
        defaultDate: "2017-09-01",
        editable: true,
        eventLimit: true,
        selectable: true,        
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        events: [
            {
                title: 'Employee Leave',
                start: "2017-09-25",
                end: "2017-11-12",
                color: "#a4f0e3",
                textColor: "#190500"
            }
        ]*/

    });


In  javascript file


   EmployeeTravelCalendar.method('getTravel', function() {
        var url = this.moduleRelativeURL+"?a=ca&sa=getTravelsForMeAndSubordinates&t="+this.table+"&mod=modules%3Dtravelcal";
        return url;
    });

在travelcal.php文件中

public function getTravelsForMeAndSubordinates($req){

        $employeeTravel = new EmployeeTravelRecord();

        $req->start = strtotime($req->start);
        $req->end = strtotime($req->end);


        $startDate = date("Y-m-d H:i:s",$req->start);
        $endDate = date("Y-m-d H:i:s",$req->end);   

        $list = $employeeTravel->Find("((travel_date >= ? and travel_date <= ? ) or (return_date >= ? and return_date <= ?))",array($startDate,$endDate,$startDate,$endDate));

    $data = array();

        foreach($list as $leave){

            $data[] = $this->daytoEvent($leave);
        }   
        echo json_encode($data);
        exit();
    }


public function daytoEvent($leave, $leaveTypes){
        $event = array();
        $event['id'] = $leave->id;

        $event['title'] = $leave->employee." (".$leave->purpose.")";
        $event['start'] = $leave->travel_date; //2017-09-25
        $event['end'] = $leave->return_date;  //2017-11-15
        $eventBackgroundColor = "";     

        if($leave->type == "Local"){
            $eventBackgroundColor = "#a4f0e3";
            $eventTextColor = "#190500";
        }else{
            $eventBackgroundColor = "#c1a4f0";
            $eventTextColor = "#190500";
        }       

        $event['color'] = $eventBackgroundColor;
        $event['backgroundColor'] = $eventBackgroundColor;
        $event['textColor'] = $eventTextColor;

        return $event;
    }

这是示例JSON:

[
  { "id":"46",
    "title":"AnuB (test)",
    "start":"2017-09-25 15:28:26",
    "end":"2017-11-12 15:28:26",
    "color":"#c1a4f0",
    "backgroundColor":"#c1a4f0",
    "tex‌​tColor":"#190500"
  }
] 

0 个答案:

没有答案