Calendar
Display calendars with optional events.
Summary
- Introduction
- Legal Copyright (C) 2007 Stephane Lavergne http://www.imars.com/
- TODO Implement XHTML()'s year mode.
- Description This class specifically addresses the issue of displaying calendars of various kinds, possibly with events involved.
- Methods
Introduction
Legal
Copyright (C) 2007 Stephane Lavergne http://www.imars.com/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
TODO
Implement XHTML()'s year mode.
Description
This class specifically addresses the issue of displaying calendars of various kinds, possibly with events involved. It is not an events manager.
Example
require_once 'Calendar.inc'; $cal = new Calendar(); echo $cal->XHTML();
TODO
There is still no linking nor pop-up possibilities. Year view is not yet implemented.
Methods
Calendar
function Calendar($weekstart = 0, $monthstart = 1)
Instantiate the class. Note that this class is designed to be reusable as many times as needed: once events are loaded with AddEvent(), multiple calendars of any kind can be generated with that same instance. This could be useful, for example, to load a single list of events to display a current month in XHTML()'s 'full' mode along with the previous and next months in its 'compact' mode.
Parameters
- $weekstart
- Which day (0-6) to start weeks at. (Optional.)
- $monthstart
- Which month (1-12) to start year at. (Optional.)
SetDays
function SetDays($sun, $mon, $tue, $wed, $thu, $fri, $sat)
Specify non-English day names. Single letter short versions will be derived from this as well.
Parameters
- $sun
- String to identify Sunday.
- $mon
- String to identify Monday.
- $tue
- String to identify Tuesday.
- $wed
- String to identify Wednesday.
- $thu
- String to identify Thursday.
- $fri
- String to identify Friday.
- $sat
- String to identify Saturday.
Returns
Always returns true.
SetMonths
function SetMonths($m1, $m2, $m3, $m4, $m5, $m6, $m7, $m8, $m9, $m10, $m11, $m12)
Specify non-English month names.
Parameters
- $m1
- String to identify month 1 (January).
- $m2
- String to identify month 2 (February).
- $m3
- String to identify month 3 (March).
- $m4
- String to identify month 4 (April).
- $m5
- String to identify month 5 (May).
- $m6
- String to identify month 6 (June).
- $m7
- String to identify month 7 (July).
- $m8
- String to identify month 8 (August).
- $m9
- String to identify month 9 (September).
- $m10
- String to identify month 10 (October).
- $m11
- String to identify month 11 (November).
- $m12
- String to identify month 12 (December).
Returns
Always returns true.
AddEvent
function AddEvent($year, $month, $day, $class, $title, $starttime = null, $stoptime = null, $body = null)
Add an event to the in-memory calendar, for a specific date. Optional start and stop times may be specified as well as a long description.
Internally, events are sorted as they are added, so that displaying can be quick and repeatable. For each day, timeless events are added in the order in which they were added. Next, events with start times are sorted in chronological order. If two events start at the same time, they are sorted in the order in which they were added.
Parameters
- $year
- Event's year (4-digit format).
- $month
- Event's month in the year (1-12).
- $day
- Event's day of the month (1-31).
- $class
- CSS class to highlight the day with. (Used in display methods.)
- $title
- Short description of the event.
- $starttime
- Start time in “hh:mm” format. (Optional.)
- $stoptime
- Stop time in “hh:mm” format. (Optional, even when $starttime is defined.)
- $body
- Long description of the event. (Optional.)
Returns
Always returns true.
XHTML
function XHTML($mode = 'compact', $year = null, $month = null)
Display a calendar in XHTML 1.1 Strict. Each mode returns a different kind of calendar. In each case, it is up to the caller to use some CSS to achieve the desired display characteristics.
Compact mode
A table of class 'calendar_compact' is generated. First, a row of headers lists the first letters of each day of the week. Next, as many rows of cells as necessary are generated to contain actual days. Each day cell which is within the current month gets attributed a class, one of:
- weekday
- By default, days 1-5 receive this class.
- weekend
- By default, days 0 and 6 receive this class.
- today
- By default, the current day gets this class.
If there are events for a day, the class of the day's first event (see AddEvent() for sort order) is used instead of one of the above.
Full mode
A table of class 'calendar_full' is generated. First, a row of headers lists the full names of each day of the week. Next, as many rows of cells as necessary are generated to contain actual days. Like compact mode, each day cell can be of class 'weekday', 'weekend', or 'today'. However, cells are not directly affected by events, as they contain a list of the day's events in this mode.
For each event, in order (see AddEvent() for sort order), a div of class 'event' is created. Inside, first a span containing a small space is displayed, member of the event's class. This is intended for color-coding. Next, the event's short title is displayed.
Year mode
NOT YET IMPLEMENTED. This will essentially call itself 12 times in compact mode, starting with $monthstart. I believe 12 tables in a row would wrap according to their containing block, but some testing should confirm this.
Parameters
- $mode
- One of: compact, full, year. (Optional.)
- $year
- 4-digit year. (Optional.)
- $month
- Month (1-12). (Optional.)
Returns
The generated XHTML code ready to output.