Re: Package-proposal: HTML_Calendar
| From: | Harry Fuecks | Date: | Sat, 09 Aug 2003 14:08:06 +0000 |
| Subject: | Re: Package-proposal: HTML_Calendar | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-19431@lists.php.net to get a copy of this message | ||
At some point soon will submit a collection of classes I've got for building calendar data structures (i.e. absolutely no output is generated). This would be for the Date namespace.
**Using** it to build some HTML looks something like this;
<?php
// Initialize GET variables
if (!isset($_GET['y'])) $_GET['y'] = date('Y');
if (!isset($_GET['m'])) $_GET['m'] = date('m');
if (!isset($_GET['d'])) $_GET['d'] = date('d');
// Build Month (data structure
$month = new Month($_GET['y'],$_GET['m']);
// Define selected days
$selectedDays = array (
new Day($_GET['y'],$_GET['m'],$_GET['d']),
new Day($_GET['y'],12,25), /* Christmas day! */
);
// Build the days in the month passing selected days
$month->buildWeekDays($selectedDays);
?>
<table class="calendar">
<?php
while ( $day = $month->fetch() ) {
// Passing true to thisDay() returns a timestamp
$dayStamp = $day->thisDay(true);
$link = $_SERVER['PHP_SELF'].'?y='.date('Y',$dayStamp).
'&m='.date('m',$dayStamp).'&d='.date('d',$dayStamp);
// isFirst() to find start of a week
if ( $day->isFirst() )
echo ( "<tr>\n" );// Is the day selected? if ( $day->isSelected() ) {
echo ( "<td class=\"selected\">".$day->thisDay()."</td>\n" );// "Empty" days are used as place holders for building the table } else if ( $day->isEmpty() ) {
echo ( "<td> </td>\n" );} else {
// Here thisDay() simple returns a number for the day of the week
echo ( "<td><a href=\"".$link."\">".$day->thisDay()."</a></td>\n" ) ;
}
// isLast() to find end of a week
if ( $day->isLast() )
echo ( "</tr>\n" );} ?> </table> By treating calendars purely as data structures, it's possible to build any output you like from them (e.g. WML). Stefan, if you're prepared to wait a couple of weeks (the code isn't in PEAR format right now) I'll submit it then HTML_Calendar could become a class which "sits on top" for building output. Drop me a line on hfuecks@phppatterns.com if you don't hear anything. As Mattias says, it's very important to seperate the logic from the output. On Sat, 09 Aug 2003 15:48:16 +0200, Matthias Nothhaft <matthias.nothhaft@gmx.de> wrote:
Stefan Neufeind wrote:I guess everybody knows what it should be useful for :-) Draw a monthly calendar, displaying the days / weeks / weekdays. Proposed features: - possibility to give links for every day so dates can be linked to other pages - possibility to give onMouseOver-text for for every day so text can be displayed inside DHTML-boxes - variable start of week (Sunday / Monday) - links to next / previous month - maybe also direct month-/year- selection via dropdown-box if package-users wish - ... I think this might be a quite useful class that could be used in various occassions without "reinventing the wheel" everytime. We missed such a package in pear currently. Please comment Stefan Neufeind **************************************************** SpeedPartner, Inh. Michael Metz Neukirchener Str. 57, 41470 Neuss, Germany Tel.: +49-2137 / 929 829, Fax: +49-2137 / 137 17 E-Mail: info@speedpartner.de ****************************************************I think this is a good idea, would be very nice if we could customize all... Please try separating logic from output. A generic package would be a good solution: Some people need it with integrated (d)html output and others (me) need a "raw data set" to build a template (I'm using Smarty) You could use a factory and some drivers for different outputs - or do you think this is overkill? Regards, Matthias