Source for file 20.php
Documentation is available at 20.php
* Description: demonstrates a decorator used to "attach a payload" to a selection
* to make it available when iterating over calendar children
//if you use ISO-8601 dates, switch to PearDate engine
define('CALENDAR_ENGINE', 'PearDate');
if ( !@include 'Calendar/Calendar.php' ) {
define ('CALENDAR_ROOT','../../');
require_once CALENDAR_ROOT . 'Month/Weekdays.php';
require_once CALENDAR_ROOT . 'Day.php';
require_once CALENDAR_ROOT . 'Decorator.php';
// accepts multiple entries
function addEntry ($entry) {
$this->entries[] = $entry;
$entry = each($this->entries);
function build($events=array ())
$this->cE = & $this->getEngine ();
$daysInMonth = $this->cE->getDaysInMonth ($this->year, $this->month);
for ($i=1; $i<= $daysInMonth; $i++ ) {
$Day = new Calendar_Day(2000 ,1 ,1 ); // Create Day with dummy values
$Day->setTimeStamp ($this->cE->dateToStamp ($this->year, $this->month, $i));
if (count($events) > 0 ) {
$daysInMonth = $this->cE->getDaysInMonth ($this->year, $this->month);
for ($i=1; $i<= $daysInMonth; $i++ ) {
$stamp1 = $this->cE->dateToStamp ($this->year, $this->month, $i);
$stamp2 = $this->cE->dateToStamp ($this->year, $this->month, $i+1 );
foreach ($events as $event) {
if (($stamp1 >= $event['start'] && $stamp1 < $event['end']) ||
($stamp2 >= $event['start'] && $stamp2 < $event['end']) ||
($stamp1 <= $event['start'] && $stamp2 > $event['end'])
$this->children[$i]->addEntry ($event);
$this->children[$i]->setSelected ();
$child = each($this->children);
// Calendar instance used to get the dates in the preferred format:
// you can switch Calendar Engine and the example still works
'start' => $cal->cE->dateToStamp (2004 , 6 , 1 , 10 ),
'end' => $cal->cE->dateToStamp (2004 , 6 , 1 , 12 ),
'desc' => 'Important meeting'
'start' => $cal->cE->dateToStamp (2004 , 6 , 1 , 21 ),
'end' => $cal->cE->dateToStamp (2004 , 6 , 1 , 23 , 59 ),
'desc' => 'Dinner with the boss'
'start' => $cal->cE->dateToStamp (2004 , 6 , 5 ),
'end' => $cal->cE->dateToStamp (2004 , 6 , 10 , 23 , 59 ),
$MonthDecorator->build($events);
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<title> Calendar </title>
border-collapse: collapse;
background-color: #e7e3e7;
border: 1px solid #b5bece;
background-color: #f3f3f7;
background-color: #efeffa;
background-color: #f8f8f8;
border-bottom: 1px solid #ccc;
<h2>Sample Calendar Payload Decorator (using <?php echo CALENDAR_ENGINE; ?> engine)</h2>
<table class="calendar" width="98%" cellspacing="0" cellpadding="0">
while ($Day = $MonthDecorator->fetch()) {
echo '<td class="calCell';
echo '<div class="dayNumber">'. $Day->thisDay(). '</div>';
echo '<div class="dayContents"><ul>';
while ($entry = $Day->getEntry ()) {
echo '<li>'. $entry['desc']. '</li>';
//you can print the time range as well
Documentation generated on Mon, 11 Mar 2019 15:37:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|