hellomoto Posted October 19, 2015 Share Posted October 19, 2015 I am trying to build on lindquist's Calendar module just to get a working demo of some additional features I would eventually like to somehow implement in a more solid way, such as overriding the default info for a recurring event for some instances. Here is my events template: <?php $scriptsHead[] = $config->urls->templates."js/moment.min.js"; $scriptsHead[] = $config->urls->templates."js/fullcalendar.min.js"; $styles[] = $config->urls->templates."css/fullcalendar.min.css"; $content .= '<div id="calendar" style="width:100%"></div>'; $calendar = wire('modules')->getModule('Calendar'); // get current/upcoming events -1:+6 months $start = new DateTime(); $until = new DateTime(); $start->sub(new DateInterval('P1M')); $until->add(new DateInterval('P6M')); $events = $calendar->expandEvents($start, $until); //$start = strtotime($start); $start = $start->format('Y-m-d H:i'); $until = $until->format('Y-m-d H:i'); function eventsToJSON($events, $start, $until) { $items = array(); $ids = array(); $idx = 0; foreach($events as $event) { $pages = wire('pages'); $eid = $pages->get($event->event->id); $allday = (bool)$eid->calendar_event_allday; $recurs = (bool)$eid->calendar_event_recurs; if($eid->children("calendar_event_start={$start}")) { $start = wireDate($event->start->format('Y-m-d H:i')); if($eid->children("calendar_event_start={$start}")) { $subevent = $eid->children("calendar_event_start={$start}"); //echo "same same {$subevent->id} {$subevent->title} {$eid->title}"; } } // translate events from some source to a format recognizable by fullCalendar $addItem = array( 'id' => $event->event->id, 'title' => $event->event->title, 'allDay' => $allday, 'start' => wireDate($event->start->format('Y-m-d H:i')),//calendar_event_start), 'end' => wireDate($event->end->format('Y-m-d H:i')), //'url' => "./$event[id]", // event ID is the url segment 'url' => $event->event->url, ); $items[] = $addItem; //$n = 0; $c = 0; if($eid->hasChildren() && !in_array($eid->id, $ids)) { foreach($eid->children() as $i) { $items[] = array( 'id' => $i->id, 'title' => "{$i->parent->title}: {$i->title}", 'start' => wireDate('Y-m-d', $i->calendar_event_start), 'url' => $i->url, ); $items[$idx]['title'] = "{$i->parent->title}: {$i->title}"; } //echo $n . ' ' . $c; } $ids[] = $eid->id; //$n++; $c++; /* if($event->calendar_event_recurs == true) { echo $event->calendar_event_rrule; }*/ } //print_r($items); //$idx++; return json_encode($items); } $eventsJson = eventsToJSON($events, $start, $until); //echo '<br><br>'.$eventsJson; $content .= <<<EOT <script> $(document).ready(function() { /* date store today date. d store today date. m store current month. y store current year. */ var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); /* Initialize fullCalendar and store into variable. Why in variable? Because doing so we can use it inside other function. In order to modify its option later. */ var calendar = $('#calendar').fullCalendar( { /* header option will define our calendar header. left define what will be at left position in calendar center define what will be at center position in calendar right define what will be at right position in calendar */ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, /* defaultView option used to define which view to show by default, for example we have used agendaWeek. */ defaultView: 'month', /* selectable:true will enable user to select datetime slot selectHelper will add helpers for selectable. */ selectable: true, selectHelper: true, /* when user select timeslot this option code will execute. It has three arguments. Start,end and allDay. Start means starting time of event. End means ending time of event. allDay means if events is for entire day or not. */ select: function(start, end, allDay) { /* after selection user will be promted for enter title for event. */ var title = prompt('Event Title:'); /* if title is enterd calendar will add title and event into fullCalendar. */ if (title) { calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay }, false // make the event "stick" ); } calendar.fullCalendar('unselect'); }, /* editable: true allow user to edit events. */ editable: false, /* events is the main option for calendar. for demo we have added predefined events in json object. */ events: {$eventsJson} }); }); </script> EOT; The calendar-event template is generated by the module; I added a child template, calendar-event_instance. So the above outputs the calendar and its events, but any recurring event instance with info input appears twice: regular, e.g., 6p Game Night, and preceded with an all-day event, Game Night: Monopoly. What I want is to replace the event recurrence's title and URL with the one for that instance when one exists. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now