[kronolith] side by side view for Day and Week

Jeroen Huinink j.huinink at wanadoo.nl
Sat Jan 4 20:25:13 PST 2003


Hello Everybody,

This is the side by side implementation for day view and week view. I
have splitted this into two messages, in order not to exceed the
maximum message size of 40k for this mailinglist. 
(I have to suspision that there might be a more approriate list to
submit patches. If so, which would that be?)

This message contains the files related to day. The next message will
contain files related to week. The week files depend on the day files.
If you only install the day files, the week view breaks.

I welcome any suggestions, remarks and comments. 

DayView.diff is the output of cvs diff kronolith\lib\DayView.php
head.inc replaces kronolith\templates\day\head.inc
head_side_by_side should be added to directory kronolith\templates\day

I currently implemented the dayview without additional columns between
the individual calendars and with the calendar names in "header"
style. I am not sure whether this is the preferred solution. Any
ideas?

Regards,
Jeroen

-------------- next part --------------
Index: DayView.php
===================================================================
RCS file: /repository/kronolith/lib/DayView.php,v
retrieving revision 1.114
diff -r1.114 DayView.php
7a8,10
> <<<<<<< DayView.php
>  * $Horde: kronolith/lib/DayView.php,v 1.111 2002/12/19 15:13:17 chuck Exp $
> =======
8a12
> >>>>>>> 1.114
10a15,18
> <<<<<<< DayView.php
>  * @author  Jan Schneider <jan at ammma.de>
>  * @version $Revision: 1.111 $
> =======
12a21
> >>>>>>> 1.114
22c31,34
<     var $_span;
---
>     var $_span = array();
>     var $_totalspan = 0;
>     var $_sidebyside = false;
>     var $_currentCalendars = array();
28a41,52
>         global $prefs;
>         $this->_sidebyside = $prefs->getValue('show_shared_side_by_side') && (count($GLOBALS['display_calendars']) > 1);
>         if ($this->_sidebyside) {
>             $allCalendars = Kronolith::listCalendars();
>             foreach ($GLOBALS['display_calendars'] as $cid) {
>                  $this->_currentCalendars[$cid] = &$allCalendars[$cid];
>                  $this->_all_day_events[$cid] = array();
>             }
>         } else {
>             $this->_currentCalendars = array(0);
>         }
> 
30d53
<             global $prefs;
50a74
>         $include_all_events = !$prefs->getValue('show_shared_side_by_side');
62,65c86,87
<         require $template_path . '/day/head.inc';
< 
<         if (count($this->_all_day_events) > 0) {
<             $rowspan = ' rowspan="' . count($this->_all_day_events) . '"';
---
>         if ($this->_sidebyside) {
>             require $template_path . '/day/head_side_by_side.inc';
67c89
<             $rowspan = '';
---
>             require $template_path . '/day/head.inc';
69c91
< 
---
>         $row = '';
79,89c101,129
< 
<         foreach ($this->_all_day_events as $key => $event) {
<             $categoryColor = isset($colors[$event->getCalendar()][$event->getCategory()]) ? $colors[$event->getCalendar()][$event->getCategory()] : '#ccffcc';
<             $row = '<td class="day-eventbox" style="background-color: ' . $categoryColor . '; ';
<             $row .= 'border: thin solid ' . Kronolith::borderColor($categoryColor) . '" ';
<             $row .= 'onmouseover="javascript:style.backgroundColor=\'' . Horde_Image::modifyColor($categoryColor) . '\'" ';
<             $row .= 'onmouseout="javascript:style.backgroundColor=\'' . $categoryColor . '\'" ';
<             $row .= 'valign="top" colspan="' . $this->_span . '">';
<             $row .= $event->getLink($this->getStamp());
<             $row .= '</td>' . "\n";
< 
---
>     
>         /*
>          * The all day events are not listed in different columns, but in different rows.
>          * In side by side view we do not spread an event over multiple rows if there are
>          * different numbers of all day events for different calendars. 
>          * We just put one event in a single row with no rowspan. 
>          * We put in a rowspan in the row after the last event to fill all remaining rows.
>          * 
>          */
>         $rowspan = ' rowspan="' . $this->_all_day_maxrowspan . '" ';
>         for ($k = 0; $k < $this->_all_day_maxrowspan; $k++) {
>             $row = '';
>             foreach ($this->_currentCalendars as $cid => $cal) {
>                 if (count($this->_all_day_events[$cid]) === $k) {
>                     //There are no events or all events for this calendar have already been printed.
>                     $row .= '<td width="1%" rowspan="' . ($this->_all_day_maxrowspan - $k) . '" colspan="'.  $this->_span[$cid] . '">&nbsp;</td>';
>                 } elseif (count($this->_all_day_events[$cid]) > $k) { 
>                     //We have not printed every all day event yet. Put one into this row.
>                     $event = $this->_all_day_events[$cid][$k];
>                     $categoryColor = isset($colors[$event->getCalendar()][$event->getCategory()]) ? $colors[$event->getCalendar()][$event->getCategory()] : '#ccffcc';
>                     $row .=  '<td class="day-eventbox" style="background-color: ' . $categoryColor . '; ';
>                     $row .= 'border: thin solid  ' . Kronolith::borderColor($categoryColor) . '" ';
>                     $row .= 'onmouseover="javascript:style.backgroundColor=\'' . Horde_Image::modifyColor($categoryColor) . '\'" ';
>                     $row .= 'onmouseout="javascript:style.backgroundColor=\'' . $categoryColor . '\'" ';
>                     $row .= 'valign="top" colspan="' . $this->_span[$cid] . '">';
>                     $row .= $event->getLink($this->getStamp());
>                     $row .= '</td>';
>                 } 
>             }
94c134
<             $row = '<td colspan="' . $this->_span . '">&nbsp;</td>';
---
>             $row .= '<td colspan="' . $this->_totalspan. '">&nbsp;</td>';
96a137
> 
102,104c143
<             if (!$started
<                 && $i < $prefs->getValue('day_hour_start')
<                 && !count($this->_event_matrix[$i])) {
---
>             if ($i < $this->first && $i < $prefs->getValue('day_hour_start')) {
107,109c146,147
< 
<             $started = true;
<             $row = '';
---
>             
>             $row = ''; 
113,133c151,176
< 
<             foreach ($this->_event_matrix[$i] as $key) {
<                 $event = $this->_events[$key];
<                 $start = mktime(floor($i/2), ($i % 2) * 30, 0, $this->month, $this->mday, $this->year);
< 
<                 // Since we've made sure that this event's overlap is
<                 // a factor of the total span, we get this event's
<                 // individual span by dividing the total span by this
<                 // event's overlap.
<                 $span = $this->_span / $event->overlap;
<                 $hspan += $span;
< 
<                 $categoryColor = isset($colors[$event->getCalendar()][$event->getCategory()]) ? $colors[$event->getCalendar()][$event->getCategory()] : '#ccccff';
<                 if ($event->startTimestamp >= $start && $event->startTimestamp < $start + 60 * 30 || $start == $this->getStamp()) {
<                     $row .= '<td class="day-eventbox" style="background-color: ' . $categoryColor . '; ';
<                     $row .= 'border: thin solid ' . Kronolith::borderColor($categoryColor) . '" ';
<                     $row .= 'onmouseover="javascript:style.backgroundColor=\'' . Horde_Image::modifyColor($categoryColor) . '\'" ';
<                     $row .= 'onmouseout="javascript:style.backgroundColor=\'' . $categoryColor . '\'" ';
<                     $row .= 'valign="top" width="' . round(100 * ($span / $this->_span)) . '%" colspan="' . $span . '" rowspan="' . $event->rowspan . '">';
<                     $row .= $event->getLink($this->getStamp());
<                     $row .= '&nbsp;</td>' . "\n";
---
>     
>             foreach ($this->_currentCalendars as $cid => $cal) {
>                 foreach ($this->_event_matrix[$cid][$i] as $key) {
>                     $event = $this->_events[$key];
>                     if ($include_all_events || $event->getCalendar() == $cid) {
>                         $start = mktime(floor($i/2), ($i % 2) * 30, 0, $this->month, $this->mday, $this->year);
>         
>                         // Since we've made sure that this event's overlap is
>                         // a factor of the total span, we get this event's
>                         // individual span by dividing the total span by this
>                         // event's overlap.
>                         $span = $this->_span[$cid] / $event->overlap;
>                         $hspan += $span;
>         
>                         $categoryColor = isset($colors[$event->getCalendar()][$event->getCategory()]) ? $colors[$event->getCalendar()][$event->getCategory()] : '#ccccff';
>                         if ($event->startTimestamp >= $start && $event->startTimestamp < $start + 60 * 30 || $start == $this->getStamp()) {
>                             $row .= '<td class="day-eventbox" style="background-color: ' . $categoryColor . '; ';
>                             $row .= 'border: thin solid ' . Kronolith::borderColor($categoryColor) . '" ';
>                             $row .= 'onmouseover="javascript:style.backgroundColor=\'' . Horde_Image::modifyColor($categoryColor) . '\'" ';
>                             $row .= 'onmouseout="javascript:style.backgroundColor=\'' . $categoryColor . '\'" ';
>                             $row .= 'width="' . round((90/count($this->_currentCalendars)) * ($span / $this->_span[$cid]))  . '%" ';
>                             $row .= 'valign="top" colspan="' . $span . '" rowspan="' . $event->rowspan . '">';
>                             $row .= $event->getLink($this->getStamp());
>                             $row .= '&nbsp;</td>';
>                         }
>                     } 
135,140c178,183
<             }
< 
<             $diff = $this->_span - $hspan;
<             if ($diff > 0) {
<                 for ($t = 0; $t < $diff; $t ++) {
<                     $row .= '<td width="' . round(100 * (1 / $this->_span)) . '%" colspan="1" class="' . $style . '">&nbsp;</td>' . "\n";
---
>     
>                 $diff = $this->_span[$cid] - $hspan;
>                 if ($diff > 0) {
>                     for ($t = 0; $t < $diff; $t ++) {
>                         $row .= '<td colspan="1" class="' . $style . '">&nbsp;</td>';
>                     }
180a224,227
>         $tmp = array();
>         global $prefs;
>         $include_all_events = !$prefs->getValue('show_shared_side_by_side');
>         $this->_all_day_maxrowspan = 0;
183c230,234
<         $tmp = array();
---
>         foreach ($this->_currentCalendars as $cid => $cal) {
>             $this->_all_day_events[$cid] = array();
>             $this->_all_day_rowspan[$cid] = 0;
>         }
> 
184a236,243
>             // if we have side_by_side we only want to include the 
>             // event in the proper calendar.
>             if (!$include_all_events) {
>                 $cid = $event->getCalendar();
>             } else {
>                 $cid = 0;
>             }
> 
187c246,250
<                 $this->_all_day_events[] = $event;
---
>                 $this->_all_day_events[$cid][] = $event;
>                 $this->_all_day_rowspan[$cid]++;
>                 if ($this->_all_day_maxrowspan < $this->_all_day_rowspan[$cid]) {
>                     $this->_all_day_maxrowspan = $this->_all_day_rowspan[$cid];
>                 }
192c255
< 
---
>     
195c258
< 
---
>     
214a278
>         $this->first = 48;
220c284,286
<             $this->_event_matrix[$i] = array();
---
>             foreach ($this->_currentCalendars as $cid => $cal) {
>                 $this->_event_matrix[$cid][$i] = array();
>             }
227a294,301
>                 // if we have side_by_side we only want to include the 
>                 // event in the proper calendar.
>                 if (!$include_all_events) {
>                     $cid = $event->getCalendar();
>                 } else {
>                     $cid = 0;
>                 }
>  
233c307
< 
---
>   
239c313,319
< 
---
>    
>                     // Make sure we keep the first hour than an event
>                     // reaches up-to-date.
>                     if ($i < $this->first) {
>                         $this->first = $i;
>                     }
>    
242,243c322,323
<                     $this->_event_matrix[$i][] = $key;
< 
---
>                     $this->_event_matrix[$cid][$i][] = $key;
>     
249,267c329,335
<             // Update the number of events that events in this row
<             // overlap with.
<             foreach ($this->_event_matrix[$i] as $ev) {
<                 $this->_events[$ev]->overlap = max($this->_events[$ev]->overlap,
<                                                    count($this->_event_matrix[$i]));
<             }
< 
<             // Update the set of rowspans to include the value for
<             // this row.
<             $spans[count($this->_event_matrix[$i])] = true;
<         }
< 
<         // Sort every row by event duration, so that longer events are
<         // farther to the left.
<         for ($i = 0; $i <= $this->last; $i++) {
<             if (count($this->_event_matrix[$i])) {
<                 usort($this->_event_matrix[$i], array($this, '_sortByDuration'));
<             }
<         }
---
>             foreach ($this->_currentCalendars as $cid => $cal) { 
>                 // Update the number of events that events in this row
>                 // overlap with.
>                 foreach ($this->_event_matrix[$cid][$i] as $ev) {
>                     $this->_events[$ev]->overlap = max($this->_events[$ev]->overlap,
>                                                     count($this->_event_matrix[$cid][$i]));
>                 }
269,284c337,339
<         // Now that we have the number of events in each row, we can
<         // calculate the total span needed.
<         $span = 1;
< 
<         // Turn keys into array values.
<         $spans = array_keys($spans);
< 
<         // Start with the biggest one first.
<         rsort($spans);
<         foreach ($spans as $s) {
<             // If the number of events in this row doesn't divide
<             // cleanly into the current total span, we need to
<             // multiply the total span by the number of events in this
<             // row.
<             if ($span % $s != 0) {
<                 $span *= $s;
---
>                 // Update the set of rowspans to include the value for
>                 // this row.
>                 $spans[$cid][count($this->_event_matrix[$cid][$i])] = true;
287a343,371
>         foreach ($this->_currentCalendars as $cid => $cal) {
>             // Sort every row by event duration, so that longer events are
>             // farther to the left.
>             for ($i = 0; $i <= $this->last; $i++) {
>                 if (count($this->_event_matrix[$cid][$i])) {
>                     usort($this->_event_matrix[$cid][$i], array($this, '_sortByDuration'));
>                 }
>             }
>     
>             // Now that we have the number of events in each row, we can
>             // calculate the total span needed.
>  
>             $span[$cid] = 1;
>             // Turn keys into array values.
>             $spans[$cid] = array_keys($spans[$cid]);
>     
>             // Start with the biggest one first.
>             rsort($spans[$cid]);
>             foreach ($spans[$cid] as $s) {
>                 // If the number of events in this row doesn't divide
>                 // cleanly into the current total span, we need to
>                 // multiply the total span by the number of events in this
>                 // row.
>                 if ($span[$cid] % $s != 0) {
>                     $span[$cid] *= $s;
>                 }
>             }
>             $this->_totalspan += $span[$cid];
>         } 
290c374
< 
---
>    
-------------- next part --------------
<table border="0" cellspacing="0" cellpadding="1" width="100%" class="item0">
  <tr>
    <td class="header" colspan="<?php echo ($this->_totalspan + 3) ?>" align="center">
      <?php echo (!$print_view) ? Horde::link($this->link(-1), _("Previous day"), 'smallheader') . Horde::img('prev.gif', '&lt;', 'hspace="2"') . '</a>' : ''?>
      <b><?php echo $this->getTime($prefs->getValue('date_format')) ?></b>
      <?php echo (!$print_view) ? Horde::link($this->link(1), _("Next day"), 'smallheader') . Horde::img('next.gif', '&gt;', 'hspace="2"') . '</a>' : ''?>
    </td>
  </tr>
  <tr>
    <td width="1%" class="header" colspan="3" align="center">
<?php $i = 0; foreach ($this->_currentCalendars as $cid => $cal): ?>
    <td width="<?php echo round(90/count($this->_currentCalendars)); ?>%" class="header" align="center" colspan="<?php echo $this->_span[$cid]; ?>">
      <?php echo $cal->getShareName(); ?>
    </td>
<?php endforeach; ?>
  </tr>
-------------- next part --------------
<table border="0" cellspacing="0" cellpadding="1" width="100%" class="item0">
  <tr>
    <td class="header" colspan="<?php echo ($this->_totalspan + 3) ?>" align="center">
      <?php echo (!$print_view) ? Horde::link($this->link(-1), _("Previous day"), 'smallheader') . Horde::img('prev.gif', '&lt;', 'hspace="2"') . '</a>' : ''?>
      <b><?php echo $this->getTime($prefs->getValue('date_format')) ?></b>
      <?php echo (!$print_view) ? Horde::link($this->link(1), _("Next day"), 'smallheader') . Horde::img('next.gif', '&gt;', 'hspace="2"') . '</a>' : ''?>
    </td>
  </tr>
  


More information about the kronolith mailing list