Sitellite Application Framework
Class Tree         Index         All Elements

Class: Calendar

Source Location: Program_Root/Date/Calendar.php

Class Overview

HtmlLayout
   |
   --Calendar

Calendar implements a graphical calendar generator. This class derives most of its functionality from the saf.GUI.Layout package, so for more information and additional functionality, please read up on that one as well.


Author(s)

Version

  • 1.2, 2003-01-20, $Id: Calendar.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods

Class: HtmlLayout

HtmlLayout::HtmlLayout()
Constructor method.
HtmlLayout::addCol()
Increases the number of columns by 1.
HtmlLayout::addRow()
Increases the number of rows by 1.
HtmlLayout::append()
Appends more to the template of the specified child HtmlCell object. $part may be either a string of the format 'a1', or an array with two numeric values denoting the cell's x and y position.
HtmlLayout::assign()
Assigns a template to the specified child HtmlCell object.
HtmlLayout::col()
Returns the specified column as an array of cells.
HtmlLayout::render()
Renders this layout and all of its cells as well.
HtmlLayout::row()
Returns the specified row as an array of cells.
HtmlLayout::set()
Increases the number of columns by 1. Note that $part may be either 'table', 'row', or 'cell' to refer to internal properties, or 'a1, a2, etc' or an array of x and y to refer to pass the property/value pair on to the set() method of individual cells.
HtmlLayout::spanCols()
Sets the colspan on the specified cell, and set the cells that would be in the way to false. $num is the colspan.
HtmlLayout::spanRows()
Sets the rowspan on the specified cell, and set the cells that would be in the way to false. $num is the rowspan.
HtmlLayout::sub()
Create and return a sub HtmlLayout object in the
HtmlLayout::translate()
Translates between the 'a1, a2, b1, b2' notation and the array (0, 0), array (0, 1), array (1, 0), array (1, 1) notation.
HtmlLayout::walk()
Returns the entire grid as an array of cells, going top-to-bottom, then left-to-right.

Class Details

[line 289]
Calendar implements a graphical calendar generator. This class derives most of its functionality from the saf.GUI.Layout package, so for more information and additional functionality, please read up on that one as well.

New in 1.2:

  • Stopped using saf.Template in favour of saf.Template.Simple. Templates now use the {tagname} syntax instead of ##tagname##.
  • Modified the example to include saf/init.php instead of the more verbose stuff that was there before.

