Re: Call for Votes: PEAR::Calendar
| From: | hfuecks at phppatterns dot com | Date: | Fri, 24 Oct 2003 10:23:00 +0000 |
| Subject: | Re: Call for Votes: PEAR::Calendar | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-22958@lists.php.net to get a copy of this message | ||
[Whoops - Greg I sent this to you directly but missed that you'd sent this
to the list so sending it again]
> Harry,
>
> Nice examples, good looking code. I have run into a problem testing the
package that isn't your fault :). Namely, the web installer will not
allow one to install packages that aren't available through
> pear.php.net. I want to test the package on my provider, as their
system is slower than mine (I get 0.3 seconds build time on the
calendar).
OK - guess that means manually placing the files in the correct location
(if/until PEAR::Calendar is accepted). If you unzip the download, place
all the files in the root of the zip under;
<PEAR_ROOT>/Calendar
Then you'll need to place the file Calendar_Engine_UnixTs (also
Calendar_Engine_Interface but this file is just for developers - not
actually used) under;
<PEAR_ROOT>/Calendar/Engine
That should be all you need to do to install.
> The calendar I have at chiaraquartet.net takes about 7 seconds to build
a 12-month calendar. This is due to the database access that is needed in
order to make the calendar at all useful. I don't know how much of the
deadweight is from DB access or html/calendar generation, but I was hoping
to test this before voting. This is my only concern with
performance - I need a very easy way to plug in data to the dates. My
first look says this is possible, but I can't give you a good informed
evaluation without more time to test this.
OK - combining any Calendar with a database is always tricky in my opinion
- needs to be very careful with what get's iterated over but it _should_
be possible to achieve with a single query. Here's a guess at what you'll
need to do (in brief);
First to generate all the months in a year with some being selected;
<?php
require_once('Calendar/Calendar_Year.php'); // Include a year
require_once('Calendar/Calendar_Day.php'); // Include to allow selections
/* This controls the "type" of Month you get when you call
Calendar_Year::build()
Need to do this so you get a "tabular" representation of a month
mentioned in the FAQ at the bottom */
define('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS);
// Fetch the events from the DB (guessing that dates are stored with Unix
timestamps)
$selection = array(); // Selected events go here
$sql = "SELECT * FROM events";
$result = $db->query($sql);
while ( $row = $db->fetchRow('DB_ASSOC') ) {
$ts = $row['EventTime']; // Timestamp field
// Build a day object for the event
$Day = & new
Calendar_Day(date('Y',$ts),date('n',$ts),date('j',$ts));
$selection[]=& $Day; // Add the day to the selection
}
// Initialize this get variable, to allow paging of years
if ( !isset($_GET['year']) ) $_GET['year'] = date('Y');
// Create a year
$Year = & new Calendar_Year($_GET['year']);
// Build the Calendar_Month_Weekdays
$Year->build();
while ( $Month = & $Year->fetch() ) {
echo ( "<table>\n" );
// Build the days in the month, passing it the selection
$Month->build($selection);
while ( $Day = & $Month->fetch() ) {
if ( $Day->isFirst() ) { // First of a week
echo ( "<tr>\n" );
}
if ( $Day->isEmpty() ) { // Empty days - see FAQ
echo ( "<td> </td>\n" );
} else if ( $Day->isSelected() ) { // An event from the DB
echo (
"<td><b>".$Day->thisDay()."</b></td>\n" );
} else { // All other days
echo ( "<td>".$Day->thisDay()."</td>\n" );
}
}
echo ( "</table>\n");
}
?>
One calendar for a year, with events... Hope that helps.
> In addition, if you could write a 1-page tutorial on what class
> combinations are useful for typical problems, that would be very helpful
in my limited time to make sure I (and maybe others like me) understand
which class is designed for what task.
Will do so when I get a moment.
Harry