I ran into a situation where I needed a calendar generator for the Zend Framework. I spent an hour or so searching but couldn’t find anything that fit my tastes so I wrote my own. My calendar uses Zend_Date and Zend_Locale and is truly Zendy (new word?). It uses a view script to generate the calendar so it’s completely customizable and cssable (another new word?). I call it SpiffyCalendar (dun dun dun)!
- Completely integrated as a library package for Zend Framework.
- Utilizes Zend_Date and Zend_Locale provided by the Zend Framework.
- Rendered using different adapters (ships with Zend_View and a view script).
- Released under the GNU GPL license
- Support for adding events/appointments.
- Easily AJAXified
You can checkout the latest source from the SpiffyLib Google Project’s page.
Below are a few examples to show the capabilities of SpiffyCalendar. This is by no means an exhaustive list so if you have something you want to be able to do and don’t know how post a comment and I’ll see if I will try my best to update this page with the answers.
Generating a simple calendar
view->cal = $cal; echo $cal;
Adding an event from an array
This example will add two events using an array to the calendar. Event #1 is added to the calendar using a day of 1 with the current month and year. Event #2 is added using the default day of 5 with a current month and year. Event #3 is added to the current day, month, and year. The event array source always uses the ‘eventDate’ to determine the date and falls back to the default date and finally the current date. All values passed as date can be retrieved in the renderer using $cal->getData().
createEvent( 'array', array( array( 'title' => 'Event #1', 'eventDate' => array('day' => 1)) array('title' => 'Event #2') ), array( 'day' => 5 )); $cal->createEvent('array', array(array('title' =>; 'Event #3')));
Adding an event from a Zend_Db_Table using objects
SpiffyCalendar also supports the ability to use a Zend_Db_Table as a data source. You can use every method that a table has but the most common method is using select() to filter results.
setTable(new Default_Model_DbTable_Event()); // Only shows ids greater than 10 $events->getSelect()->where('id = 10'); // Set a default date in case the table doesn't have one $events->setDate(array('day' => 10)); // Set the dateField and dateFormat of the date field from the database. $events->setParams( array('dateField' => 'date', 'dateFormat' => 'YYYY-MM-DD')); // Create the event $cal->createEvent($events); $this->view->calendar = $cal
1.0.1 – 10.02.2009
- Fixed getMonthNames() to use the new date object’s locale.
- Fixed getEndDay() to use all days of the week.
- Fixed a bug with getDay() which would sometimes cause duplicate days.
- Added method getNextMonthName($format = Zend_Date::MONTH_NAME); which returns the next month’s name using the specified format.
- Added method getPrevMonthName($format = Zend_Date::MONTH_NAME); which returns the previous month’s name using the specified format.
- Added method getNextYear($format = Zend_Date::YEAR); which returns the next year using the specified format.
- Added method getPrevYear($format = Zend_Date::YEAR); which returns the previous year using the specified format.
- Added method getYearList($limit = 5, $format = Zend_Date::YEAR); which returns an array of years beginning with the current year and going +/- $limit years.
- Added automatic cache detection by setting a registry key of “Spiffy_Calendar_Cache”
- Added parameter check of day, month, year which can be passed via $_POST, $_GET or the URI.
- Added methods getDayDigit(), getMonthDigit(), and getYearDigit(). Returns the day (1-31), month (1-12), and year (YYYY) respectively.
1.0.0 – 09.18.2009
- Initial Release