1 <?php
2
3 // let's create a browseable daily, weekly, and monthly calendar with next|previous links
4
5 // load the necessary packages
6 include_once ('saf/init.php');
7
8 $loader->inc ('saf.Date.Calendar');
9 $loader->inc ('saf.Database');
10 $loader->inc ('saf.Template.Simple');
11 $loader->inc ('saf.CGI');
12
13 // create a few supporting objects
14 // adjust database parameters as necessary (for more info see saf.Database)
15 $db = new Database ('MySQL:www.sitellite3.lo:DBNAME', 'USER', 'PASS');
16 $simple = new SimpleTemplate;
17 $cgi = new CGI;
18
19 // set a few defaults for $cgi params
20 if (empty ($cgi->date)) {
21 $cgi->date = date ('Y-m-d');
22 }
23
24 if (empty ($cgi->show)) {
25 $cgi->show = 'week';
26 }
27
28 if (empty ($cgi->startOn)) {
29 $cgi->startOn = 'Sun';
30 }
31
32 // create our calendar
33 $c = new Calendar ($cgi->date, $cgi->show, $cgi->startOn);
34
35 // set some visual properties for the cell and table elements in our calendar
36 $c->cell['width'] = '14%';
37 $c->cell['height'] = '75';
38 $c->cell['style'] = "border: #000 1px solid; font: 12px Arial";
39 $c->table['style'] = "border: #000 1px solid";
40 $c->table['border'] = "1";
41 $c->table['width'] = "100%";
42
43 if ($c->showPeriod == 'day') {
44 // initialize day view
45
46 // height limit of 75 not wanted
47 unset ($c->cell['height']);
48
49 // only show from 9 to 5 (4 & 4:30, but not 5 itself)
50 $c->showFromHour = 9;
51 $c->showToHour = 16;
52
53 // fill the calendar with pretty things from the database
54 $res = $c->fillCalendar (
55 'select * from sitellite_event order by date asc',
56 'date',
57 '<a href="/index/events/id.{id}">{title}</a><br />'
58 );
59
60 // create the header of the calendar
61 $yesterday = Date::subtract ($cgi->date, '1 day');
62 $tomorrow = Date::add ($cgi->date, '1 day');
63
64 $c->makeHeader (
65 '<h1>' . Date::format ($cgi->date, 'F jS, Y') . '</h1>' .
66 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $yesterday . '">' .
67 Date::format ($yesterday, 'F jS, Y') . '</a> | <a href="caltest.php' .
68 $cgi->makeQuery ('date') . '&date=' . $tomorrow . '">' .
69 Date::format ($tomorrow, 'F jS, Y') . '</a></p>',
70 array (
71 'style' => 'background-color: #69c; font: 14px Arial',
72 'align' => 'center',
73 'valign' => 'middle',
74 'width' => '100%',
75 'height' => '25',
76 ),
77 array (
78 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold',
79 'align' => 'center',
80 'valign' => 'middle',
81 'height' => '20',
82 )
83 );
84
85 // this is another way we could add content to a specific cell
86 //$c->append ('_9am', 'Foo bar');
87
88 } elseif ($c->showPeriod == 'week') {
89 // initialize week view
90
91 // fill the calendar with pretty things from the database
92 $res = $c->fillCalendar (
93 'select * from sitellite_event order by date asc',
94 'date',
95 '<a href="/index/events/id.{id}">{title}</a><br />',
96 '{day}<br />'
97 );
98
99 // shade today's box
100 if (is_object ($c->{$c->activeCells[date ('Y-m-d')]})) {
101 $c->set ($c->activeCells[date ('Y-m-d')], 'bgcolor', '#ffffdd');
102 }
103
104 // create the header of the calendar
105 $lastWeek = Date::subtract ($cgi->date, '1 week');
106 $nextWeek = Date::add ($cgi->date, '1 week');
107
108 $c->makeHeader (
109 '<h1>Week of ' . Date::format ($c->firstDay, 'F jS, Y') . '</h1>' .
110 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $lastWeek .
111 '">Week of ' . Date::format ($lastWeek, 'F jS, Y') . '</a> | <a href="caltest.php' .
112 $cgi->makeQuery ('date') . '&date=' . $nextWeek . '">Week of ' .
113 Date::format ($nextWeek, 'F jS, Y') . '</a></p>',
114 array (
115 'style' => 'background-color: #69c; font: 14px Arial',
116 'align' => 'center',
117 'valign' => 'middle',
118 'width' => '100%',
119 'height' => '25',
120 ),
121 array (
122 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold',
123 'align' => 'center',
124 'valign' => 'middle',
125 'height' => '20',
126 ),
127 array (
128 'style' => 'background-color: #ccc',
129 ),
130 array (
131 'style' => 'background-color: #ccc',
132 )
133 );
134
135 // this is another way we could add content to a specific cell
136 //$c->append ('_5th', 'Foo bar');
137
138 } elseif ($c->showPeriod == 'month') {
139 // initialize month view
140
141 // fill the calendar with pretty things from the database
142 $res = $c->fillCalendar (
143 'select * from sitellite_event order by date asc',
144 'date',
145 '<a href="/index/events/id.{id}">{title}</a><br />',
146 '{day}<br />'
147 );
148
149 // shade today's box
150 if (is_object ($c->{$c->activeCells[date ('Y-m-d')]})) {
151 $c->set ($c->activeCells[date ('Y-m-d')], 'bgcolor', '#ffffdd');
152 }
153
154 // create the header of the calendar
155 $lastMonth = Date::subtract ($cgi->date, '1 month');
156 $nextMonth = Date::add ($cgi->date, '1 month');
157
158 $c->makeHeader (
159 '<h1>' . Date::format ($cgi->date, 'F, Y') . '</h1>' .
160 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $lastMonth . '">' .
161 Date::format ($lastMonth, 'F, Y') . '</a> | <a href="caltest.php' .
162 $cgi->makeQuery ('date') . '&date=' . $nextMonth . '">' .
163 Date::format ($nextMonth, 'F, Y') . '</a></p>',
164 array (
165 'style' => 'background-color: #69c; font: 14px Arial',
166 'align' => 'center',
167 'valign' => 'middle',
168 'width' => '100%',
169 'height' => '25',
170 ),
171 array (
172 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold',
173 'align' => 'center',
174 'valign' => 'middle',
175 'height' => '20',
176 ),
177 array (
178 'style' => 'background-color: #ccc',
179 ),
180 array (
181 'style' => 'background-color: #ccc',
182 )
183 );
184 }
185
186 // the following is a bunch of form junk to make the calendar view user-definable
187 if ($cgi->show == 'day') {
188 $showDay = ' selected="selected"';
189 } elseif ($cgi->show == 'week') {
190 $showWeek = ' selected="selected"';
191 } elseif ($cgi->show == 'month') {
192 $showMonth = ' selected="selected"';
193 }
194
195 if ($cgi->startOn == 'Sun') {
196 $startSun = ' selected="selected"';
197 } elseif ($cgi->startOn == 'Mon') {
198 $startMon = ' selected="selected"';
199 } elseif ($cgi->startOn == 'Tue') {
200 $startTue = ' selected="selected"';
201 } elseif ($cgi->startOn == 'Wed') {
202 $startWed = ' selected="selected"';
203 } elseif ($cgi->startOn == 'Thu') {
204 $startThu = ' selected="selected"';
205 } elseif ($cgi->startOn == 'Fri') {
206 $startFri = ' selected="selected"';
207 } elseif ($cgi->startOn == 'Sat') {
208 $startSat = ' selected="selected"';
209 }
210
211 ? ><form method="get">
212 <p align="right">
213 <input type="hidden" name="date" value="<?php echo $cgi->date; ? >" />
214 View: <select name="show">
215 <option value="day"<?php echo $showDay; ? >>Day</option>
216 <option value="week"<?php echo $showWeek; ? >>Week</option>
217 <option value="month"<?php echo $showMonth; ? >>Month</option>
218 </select>
219 , Start Week On: <select name="startOn">
220 <option value="Sun"<?php echo $startSun; ? >>Sun</option>
221 <option value="Mon"<?php echo $startMon; ? >>Mon</option>
222 <option value="Tue"<?php echo $startTue; ? >>Tue</option>
223 <option value="Wed"<?php echo $startWed; ? >>Wed</option>
224 <option value="Thu"<?php echo $startThu; ? >>Thu</option>
225 <option value="Fri"<?php echo $startFri; ? >>Fri</option>
226 <option value="Sat"<?php echo $startSat; ? >>Sat</option>
227 </select>
228 <input type="submit" value="Go" />
229 </p>
230 </form><?php
231
232 // display the calendar
233 if ($res) {
234 echo $c->render ();
235 } else {
236 echo $c->error;
237 }
238
239 ? >




