sfEventCalendarPlugin
Overview
This plugin enables you easily create a calendar of events in several calendar formats including day, week, month and year.
Maintainer
Please report all bugs to Ian Ricketson <ian.ricketson[at]symfony-project[dot]com> (_Slick_Rick on IRC)
Prerequisites
- Make sure you are using the latest version of symfony (at least version 0.9.2484).
- You must have the PEAR Date_Calc class (part of the Date library) installed, either via PEAR or by hand somewhere in your app.
Install the Plugin
Make sure you have the PEAR Date library installed:
pear install Date
If the PEAR Date library is installed, make sure it is updated:
pear upgrade Date
To install the plugin from the symfony command line, run the following command:
symfony plugin-install http://plugins.symfony-project.com/sfEventCalendarPlugin
You can also choose to manually install the plugin by downloading the attached file.
Basic Usage
// Initialize the event calendar with two parameters
// 1.) The style of the calendar (day, week, month, year)
// 2.) Any date within the specified time period. The script will automatically determine the best calendar days to return.
// For example, if you choose "month" and pass 1/15/2006, the calendar will return all dates and events from 01/01/2006 - 01/31/2006.
// If you choose "week" and pass 1/18/2006, the calender will return all dates and events from 01/16/2006 - 01/22/2006.
$c = new sfEventCalendar('month', '2006-01-01'); // The style of the calendar, any date within the specified time period
// Add an event to the calendar
// You must enter a date for the calendar event.
// You can enter as many options as you'd like that best fit your circumstances.
// For example, i've passed a title, and url to the calendar.
// You can pass these, or any number of parameters you'd like to associate with the event
$c->addEvent('12/15/2006', array('title' => 'Doctor Appointment', 'url' => '/module/action?id=1'));
// Return an array of calendar dates with the events attached to them.
// You can use this array to formulate a calendar in any way you'd like.
// The array automatically breaks years into months and months into weeks, etc...
$calendar = $c->getEventCalendar();
Note: For testing purposes you should print the $calendar array to see how the calendar is formatted.
Example $calendar Handling
Here is an example of how you might handle the output of a calendar in month format in a template file:
<table>
<?php
foreach ($calendar as $week)
{
?>
<tr>
<?php
foreach ($week as $day => $events)
{
echo ($day == date('Y-m-d')) ? '<td class="today">' : '<td>';
echo '<div>' . date('d', strtotime($day)) . '</div>';
if (!empty($events))
{
foreach ($events as $event)
{
?><p><?php echo link_to_if(isset($event['url']), $event['title'], $event['url'], array('title' => $event['alt'])); ?></p><?php
}
}
?>
</td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
Note: This is just an example, which uses the event parameters that I passed from the Basic Usage example. You could have an entirely different display format for your own scenerio.
Additional Information
You can also utilize the entire Date_Calc library from within the sfEventCalendar plugin by calling $c->getCalendar(), here are just a few examples:
$prev_week = $c->getCalendar()->beginOfPrevWeek($date_day, $date_month, $date_year, '%Y-%m-%d'); $next_week = $c->getCalendar()->beginOfNextWeek($date_day, $date_month, $date_year, '%Y-%m-%d'); $prev_month = $c->getCalendar()->beginOfPrevMonth($date_day, $date_month, $date_year, '%Y-%m-%d'); $next_month = $c->getCalendar()->beginOfNextMonth($date_day, $date_month, $date_year, '%Y-%m-%d');
For more information about the PEAR Date_Calc library, please see the PEAR Date_Calc Documentation
Attachments
- sfEventCalendarPlugin-1.0.0.tgz (3.2 kB) - added by slickrick on 12/05/06 19:35:00.
- sfEventCalendarPlugin-1.0.1.tgz (3.3 kB) -
Added additional error handling
, added by slickrick on 02/21/07 21:31:53.