Recurring Events in FullCalendar

后端 未结 8 1042
独厮守ぢ
独厮守ぢ 2020-11-22 09:49

I am using jQuery FullCalendar as my calendar used in my website for availability agenda.

Is there any functions/methods/options in fullcalendar that handles my recu

相关标签:
8条回答
  • 2020-11-22 10:44

    There is now a plugin that will do what you want: http://momentjs.com/docs/#/plugins/recur/

    0 讨论(0)
  • 2020-11-22 10:45

    No need to make parent and child relationship here is the code that provide simple solution for recurring events in jquery Full calender use these below functions in your php file that you use further to call all your events.

    function render_fccalendar_events() {
            $_POST['start'] = strtotime('2013-05-01');
            $_POST['end'] = strtotime('2013-05-31');
            $start = date('Y-m-d',$_POST['start']);
            $end = date('Y-m-d', $_POST['end']);
            $readonly = (isset($_POST['readonly'])) ? true : false;    
            $events = fcdb_query_events($start, $end);       
            render_json(process_events($events, $start, $end, $readonly));
    }
    
    function process_events($events, $start, $end, $readonly) {
        if ($events) {
            $output = array();
            foreach ($events as $event) {
                $event->view_start = $start;
                $event->view_end = $end;
                $event = process_event($event, $readonly, true);
                if (is_array($event)) {
                    foreach ($event as $repeat) {
                        array_push($output, $repeat);
                    }
                } else {
                    array_push($output, $event);
                }
            }
            return $output;
        }
    }
    
    function process_event($input, $readonly = false, $queue = false) {
        $output = array();
        if ($repeats = generate_repeating_event($input)) {
            foreach ($repeats as $repeat) {
                array_push($output, generate_event($repeat));
            }
        } else {
            array_push($output, generate_event($input));
        }
    
        if ($queue) {
            return $output;
        }
        render_json($output);
    }
    
    
    function generate_event($input) {
        $output = array(
            'id' => $input->id,
            'title' => $input->name,
            'start' => $input->start_date,
            'end' => $input->end_date,
            'allDay' => ($input->allDay) ? true : false,
            //'className' => "cat{$repeats}",
            'editable' => true,
            'repeat_i' => $input->repeat_int,
            'repeat_f' => $input->repeat_freq,
            'repeat_e' => $input->repeat_end
        );
        return $output;
    }
    
    
    
    function generate_repeating_event($event) {
    
        $repeat_desk = json_decode($event->repeat_desk);
        if ($event->repeat == "daily") {
            $event->repeat_int =0;
            $event->repeat_freq = $repeat_desk->every_day;
        }
        if ($event->repeat == "monthly") {
            $event->repeat_int =2;        
            $event->repeat_freq = $repeat_desk->every_month;
        }
        if ($event->repeat == "weekly") {
            $event->repeat_int =1;                
           $event->repeat_freq = $repeat_desk->every_weak;
        }
        if ($event->repeat == "year") {
            $event->repeat_int =3;                        
            $event->repeat_freq = $repeat_desk->every_year;
        }
    
        if ($event->occurrence == "after-no-of-occurrences") {
            if($event->repeat_int == 0){
                $ext = "days";
            }
            if($event->repeat_int == 1){
                $ext = "weeks";
            }
            if($event->repeat_int == 2){
                $ext = "months";
            }
            if($event->repeat_int == 3){
                $ext = "years";
            }
           $event->repeat_end =  date('Y-m-d',strtotime("+" . $event->repeat_int . " ".$ext));
        } else if ($event->occurrence == "no-end-date") {
            $event->repeat_end = "2023-04-13";
        } else if ($event->occurrence == "end-by-end-date") {
            $event->repeat_end = $event->end_date;
        }
    
    
    
        if ($event->repeat_freq) {
    
            $event_start = strtotime($event->start_date);
            $event_end = strtotime($event->end_date);
            $repeat_end = strtotime($event->repeat_end) + 86400;
            $view_start = strtotime($event->view_start);
            $view_end = strtotime($event->view_end);
            $repeats = array();
    
            while ($event_start < $repeat_end) {
                if ($event_start >= $view_start && $event_start <= $view_end) {
                    $event = clone $event; // clone event details and override dates
                    $event->start_date = date(AEC_DB_DATETIME_FORMAT, $event_start);
                    $event->end_date = date(AEC_DB_DATETIME_FORMAT, $event_end);
                    array_push($repeats, $event);
                }
                $event_start = get_next_date($event_start, $event->repeat_freq, $event->repeat_int);
                $event_end = get_next_date($event_end, $event->repeat_freq, $event->repeat_int);
            }
            return $repeats;
        }
        return false;
     }
    
    function get_next_date($date, $freq, $int) {
        if ($int == 0)
            return strtotime("+" . $freq . " days", $date);
        if ($int == 1)
            return strtotime("+" . $freq . " weeks", $date);
        if ($int == 2)
            return get_next_month($date, $freq);
        if ($int == 3)
            return get_next_year($date, $freq);
    }
    
    function get_next_month($date, $n = 1) {
        $newDate = strtotime("+{$n} months", $date);
        // adjustment for events that repeat on the 29th, 30th and 31st of a month
        if (date('j', $date) !== (date('j', $newDate))) {
            $newDate = strtotime("+" . $n + 1 . " months", $date);
        }
        return $newDate;
    }
    
    function get_next_year($date, $n = 1) {
        $newDate = strtotime("+{$n} years", $date);
        // adjustment for events that repeat on february 29th
        if (date('j', $date) !== (date('j', $newDate))) {
            $newDate = strtotime("+" . $n + 3 . " years", $date);
        }
        return $newDate;
    }
    
    function render_json($output) {
        header("Content-Type: application/json");
        echo json_encode(cleanse_output($output));
        exit;
    }
    
    
    function cleanse_output($output) {
        if (is_array($output)) {
            array_walk_recursive($output, create_function('&$val', '$val = trim(stripslashes($val));'));
        } else {
            $output = stripslashes($output);
        }
        return $output;
    }
    
    function fcdb_query_events($start, $end) {
        global $wpdb;
        $limit = ($limit) ? " LIMIT {$limit}" : "";
        $result = $wpdb->get_results("SELECT id, name,start_date,end_date,repeat_desk,`repeat`,occurrence,occurrence_desk
    
                                            FROM " . 
    
    $wpdb->prefix . "lgc_events
                                            WHERE (
                                            (start_date >= '{$start}' AND start_date < '{$end}')
                                            OR (end_date >= '{$start}' AND end_date < '{$end}')
                                            OR (start_date <= '{$start}' AND end_date >= '{$end}')
                                            OR (start_date < '{$end}' AND (`repeat`!= ''))
    
    
                                )
                                            ORDER BY start_date{$limit};");
    
        return return_result($result);
    }
    
    
    function return_result($result) {
        if ($result === false) {
            global $wpdb;
            $this->log($wpdb->print_error());
            return false;
        }
        return $result;
    }
    

    in the above code i used repeat_desk in which i store json code for repeat frequencyenter image description here

    and jquery to call your file

     events:  {
                    url: '<?php echo $lgc_plugindir; ?>includes/imagerotator.php',
                    data: {
                        action: 'get_events'
                    },
                    type: 'POST'
                }
    

    i used this for wordpress you can use this code as per your requirement

    0 讨论(0)
提交回复
热议问题