使用Laravel在FullCalendar中重复发生的事件 [英] Recurring events in FullCalendar with Laravel

查看:58
本文介绍了使用Laravel在FullCalendar中重复发生的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的页面制作一个fullcalendar模块。我可以在没有重复功能的日历上显示事件。但是当我改变我的表以包含重复的功能时,我无法显示表中的事件。
这是我的表结构。

I'm working on a fullcalendar module for my page.I could display Events on calendar without the recurring feature. But when I altered my table to include recurring features I could not display events from the table. This is my table structure.

在提交表单时调用控制器中的Update函数,我注意到它正在更新中桌子。这是我的表格。

The Update function in controller is called while the form is submitted and i noticed that it is being updated in the table.This is my form.

这是我的控制器更新功能。

and this is my controller update function.

public function update($id)
{
    //$type=Input::get('type');
    $event_id= Input::get('eventid');
    $title= Input::get('title');
    $start_day=Input::get('start');
    $end_day=Input::get('end');
    $allday=Input::get('allday');
    $repeat=Input::get('repeat');
    $frequency=Input::get('frequency');
    $start_time=Input::get('start_time');
    $end_time=Input::get('end_time');   
    $dow=Input::get('dow');
    $month=Input::get('month');
    $weekly_json=json_encode($dow);
    $monthly_json=json_encode($month);          
    $newstrt=substr($start_day,0,10);
    $newend=substr($end_day,0,10);
    $start= date("Y-m-d H:i:s",$newstrt);
    $end= date("Y-m-d H:i:s" , $newend);
    $roles = DB::table('events')
                ->where('event_id','=',$event_id)
                ->update(array('title' => $title,'daily'=>$allday,'repeat'=>$repeat,'frequency'=>$frequency,'start'=>$start,'end'=>$end,'time'=>$time,'dow'=>$weekly_json,'monthly_json'=>$monthly_json));

    if (Request::ajax())
    { 

    return Response::json(array('id'=>$event_id,'title'=>$title,'newstrt'=>$start,'newend'=>$end,'start_time'=>$start_time,'end_time'=>$end_time));
    }               
    else 
    {
        return  Redirect::route('calendar.index');
    }
}

但是我无法显示这些细节在完整日历上。我正在关注此链接以在fullcalendar上实现重复活动。
FullCalendar中的重复活动

But I'm not being able to display these details on the full calendar.I was following this link to implement recurring events on fullcalendar. Recurring Events in FullCalendar.

这是我用于从表格中获取详细信息的索引函数。

This is my index function used for GETting details from the table.

public function index()
{
    $event = DB::table('events')

    ->leftJoin('people','people.people_id','=','events.people_id')  
    ->where('events.flag', '=', 1)          
    ->get(array('events.event_id','events.title','events.start','events.end','events.start_time','events.end_time','events.repeat','events.frequency','events.dow'));   
    $id=array(array());
    $temp = array(array());
    $i=0;
    foreach ($event as $events)
        {
            $j=0;
            $id[$i]["event_id"]=$events->event_id;
            $id[$i]["title"]=$events->title;
            $temp[$j]['start']=$events->start;
            $temp[$j]['end'] = $events->end;
            $temp[$j]['start_time']=$events->start_time;
            $temp[$j]['end_time'] = $events->end_time;
            $start_json=json_encode($temp);
            $id[$i]['range'] = $start_json;
            $id[$i]["frequency"]=$events->frequency;
            $id[$i]["repeat"]=$events->repeat;
            $id[$i]["dow"]=$events->dow;

            $i++;           
        }


    return Response::json($id);
}

这是我的日历eventrender功能和事件结构。

This is my calendar eventrender function and events structure.

