My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 1708: Split multi-day event into separate events
1 person starred this issue and may be notified of changes. Back to list
Status:  Done
Owner:  ----
Closed:  Aug 2013


Sign in to add a comment
 
Reported by donohuetechnology, Feb 25, 2013
I have a calendar that gets it's events from a mysql database using a php script. It echos the results in json. Everything is working perfectly. The one thing that I would like to do with it I haven't been able to figure out and haven't found anyone else who has asked to do the same thing. I would like to be able to take an event that spans several days and split it into multiple events for each day that it spans. I only want it to be for aesthetics (mainly to make it easier to read when printing) so I'm figuring the best way to do it would be in the mysql query or possibly in jquery. I want to leave the data in my database alone because the same data may be pulled for other calendars where I don't need the same thing. So essentially I want to take a big long event and make it look like multiple smaller events. Any ideas?

Mar 1, 2013
#1 donohuetechnology
I figured this one out on my own. I've posted the code I used below. I was able to do it in php after it pulled the data from the mysql database. Essentially I've got it doing a while loop where it sets the end time to midnight of whatever day it's on in the loop. Then when the dates of the start_date and end_date are the same it uses the actual end_date from the database. You wouldn't want to use this on the actual calendar that people will be editing because it causes all sorts of issues when resizing or moving events. I just needed it for printing so I added a "Printable Version" button to the calendar that will send them to a readonly calendar with this as it's json feed. Then they can print it out and it makes things easier to read. Hopefully this will be useful to someone else out there. If anyone has any suggestions to improve or clean up this code I would love to hear it. I've only been playing around with php for about a month so I'm sure I'm not doing some things in the most efficient way. Cheers!

$result = mysql_query("select * from $dept
where start_date between from_unixtime($start_date) and from_unixtime($end_date)
or end_date between from_unixtime($start_date) and from_unixtime($end_date)
order by start_date");
}


	$event_array = array();
while ($row = mysql_fetch_array($result)) {
	

	if (($dept = 'emergency_room') && ($row['Unassigned_pt'] =='true')) {
		
		$startitup = $row['start_date'];
		
		$endit = $row['end_date'];
		
		while (date('Y-m-d', strtotime($startitup)) < date('Y-m-d', strtotime($endit))) {
		
		
    $event_array[] = array(
		"allDay" => ($row['all_day'] === 'true'),
        'id' => $row['id'],
        'title' => $row['title'],
        'start' => $startitup,
        'end' => date('Y-m-d 00:00:00', strtotime($startitup. ' + 1 days')),
		'color' => 'red',
		'comment' => $row['comment']
    );
	$startitup = date('Y-m-d 00:00:00', strtotime($startitup. ' + 1 days'));
	
		}
		if (date('Y-m-d 00:00:00', strtotime($startitup)) == date('Y-m-d H:i:s', strtotime($row['end_date']))){
			
		}
		else if (date('Y-m-d', strtotime($startitup)) == date('Y-m-d', strtotime($row['end_date']))) {
			$event_array[] = array(
		"allDay" => ($row['all_day'] === 'true'),
        'id' => $row['id'],
        'title' => $row['title'],
        'start' => $startitup,
        'end' => $endit,
		'color' => 'red',
		'comment' => $row['comment']
    );
		}
		
			
		
		
}

else{

        $startitup = $row['start_date'];
		
		$endit = $row['end_date'];
		
		while (date('Y-m-d', strtotime($startitup)) < date('Y-m-d', strtotime($row['end_date']))) {

	
    $event_array[] = array(
		"allDay" => ($row['all_day'] === 'true'),
        'id' => $row['id'],
        'title' => $row['title'],
        'start' => $startitup,
        'end' => date('Y-m-d 00:00:00', strtotime($startitup. ' + 1 days')),
		'comment' => $row['comment']
    );
	$startitup = date('Y-m-d 00:00:00', strtotime($startitup. ' + 1 days'));
		}
		if (date('Y-m-d 00:00:00', strtotime($startitup)) == date('Y-m-d H:i:s', strtotime($row['end_date']))){
			
		}
		else if (date('Y-m-d', strtotime($startitup)) == date('Y-m-d', strtotime($row['end_date']))) {
			$event_array[] = array(
		"allDay" => ($row['all_day'] === 'true'),
        'id' => $row['id'],
        'title' => $row['title'],
        'start' => $startitup,
        'end' => $endit,
		'comment' => $row['comment']
    );
		}
}
}
echo json_encode($event_array);

Aug 24, 2013
Project Member #2 adamrs...@gmail.com
(No comment was entered for this change.)
Status: Done
Sign in to add a comment

Powered by Google Project Hosting