Home » Date and Time » Calendar » Bug #1386
Multiple entries not possible
Details
| Submitted | 2004-05-11 18:42 UTC |
|---|---|
| From | max at tvattomaten dot se |
| Assigned | quipo |
| Status | Bogus |
| Package | Calendar |
| PHP Version | 4.3.6 |
| Roadmaps | (Not assigned) |
Comments
[2004-05-11 18:42 UTC] max at tvattomaten dot se
Description:
------------
I want to have several diary events for my calendar on the same day. I've duplicated more or less your example code with the small change that I have month -> days.
The problem is that there is as I can see no way of having multiple events in one day when examining a month. There is also no support for having events that occur at the same time.
Please consider adding the functionality, I believe that a diary without the possibility to have multiple entries on the same day/time is unrealistic and will because of that not be used.
Reproduce code:
---------------
require_once 'Calendar/Month/Weekdays.php';
require_once 'Calendar/Day.php';
require_once 'Calendar/Hour.php';
require_once 'Calendar/Decorator.php';
// Decorator to "attach" functionality to selected hours
class DiaryEvent extends Calendar_Decorator {
var $entry;
function DiaryEvent($calendar) {
Calendar_Decorator::Calendar_Decorator($calendar);
}
function setEntry($entry) {
$this->entry = $entry;
}
function getEntry() {
return $this->entry;
}
}
if (!isset($_GET['Y'])) $_GET['Y'] = date('Y');
if (!isset($_GET['m'])) $_GET['m'] = date('m');
$Month = new Calendar_Month_Weekdays($_GET['Y'], $_GET['m']);
$Times = array(
array("Date" => "2004-05-20",
"StartTime" => "12:10:00",
"EndTime" => "14:00:00"),
array("Date" => "2004-05-20",
"StartTime" => "15:10:00",
"EndTime" => "18:00:00"));
// An array to place selected hours in
$selection = array();
// Loop through the "database result"
foreach ( $Times as $Time ) {
$d = explode("-", substr($Time["Date"],0, strlen("2004-01-01")));
$year = $d[0];
$month = $d[1];
$day = $d[2];
unset($d);
$d = explode(":", $Time["StartTime"]);
$h = $d[0];
$min = $d[1];
$sec = $d[2];
unset($d);
$MDay = new Calendar_Day(2000,1,1,1); // Create Hour with dummy values
$MDay->setTimeStamp(mktime($h, $min, $sec, $month, $day, $year));
// Create the decorator, passing it the Hour
$DiaryEvent = new DiaryEvent($MDay);
$msg = '<a style="font-size: 1em;"'
.' href="delivery_time.php?ID=' . $Time["ID"] . '">'
. substr($Time["StartTime"], 0, 2)
. '<span style="position: relative; top: -.5em; font-size: .6em;">'
. substr($Time["StartTime"], 3, 2) . "</span>"
."-"
. substr($Time["EndTime"], 0, 2)
. '<span style="position: relative; top: -.5em; font-size: .6em;">'
. substr($Time["EndTime"], 3, 2) . "</span>"
."</a>";
// Attach the payload
$DiaryEvent->setEntry($msg);
// Add the decorator to the selection
$selection[] = $DiaryEvent;
}
$Month->build($selection);
$OutputCalendar .= "<table class=\"time\">\n";
$today = date("Y-m-d", strtotime("now"));
while ($Day = $Month->fetch()) {
if ($Day->isFirst()) {
$OutputCalendar .= "<tr>\n";
}
if ($Day->isEmpty()) {
$OutputCalendar .= "<td> </td>\n";
} else {
if ( $Day->isSelected() ) {
if ($today == date("Y-m-d", $Day->thisDay(TRUE))){
$OutputCalendar .= '<td id="selectedToday"><strong>'.$Day->thisDay()."</strong>\n";
}else{
$OutputCalendar .= '<td id="selectedTime"><strong>'.$Day->thisDay()."</strong>\n";
}
$OutputCalendar .= "<br />" .$Day->getEntry()."\n";
}elseif ($today == date("Y-m-d", $Day->thisDay(TRUE))){
$OutputCalendar .= '<td id="selectedToday"><strong>'.$Day->thisDay()."</strong>\n";
}else{
$OutputCalendar .= '<td><strong>'.$Day->thisDay()."</strong>\n";
}
$OutputCalendar .= '</td>';
}
if ($Day->isLast()) {
$OutputCalendar .= "</tr>\n";
}
}
$OutputCalendar .= "</table></p>\n";
echo $OutputCalendar;
Expected result:
----------------
I would like there to be a function for iterating through the diary events so that they are all displayed.
Actual result:
--------------
Only one of the two events that that are shown.
[2004-05-11 21:44 UTC] max at tvattomaten dot se
Thanks for your answer. Would be good to add that to your examples.
As I understand a simple:
while($entry = $Day->getEntry()){
...
}
should work. That would be neat and efficient.
Is there a good way of adding an entry that spans several hours/days/months? That would also be interesting. I guess that can be done by adding multiple objects but that seems to me like an less desirable way to go...