Tags:

access:  public
version:  1.2, 2003-01-20, $Id: Calendar.php,v 1.2 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$activeCells = array ()

[line 360]

Contains a list of the active cells in the Calendar matrix. Active cells are the days that are in use.



Tags:

access:  public

Type:   mixed


[ Top ]

$beginWeekOn =

[line 307]

Tells the calendar what day of the week to start the calendar on. Value may be one of 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', and 'Sat'.



Tags:

access:  public

Type:   mixed


[ Top ]

$bottomBlock =

[line 388]

Reference to the cell that contains the space after the last day of the month in the 'month' $showPeriod.



Tags:

access:  public

Type:   mixed


[ Top ]

$cellTemplate =

[line 370]

Contains a default template for use in each cell. The cell template is not to be confused with the item template, which displays an individual item on any given day.



Tags:

access:  public

Type:   mixed


[ Top ]

$currentDay =

[line 324]

Contains the current date (Y-m-d format).



Tags:

access:  public

Type:   mixed


[ Top ]

$error =

[line 397]

If an error has occured within this class, you'll find it in $error.



Tags:

access:  public

Type:   mixed


[ Top ]

$firstDay =

[line 316]

Contains the date (Y-m-d format) of the first day to include in the current calendar view.



Tags:

access:  public

Type:   mixed


