3 * Description: demonstrates a decorator to provide simple output formatting
4 * on the month while still allowing the days to be accessed via the decorator
5 * In practice you _wouldn't_ do this - each decorator comes with a performance
6 * hit for extra method calls. For this example some simple functions could help
7 * format the month while the days are accessed via the normal Month object
9 if ( !@include 'Calendar/Calendar.php' ) {
10 define('CALENDAR_ROOT','../../');
12 require_once CALENDAR_ROOT.'Month/Weekdays.php';
13 require_once CALENDAR_ROOT.'Decorator.php';
15 // Decorate a Month with methods to improve formatting
16 class MonthDecorator extends Calendar_Decorator {
18 * @param Calendar_Month
20 function MonthDecorator(& $Month) {
21 parent::Calendar_Decorator($Month);
24 * Override the prevMonth method to format the output
26 function prevMonth() {
27 $prevStamp = parent::prevMonth(TRUE);
28 // Build the URL for the previous month
29 return $_SERVER['PHP_SELF'].'?y='.date('Y',$prevStamp).
30 '&m='.date('n',$prevStamp).'&d='.date('j',$prevStamp);
33 * Override the thisMonth method to format the output
35 function thisMonth() {
36 $thisStamp = parent::thisMonth(TRUE);
37 // A human readable string from this month
38 return date('F Y',$thisStamp);
41 * Override the nextMonth method to format the output
43 function nextMonth() {
44 $nextStamp = parent::nextMonth(TRUE);
45 // Build the URL for next month
46 return $_SERVER['PHP_SELF'].'?y='.date('Y',$nextStamp).
47 '&m='.date('n',$nextStamp).'&d='.date('j',$nextStamp);
51 if (!isset($_GET['y'])) $_GET['y'] = date('Y');
52 if (!isset($_GET['m'])) $_GET['m'] = date('n');
54 // Creata a month as usual
55 $Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
57 // Pass it to the decorator and use the decorator from now on...
58 $MonthDecorator = new MonthDecorator($Month);
59 $MonthDecorator->build();
62 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
65 <title> A Simple Decorator </title>
68 <h1>A Simple Decorator</h1>
70 <caption><?php echo ( $MonthDecorator->thisMonth() ); ?></caption>
72 while ( $Day = $MonthDecorator->fetch() ) {
73 if ( $Day->isFirst() ) {
76 if ( $Day->isEmpty() ) {
77 echo ( "<td> </td>" );
79 echo ( "<td>".$Day->thisDay()."</td>" );
81 if ( $Day->isLast() ) {
87 <td><a href="<?php echo ($MonthDecorator->prevMonth()); ?>">Prev</a></td>
88 <td colspan="5"> </td>
89 <td><a href="<?php echo ($MonthDecorator->nextMonth()); ?>">Next</a></td>