Danny620 Posted January 23, 2014 Share Posted January 23, 2014 (edited) Hi I am wanting to use codeigniter to build a calendar however to populate the calendar you need to provide the day numbers how can i do this with a database design like so id - int (10) check_in - date check_out - date p.s it would need to fill in the dates to between sample data 1, 2014-02-12 , 2014-02-15 2, 2014-02-15 , 2014-02-22 $this->load->library('calendar'); $data = array( 3 => 'http://example.com/news/article/2006/03/', 7 => 'http://example.com/news/article/2006/07/', 13 => 'http://example.com/news/article/2006/13/', 26 => 'http://example.com/news/article/2006/26/' ); echo $this->calendar->generate(2014, 6, $data); http://ellislab.com/codeigniter%20/user-guide/libraries/calendar.html Edited January 23, 2014 by Danny620 Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted January 23, 2014 Share Posted January 23, 2014 It sounds like you are trying to populate multi-day events into your calendar. CodeIgniter provides no way to span multiple days with a single event, so you would need to determine all of the days that include the start date, end date, and all days in between. Once you know those days, you can add them to the array that sets links for the days. So, lets say you have an event from the DB: $events = array( array( 'id' => 234235235, 'start' => '2014-01-02 12:00:00', 'end' => '2014-01-04 12:00:00' ) ); The event here spans three days, the 2nd, 3rd, and 4th. How can you get these dates with PHP? Maybe something like this: $m = 6; $y = 2014; $month_start = mktime( 0,0,0,$m,1,$y); $num_days = date('t',$month_start); foreach( $events as $event ) { $event_start = strtotime($event['start']); $event_end = strtotime($event['end']); for( $x=1; $x<=$num_days; $x++ ) { $day_start = mktime( 0,0,0,$m,$x,$y); $day_end = mktime( 0,0,0,$m,$x,$y); // Does event start on this day? if( $event_start >= $day_start && $event_start <= $day_end ) { $data[$x] = 'http://example.com/news/article/' . $y . '/' . $x . '/' . $m; } // Is day in the middle of start and end of event? else if( $day_start > $event_start && $day_end < $event_end ) { $data[$x] = 'http://example.com/news/article/' . $y . '/' . $x . '/' . $m; } // Does the event end on this day? else if( $event_end >= $day_start && $event_end <= $day_end ) { $data[$x] = 'http://example.com/news/article/' . $y . '/' . $x . '/' . $m; } } } This is untested code, but shows how to know what days the events are on. The CI calendar class does have an extreme limitation in that it assumes that you may only have one event per day. You'll have a lot of work to do, and you'll spend quite a bit of time extending the calendar class if you want to have multiple events per day. I've done this, so I know how painful it is. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted January 24, 2014 Share Posted January 24, 2014 Oops. You should add 86399 to $day_end. Quote Link to comment Share on other sites More sharing options...
Danny620 Posted January 24, 2014 Author Share Posted January 24, 2014 Oops. You should add 86399 to $day_end. First I would like to thank you so much for giving me this code it works a treat expect it does'tn seem to put the start date in on the first day? Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted January 24, 2014 Share Posted January 24, 2014 You probably have to debug the time values as the days are looped through. Use a debug log or debug console; it will make your life a lot easier. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.