[ Top ]

$lastDay =

[line 333]

Contains the date (Y-m-d format) of the last day to include in the current calendar view.



Tags:

access:  public

Type:   mixed


[ Top ]

$showFromHour =  0

[line 342]

Tells Calendar to limit the hours displayed in 'day' view.

Must be an integer from 0 to 23.




Tags:

access:  public

Type:   mixed


[ Top ]

$showPeriod =

[line 297]

Tells the calendar what to display on a single screen. May be 'day', 'week', or 'month'.



Tags:

access:  public

Type:   mixed


[ Top ]

$showToHour =  23

[line 351]

Tells Calendar to limit the hours displayed in 'day' view.

Must be an integer from 0 to 23.




Tags:

access:  public

Type:   mixed


[ Top ]

$topBlock =

[line 379]

Reference to the cell that contains the space before the first day of the month in the 'month' $showPeriod.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor Calendar [line 410]

Calendar Calendar( [string $date = ''], [string $showPeriod = 'week'], [string $beginWeekOn = 'Sun'])

Constructor Method. $date is a date in the format Y-m-d.

$beginWeekOn may be the three letter abbreviation of any of the weekdays (ie. Sun, Mon, Tue, Wed, Thu, Fri, or Sat).




Tags:

access:  public


Parameters:

string   $date  
string   $showPeriod  
string   $beginWeekOn  

[ Top ]

method fillCalendar [line 619]

boolean fillCalendar( [string $sql = ''], [string $dateColumn = 'date'], [string $itemTemplate = ''], [string $cellTemplate = '{day}
'], [string $timeColumn = 'time'])

Fills the calendar based on an optional SQL query, some

related database information, and templates for the cells and items. Also initializes the $topBlock and $bottomBlock cells if $showPeriod is 'month' (these refer to the empty space at the top and bottom of the monthly calendar), and sets aliases to each cell which can be referenced as $calendar_object->_1st, $calendar_object->_2nd, $calendar_object->_3rd, etc., or $calendar_object->_1200am, $calendar_object->_1230am, $calendar_object->_100am, etc. if the $showPeriod is 'day'.




Tags:

access:  public


Parameters:

string   $sql  
string   $dateColumn  
string   $itemTemplate  
string   $cellTemplate  
string   $timeColumn  

[ Top ]

method getFirstAndLastDay [line 439]

void getFirstAndLastDay( [string $date = ''])

Sets the $firstDay and $lastDay properties based on

the $showPeriod and the $date specified. If a $date is not specified, it defaults to the $currentDay property. Also sets the $activeCells array with a key/value list of dates (Y-m-d format) as keys and a1, a2 style notation as the values.




Tags:

access:  public


Parameters:

string   $date  

[ Top ]

method getXCells [line 525]

associative getXCells( )

Returns an array of weekdays (Mon, Tue, Wed) corresponding with the X cell value they fall under, based on the $beginWeekOn property.



Tags:

return:  array
access:  public


[ Top ]

method makeHeader [line 951]

void makeHeader( string $contents, [array $properties = array ()], [array $headerProperties = array ()], [array $topBlockProperties = array ()], [array $bottomBlockProperties = array ()])

Creates the header of the calendar, using $contents

for the main cell, a list of $properties for the <td> of the main cell, a list of $headerProperties for each of the day cells (as returned by getXCells(), and properties for the $topBlock and $bottomBlock cells as well.




Tags:

access:  public


Parameters:

string   $contents  
array   $properties  
array   $headerProperties  
array   $topBlockProperties  
array   $bottomBlockProperties  

[ Top ]

method makeTime [line 922]

string makeTime( string $hour, string $tstring)

Takes a number between 0 and 23 (the $hour), and a string from the fillCalendar() method of the format 5:30 or 12:00AM, and returns a string in the format H:i:s.



Tags:

access:  public


Parameters:

string   $hour  
string   $tstring  

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:16:52 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2