PEAR Calendar Decorator / Week bug?
| From: | Markus Konrad | Date: | Thu, 15 Apr 2004 22:43:58 +0000 |
| Subject: | PEAR Calendar Decorator / Week bug? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-11903@lists.php.net to get a copy of this message | ||
Hello,
I'm using the PEAR::Calendar and Calendar_Decorator classes for an event planner. It works great in the month and day view, but in the week view the decorator doesn't seem to save the events. I could not figure out the problem and so I tried to reproduce it with the example no. 11 in the documentation (pear/docs/Calendar/docs/examples) - the same behaviour occured.
That's my rewrite of example no. 11, so that it should display a week with events, but produces an error:
<?php
require_once("Calendar/Week.php");
require_once("Calendar/Day.php");
require_once("Calendar/Decorator.php");
// Decorator
class Event extends Calendar_Decorator
{
var $arEntry;
function Event($objCal)
{
Calendar_Decorator::Calendar_Decorator($objCal);
}
function setEntry($arEntry)
{
$this->arEntry = $arEntry;
}
function getEntry()
{
return $this->arEntry;
}
}
// Create a week calendar object
$objWeek = & new Calendar_Week(2004, 04, 12, 1);
// An array simulating data from a database
$arResult = array (
array('eventtime'=>mktime(0,0,0,04,12,2004),'entry'=>'Meeting with sales team'),
array('eventtime'=>mktime(0,0,0,04,14,2004),'entry'=>'Conference call with Widget Inc.'),
array('eventtime'=>mktime(0,0,0,04,16,2004),'entry'=>'Presentation to board of directors')
);
//An array to place selected hours in
$arSelection = array();
// Loop through the "database result"
foreach ($arResult as $arRow)
{
$objDay = new Calendar_Day(2000 ,1 ,1); //Create day with dummy values
$objDay->setTimeStamp($arRow['eventtime']); //Set the real time with setTimeStamp
// Create the decorator, passing it the day
$objEvent = new Event($objDay);
// Attach the payload
$objEvent->setEntry($arRow['entry']);
// Add the decorator to the selection
$arSelection[] = $objEvent;
}
unset($objDay);
unset($arResult);
unset($arRow);
unset($objEvent);
// Build the days in that week, passing the selection
$objWeek->build($arSelection);
//$objWeek->build(); //it does work without the selections!
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Passing a Selection Payload with a Decorator </title>
</head>
<body>
<h1>Passing a Selection "Payload" using a Decorator</h1>
<table width="90%">
<tr>
<th width="25%">Date</th>
<th>Entry</th>
</tr>
<?php
while ($objDay = & $objWeek->fetch())
{
echo ( "<tr>\n" );
echo ( "<td>" . date("Y-m-d", $objDay->getTimeStamp()) . "</td>\n" );
// If the day is selected, call the decorator method...
if ($objDay->isSelected())
{
echo ( "<td bgcolor=\"silver\">".$objDay->getEntry()."</td>\n" );
} else {
echo ( "<td> </td>\n" );
}
echo ( "</tr>\n" );
}
?>
</table>
</body>
</html>
It will display a "Fatal error: Call to undefined function: getentry() on line 88". Somehow the decorator does not save the events. I rewrote it to display a whole month and it worked again! Is this really a bug or did I overlook something?
--
Bye,
Markus Konrad
ICQ#: 119020475