source: branches/version-2_5-dev/data/module/Calendar/docs/examples/11.php @ 20119

Revision 20119, 3.0 KB checked in by nanasess, 13 years ago (diff)

module 以下は svn:keywords を除外

  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/**
3* Description: demonstrates a decorator used to "attach a payload" to a selection
4* to make it available when iterating over calendar children
5*/
6if ( !@include 'Calendar/Calendar.php' ) {
7    define('CALENDAR_ROOT','../../');
8}
9require_once CALENDAR_ROOT.'Day.php';
10require_once CALENDAR_ROOT.'Hour.php';
11require_once CALENDAR_ROOT.'Decorator.php';
12
13// Decorator to "attach" functionality to selected hours
14class DiaryEvent extends Calendar_Decorator {
15    var $entry;
16    function DiaryEvent($calendar) {
17        Calendar_Decorator::Calendar_Decorator($calendar);
18    }
19    function setEntry($entry) {
20        $this->entry = $entry;
21    }
22    function getEntry() {
23        return $this->entry;
24    }
25}
26
27// Create a day to view the hours for
28$Day = & new Calendar_Day(2003,10,24);
29
30// A sample query to get the data for today (NOT ACTUALLY USED HERE)
31$sql = "
32        SELECT
33            *
34        FROM
35            diary
36        WHERE
37            eventtime >= '".$Day->thisDay(TRUE)."'
38        AND
39            eventtime < '".$Day->nextDay(TRUE)."';";
40
41// An array simulating data from a database
42$result = array (
43    array('eventtime'=>mktime(9,0,0,10,24,2003),'entry'=>'Meeting with sales team'),
44    array('eventtime'=>mktime(11,0,0,10,24,2003),'entry'=>'Conference call with Widget Inc.'),
45    array('eventtime'=>mktime(15,0,0,10,24,2003),'entry'=>'Presentation to board of directors')
46    );
47
48// An array to place selected hours in
49$selection = array();
50
51// Loop through the "database result"
52foreach ( $result as $row ) {
53    $Hour = new Calendar_Hour(2000,1,1,1); // Create Hour with dummy values
54    $Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp
55
56    // Create the decorator, passing it the Hour
57    $DiaryEvent = new DiaryEvent($Hour);
58
59    // Attach the payload
60    $DiaryEvent->setEntry($row['entry']);
61
62    // Add the decorator to the selection
63    $selection[] = $DiaryEvent;
64}
65
66// Build the hours in that day, passing the selection
67$Day->build($selection);
68?>
69<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
70<html>
71<head>
72<title> Passing a Selection Payload with a Decorator </title>
73</head>
74<body>
75<h1>Passing a Selection "Payload" using a Decorator</h1>
76<table>
77<caption><b>Your Schedule for <?php echo ( date('D nS F Y',$Day->thisDay(TRUE)) ); ?></b></caption>
78<tr>
79<th width="5%">Time</th>
80<th>Entry</th>
81</tr>
82<?php
83while ( $Hour = & $Day->fetch() ) {
84
85    $hour = $Hour->thisHour();
86    $minute = $Hour->thisMinute();
87
88    // Office hours only...
89    if ( $hour >= 8 && $hour <= 18 ) {
90        echo ( "<tr>\n" );
91        echo ( "<td>$hour:$minute</td>\n" );
92
93        // If the hour is selected, call the decorator method...
94        if ( $Hour->isSelected() ) {
95            echo ( "<td bgcolor=\"silver\">".$Hour->getEntry()."</td>\n" );
96        } else {
97            echo ( "<td>&nbsp;</td>\n" );
98        }
99        echo ( "</tr>\n" );
100    }
101}
102?>
103</table>
104<p>The query to fetch this data, with help from PEAR::Calendar, might be;</p>
105<pre>
106<?php echo ( $sql ); ?>
107</pre>
108</body>
109</html>
Note: See TracBrowser for help on using the repository browser.