Calendar
[ class tree: Calendar ] [ index: Calendar ] [ all elements ]

Source for file 10.php

Documentation is available at 10.php

  1. <?php
  2. /**
  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
  8. */
  9. if !@include 'Calendar/Calendar.php' {
  10.     define('CALENDAR_ROOT','../../');
  11. }
  12. require_once CALENDAR_ROOT.'Month/Weekdays.php';
  13. require_once CALENDAR_ROOT.'Decorator.php';
  14.  
  15. // Decorate a Month with methods to improve formatting
  16.     /**
  17.     * @param Calendar_Month 
  18.     */
  19.     function MonthDecorator($Month{
  20.         parent::Calendar_Decorator($Month);
  21.     }
  22.     /**
  23.     * Override the prevMonth method to format the output
  24.     */
  25.     function prevMonth({
  26.         $prevStamp = parent::prevMonth(TRUE);
  27.         // Build the URL for the previous month
  28.         return $_SERVER['PHP_SELF'].'?y='.date('Y',$prevStamp).
  29.             '&m='.date('n',$prevStamp).'&d='.date('j',$prevStamp);
  30.     }
  31.     /**
  32.     * Override the thisMonth method to format the output
  33.     */
  34.     function thisMonth({
  35.         $thisStamp = parent::thisMonth(TRUE);
  36.         // A human readable string from this month
  37.         return date('F Y',$thisStamp);
  38.     }
  39.     /**
  40.     * Override the nextMonth method to format the output
  41.     */
  42.     function nextMonth({
  43.         $nextStamp = parent::nextMonth(TRUE);
  44.         // Build the URL for next month
  45.         return $_SERVER['PHP_SELF'].'?y='.date('Y',$nextStamp).
  46.             '&m='.date('n',$nextStamp).'&d='.date('j',$nextStamp);
  47.     }
  48. }
  49.  
  50. if (!isset($_GET['y'])) $_GET['y'date('Y');
  51. if (!isset($_GET['m'])) $_GET['m'date('n');
  52.  
  53. // Creata a month as usual
  54. $Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
  55.  
  56. // Pass it to the decorator and use the decorator from now on...
  57. $MonthDecorator = new MonthDecorator($Month);
  58. $MonthDecorator->build();
  59. ?>
  60.  
  61. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  62. <html>
  63. <head>
  64. <title> A Simple Decorator </title>
  65. </head>
  66. <body>
  67. <h1>A Simple Decorator</h1>
  68. <table>
  69. <caption><?php echo $MonthDecorator->thisMonth() )?></caption>
  70. <?php
  71. while $Day $MonthDecorator->fetch() ) {
  72.     if $Day->isFirst() ) {
  73.         echo "\n<tr>\n" );
  74.     }
  75.     if $Day->isEmpty() ) {
  76.         echo "<td>&nbsp;</td>" );
  77.     else {
  78.         echo "<td>".$Day->thisDay()."</td>" );
  79.     }
  80.     if $Day->isLast() ) {
  81.         echo "\n</tr>\n" );
  82.     }
  83. }
  84. ?>
  85. <tr>
  86. <td><a href="<?php echo ($MonthDecorator->prevMonth())?>">Prev</a></td>
  87. <td colspan="5">&nbsp;</td>
  88. <td><a href="<?php echo ($MonthDecorator->nextMonth())?>">Next</a></td>
  89. </tr>
  90. </table>
  91. </body>
  92. </html>

Documentation generated on Mon, 11 Mar 2019 15:37:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.