sql driver patch - multiday events
Jesse Wolff
jesse_wolff@yahoo.com
Tue, 25 Sep 2001 03:47:13 -0700
Hey all,
Attached is a patch based on the latest cvs that allows you to correctly
displays events that span multiple days when using the sql driver. It should
display correctly in all views - day, week, month and horde summary. There's no
time limit on how long an event can last.
I've tested it with the sql driver but i haven't tested it with mcal to make
sure I didn't break anything. It's coded as to avoid breaking anything when
using mcal but if someone could test it I'd appreciate it.
I've added some comments to explain the changes but feel free to ask if you
don't understand my logic...
Oh, BTW, lots of great fixes recently. When I coded this up last week I found
an annoying bug or two but when I downloaded cvs tonight and made the changes
they were all gone...
Jesse
Index: kronolith/month.php
===================================================================
RCS file: /repository/kronolith/month.php,v
retrieving revision 1.57
diff -r1.57 month.php
78,81c78,116
< $date_array[$event->getStartDate('j')][$id]['title'] = $event-
>getTitle();
< $date_array[$event->getStartDate('j')][$id]['d'] = $event-
>getStartTimestamp();
< $date_array[$event->getStartDate('j')][$id]['id'] = $id;
< $date_array[$event->getStartDate('j')][$id]['alarm'] = $event-
>alarm;
---
> /* Similar logic will need to be added above in the recurrences
> section when recurrences are implemented for the sql driver. */
> if ($GLOBALS['conf']['calendar']['driver'] == 'sql') {
> if ($event->getStartDate('n') < $month ||
> $event->getStartDate('Y') < $year) {
> $eventStartDay = 1;
> } else {
> $eventStartDay = $event->getStartDate('j');
> }
>
> if ($event->getEndDate('n') > $month ||
> $event->getEndDate('Y') > $year) {
> $eventEndDay = $daysInMonth;
> } else {
> /* If the event doesn't end at 12am set the end date to
> the current end date. If it ends at 12am set the end
> date to the previous days end date. */
> if ($event->getEndDate('G') != '0' ||
> $event->getEndDate('i') != '00') {
> $eventEndDay = $event->getEndDate('j');
> } else {
> $eventEndDay = $event->getEndDate('j') - 1;
> }
> }
>
> for ($i = $eventStartDay; $i <= $eventEndDay; $i++) {
> $date_array[$i][$id]['title'] = $event->getTitle();
> $date_array[$i][$id]['d'] = $event->getStartTimestamp();
> $date_array[$i][$id]['id'] = $id;
> $date_array[$i][$id]['alarm'] = $event->alarm;
> }
>
> }
> else {
> $date_array[$event->getStartDate('j')][$id]['title'] = $event-
>getTitle();
> $date_array[$event->getStartDate('j')][$id]['d'] = $event-
>getStartTimestamp();
> $date_array[$event->getStartDate('j')][$id]['id'] = $id;
> $date_array[$event->getStartDate('j')][$id]['alarm'] = $event-
>alarm;
> }
Index: kronolith/lib/api.php
===================================================================
RCS file: /repository/kronolith/lib/api.php,v
retrieving revision 1.14
diff -r1.14 api.php
31c31,33
<
---
>
> $today12am = mktime(0, 0, 0, $day->month, $day->mday, $day->year);
> $tomorrow12am = mktime(0, 0, 0, $day->month, $day->mday + 1, $day-
>year);
34c36,42
< if ($event->startTimestamp < $now) {
---
> /* If it's a recurring event and we're not using the sql driver
> apply the original logic. If we're using the sql driver reset
> the startTimestamp and endTimestamp if necessary to account
> for multiday events. */
> if ($GLOBALS['conf']['calendar']['driver'] != 'sql' &&
> !$event->hasRecurType(KRONOLITH_RECUR_NONE) &&
> $event->startTimestamp < $now) {
36a45,52
> } else if ($GLOBALS['conf']['calendar']['driver'] == 'sql') {
> if ($event->startTimestamp < $today12am) {
> $event->startTimestamp = $today12am;
> }
> if ($event->endTimestamp >= $tomorrow12am) {
> $event->endTimestamp = $tomorrow12am;
> }
>
52,53c68,78
< if ($event->start->hour != 0 || $event->start->min != 0
< || ($event->endTimestamp - $event->startTimestamp) != (24 *
60 * 60)) {
---
> /* The following check to make sure the start time is not 12AM
> was changed to use the getStartDate function to get the
> startTimestamp hour and min instead of using start->hour
> and start->min. When using the sql driver this change
> properly lists a multiday event as 'All day' if it spans the
> entire day. It shouldn't affect the mcal driver since in the
> case of the mcal driver the startTimestamp hour and min are
> the same as start->hour and start->min. */
> if ($event->getStartDate('G') != '0' ||
> $event->getStartDate('i') != '00' ||
> ($event->endTimestamp - $event->startTimestamp) != (24 * 60 *
60)) {
Index: kronolith/lib/DayView.php
===================================================================
RCS file: /repository/kronolith/lib/DayView.php,v
retrieving revision 1.57
diff -r1.57 DayView.php
159,163c159,171
< $start_arr = explode(':', date('G:i', $event->startTimestamp));
< $stop_arr = explode(':', date('G:i', $event->endTimestamp));
< $start_time = mktime($start_arr[0], $start_arr[1], 0, $this->Day-
>month, $this->Day->mday, $this->Day->year);
< $end_time = mktime($stop_arr[0], $stop_arr[1], 0, $this->Day-
>month, $this->Day->mday, $this->Day->year);
<
---
> /* Only reset the start and end day to the current day if we're
> not using the sql driver and this is a recurring event. */
> if ($GLOBALS['conf']['calendar']['driver'] != 'sql' &&
> !$event->hasRecurType(KRONOLITH_RECUR_NONE)) {
> $start_arr = explode(':', date('G:i', $event-
>startTimestamp));
> $stop_arr = explode(':', date('G:i', $event->endTimestamp));
> $start_time = mktime($start_arr[0], $start_arr[1], 0, $this-
>Day->month, $this->Day->mday, $this->Day->year);
> $end_time = mktime($stop_arr[0], $stop_arr[1], 0, $this->Day-
>month, $this->Day->mday, $this->Day->year);
> } else {
> $start_time = $event->startTimestamp;
> $end_time = $event->endTimestamp;
> }
>
Index: kronolith/lib/Driver/sql.php
===================================================================
RCS file: /repository/kronolith/lib/Driver/sql.php,v
retrieving revision 1.15
diff -r1.15 sql.php
113,114c113,120
< ' AND ((e.event_start >= ' . $stime .
< ' AND e.event_end <= ' . $etime . ')' .
---
> /* In order to select all events for the day including multiday
> events the event start should be during the current day or
> before. The event end should be during the current
> day or after. This assumes that the event end is greater
> than the event start which was already verified in
> templates/edit/javascript.inc when the event is saved. */
> ' AND ((e.event_start < ' . $etime .
> ' AND e.event_end > ' . $stime . ')' .
120c126
<
---
>