[dev] Patch for kronolith legends

Jason Rust jrust at rustyparts.com
Mon May 12 16:40:08 PDT 2003


Attached is a patch that implements a category legend for the different
calendars displayed.  This allows the user to know what a color for a
category means when viewing the month/day/week view (idea was taken from
the imp legend)

I also found that there is no way for a user to have more than 1 legend
even if the user has created 2 different calendars.  I'm thinking that
the category editor in kronolith should dynamically load a different
legend when the calendar is changed (via a select box).  The
functionality would be similar to the calendar editor.  Does this sound
like the correct way to go about implementing this functionality?

-Jason
-------------- next part --------------
Index: lib/Kronolith.php
===================================================================
RCS file: /repository/kronolith/lib/Kronolith.php,v
retrieving revision 1.136
diff -u -r1.136 Kronolith.php
--- lib/Kronolith.php	20 Apr 2003 16:19:21 -0000	1.136
+++ lib/Kronolith.php	12 May 2003 23:26:31 -0000
@@ -852,6 +852,41 @@
     }
 
     /**
+     * Builds the category legend for the displayed calendars 
+     *
+     * @return string The html table for the legend
+     */
+    function buildCategoryLegend()
+    {
+        if (count($GLOBALS['display_calendars']) == 0) {
+            return '';
+        }
+
+        $colors = Kronolith::categoryColors();
+        $html = '<tr><td class="header">';
+        $html .= '<table border="0" cellpadding="0" cellspacing="4">';
+        foreach (Kronolith::listCalendars() as $id => $cal) {
+            if (in_array($id, $GLOBALS['display_calendars'])) {
+                $categories = Kronolith::listCategories($id);
+                $html .= '<tr><td>' . $cal->getShareName() . ':</td>';
+                foreach ($categories as $catKey => $catName) {
+                    $categoryColor = isset($colors[$id][$catKey]) ? $colors[$id][$catKey] : '#ccccff';
+                    $html .= '<td class="month-eventbox" width="15" style="background-color: ' . $categoryColor . '; ';
+                    $html .= 'border-color: ' . Kronolith::borderColor($categoryColor) . '">';
+                    $html .= '&nbsp;</td>';
+                    $html .= '<td style="width: 60;">' . $catName . '</td>' . "\n";
+
+                }
+                $html .= '</tr>' . "\n";
+            }
+        }
+        $html .= '</table></td></tr>' . "\n";
+        return $html;
+    }
+
+    /**
      * List all calendars a user has access to.
      *
      * @param optional boolean $owneronly  Only return calenders that this
 
Index: templates/day/foot.inc
===================================================================
RCS file: /repository/kronolith/templates/day/foot.inc,v
retrieving revision 1.1
diff -u -r1.1 foot.inc
--- templates/day/foot.inc	11 Aug 2000 22:18:08 -0000	1.1
+++ templates/day/foot.inc	12 May 2003 23:26:31 -0000
@@ -1 +1,7 @@
 </table>
+<?php
+// Start a new table because rowspans mess up cell otherwise
+echo '<table border="0" cellspacing="0" cellpadding="1" width="100%">';
+echo Kronolith::buildCategoryLegend();
+echo '</table>';
+?>
Index: month.php
===================================================================
RCS file: /repository/kronolith/month.php,v
retrieving revision 1.113
diff -u -r1.113 month.php
--- month.php	3 Jan 2003 02:17:40 -0000	1.113
+++ month.php	12 May 2003 23:26:31 -0000
@@ -163,10 +163,9 @@
         $dayofweek++;
     }
 }
-?>
 
-</tr></table>
-</td></tr></table>
-
-<?php
+echo '</tr></table>
+</td></tr>';
+echo Kronolith::buildCategoryLegend();
+echo '</table>';
 require KRONOLITH_TEMPLATES . '/common-footer.inc';


More information about the dev mailing list