var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var repeatingEvents = [{
                url: '/v1/calendar/',
                type: 'GET',
        ranges: [{ //repeating events are only displayed if they are within one of the following ranges.
            start: moment().startOf('week'), //next two weeks
            end: moment().endOf('week').add(7,'d'),
        },{
            start: moment('2015-02-01','YYYY-MM-DD'), //all of february
            end: moment('2015-02-01','YYYY-MM-DD').endOf('month'),
        }],
    }];

    console.log(repeatingEvents);

    var getEvents = function( start, end ){
        return repeatingEvents;
    }

    var calendar=$('#calendar');
    $.ajax({
                url: '/v1/calendar/',
                type: 'GET',
                dataType:'json',


                success:function events(response)

                {

                    console.log(response);




    calendar.fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        eventRender: function(event, element, view){
                console.log(event.start.format());
                return (event.range.filter(function(range){
                    return (event.start.isBefore(range.end) &&
                            event.end.isAfter(range.start));
                }).length)>0;
            },
            events: function( start, end, timezone, callback ){
                var events = getEvents(start,end); //this should be a JSON request

                callback(events);
            },
        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar

        drop: function() {
            // is the "remove after drop" checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
            }
        },



        eventSources: [

            {

                url: '/v1/calendar/',
                type: 'GET',
                dataType:'json',



            },
           calendar.fullCalendar( 'addEventSource', response )
        ],

        selectable: true,
        selectHelper: true,
        select: function(start, end, allDay) 

我在控制台上收到这样的JSON响应。

and I am getting JSON response like this on the console.

dow: "{[0,1,2]↵}"
event_id: 1
frequency: "weekly"
range: "[{"start":"2015-09-11","end":"2015-09-12","start_time":"11:00:00","end_time":"15:00:00"}]"
repeat: 1
title: "Youth festival"

I在控制台上没有错误....但事件也没有显示..
我哪里出错了?帮助家伙?

I get no errors on the console....but the events aren't displayed too.. where did i go wrong? Helps guys?

推荐答案

查看此代码,我也面临

在那之后我使用这个想法,它的工作

See this code, i am also facing
After that I use this idea ,its working

在控制器

    $vendor_holiday = Vendor::all();
    return view('vendorpanel/holidays/index', compact('vendor_holiday'));

<script>
var calendar = $('#calendar').fullCalendar({
editable: false,
header: {
  left: 'prev,next today',
    center: 'title',
    right: 'month'
},
events:  [
    @foreach($vendor_holiday as $vendor_holiday)
    {
        title : "",
        start : '{{ $vendor_holiday->start }}',
    },
    @endforeach
],
selectable: true,
selectHelper: true,
select: function (start, end, allDay) {
  $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        var start = moment(start).format('YYYY-MM-DD');
        var end = moment(end).format('YYYY-MM-DD');
        var vendor_id = $("#vendor_id").val();
        var tdate = new Date();
var dd = tdate.getDate(); //yields day
var MM = tdate.getMonth(); //yields month
var yyyy = tdate.getFullYear(); //yields year
var currentDate=  yyyy+ "-" +0+( MM+1) + "-" + dd;
         if(start <= currentDate){
             alert("Mark Holiday at least 1 day before");
             return false;
         }
         if (confirm("Are you sure you want to Add a Holiday?")) {
        $.ajax({
            url: "/vendor/holidays",
            type: "POST",
            data: { vendor_id: vendor_id, start: start, end: end },
            success: function (d) {
                calendar.fullCalendar('refetchEvents');
                alert(d);
                location.reload();
            },
        })
    }
},
eventClick: function (calEvent, jsEvent, view, event) {
  $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
    if (confirm("Are you sure you want to remove it?")) {
        var start = calEvent.start.format();
        var vendor_id = $("#vendor_id").val();
        $.ajax({
            url: '/vendor/holidays/'+vendor_id,
            type: "DELETE",
            data: { _method: 'delete', start: start },
            success: function (d) {
                $('#calendar').fullCalendar('removeEvents', calEvent._id);
                alert(d);
            },
            error: function (data) {
                alert(data);
            }
        });
    }
},
});
</script>

这篇关于使用Laravel在FullCalendar中重复发生的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