Re: [Php-calendar-discussion] Fix for adding weekend only and weekday only events
Brought to you by:
sproctor
From: Sean P. <spr...@gm...> - 2006-09-13 03:05:44
|
Sorry for the delay. I'm not spending too much time working on the calendar, and I've redone the way events are stored for the next version so you can add specialty things like this without changing the database, or the code to retrieve them. Anyway, this might work fine, but you're offloading work to SQL that doesn't belong there. Your statement is going to turn out like: ...OR (eventtype = 7 AND ('Sat' != 'Sat' AND 'Sat' != 'Sun')) OR (eventtype = 8 AND ('Sat' = 'Sat' OR 'Sat' = 'Sun')... that does what you want, but it would be simpler to say: // find weekday/weekend events .(($dayofweek != 'Sat' && $dayofweek != 'Sun') ? "OR eventtype = 7" : "OR eventtype = 8"). // in the current calendar etc I haven't actually tested that, but it should work. Other than that little thing, nice job on the feature. I'm not going to merge it in, because the next version will have a similar capability (if I ever finish it), and I think it's too specific for the current version. I think the interface for adding events right now is awful. I don't want to make it any more confusing. Thanks, Sean On 6/5/06, Steve <the...@gm...> wrote: > > Hi. > I downloaded PHP Calendar for a way for my business partner and I to > communicate dates between eachother, but after playing with it for a > few minutes, I realized there wasnt a feature for weekend only and > weekday only events, and the TODO list requested it. So I added to it > after spending a good half hour navigating the code. > > This is my first code contrubution to any open source community, and > it was a real quick fix. > > I modified two files. The first was globals.php starting on line 73. > The definition for $event_types should read as follows: > > $event_types = array( > 1 => _('Normal'), > _('Full Day'), > _('To Be Announced'), > _('No Time'), > _('Weekly'), > _('Monthly'), > _('Weekdays'), > _('Weekends') > ); > > > The second file is calendar.php starting on line 264. The definition > for function get_events_by_date() should read as follows: > > function get_events_by_date($day, $month, $year) > { > global $calendar_name, $db; > > /* event types: > 1 - Normal event > 2 - full day event > 3 - unknown time event > 4 - reserved > 5 - weekly event > 6 - monthly event > 7 - weeday only > 8 - weekend only > */ > $startdate = $db->SQLDate('Y-m-d', 'startdate'); > $enddate = $db->SQLDate('Y-m-d', 'enddate'); > $date = "DATE '" . date('Y-m-d', mktime(0, 0, 0, $month, $day, > $year)) > . "'"; > $dayofweek = date("D", mktime(0, 0, 0, $month, $day, $year)); > // day of week > $dow_startdate = $db->SQLDate('w', 'startdate'); > $dow_date = $db->SQLDate('w', $date); > // day of month > $dom_startdate = $db->SQLDate('d', 'startdate'); > $dom_date = $db->SQLDate('d', $date); > > $query = 'SELECT * FROM '.SQL_PREFIX."events\n" > ."WHERE $date >= $startdate AND $date <= $enddate\n" > // find normal events > ."AND (eventtype = 1 OR eventtype = 2 OR eventtype = 3 " > ."OR eventtype = 4\n" > // find weekly events > ."OR (eventtype = 5 AND $dow_startdate = $dow_date)\n" > // find monthly events > ."OR (eventtype = 6 AND $dom_startdate = $dom_date)\n" > // find weeday events > ."OR (eventtype = 7 AND ('$dayofweek' != 'Sat' AND '$dayofweek' != > 'Sun'))\n" > // find weekend events > ."OR (eventtype = 8 AND ('$dayofweek' = 'Sat' OR > '$dayofweek' = 'Sun'))\n" > .")\n" > // in the current calendar > ."AND calendar = '$calendar_name'\n" > ."ORDER BY starttime"; > > $result = $db->Execute($query) > or db_error(_('Error in get_events_by_date'), $query); > > return $result; > } > > I hope this helps or, if I forgot something, someone can point out a bug > or two. > > Thanks, > > Steve Massey > > > _______________________________________________ > Php-calendar-discussion mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/php-calendar-discussion > |