// A sample query to get the data for today (NOT ACTUALLY USED HERE) $sql = "\n SELECT\n *\n FROM\n diary\n WHERE\n eventtime >= '" . $Day->thisDay(TRUE) . "'\n AND\n eventtime < '" . $Day->nextDay(TRUE) . "';"; // An array simulating data from a database $result = array(array('eventtime' => mktime(9, 0, 0, 10, 24, 2003), 'entry' => 'Meeting with sales team'), array('eventtime' => mktime(11, 0, 0, 10, 24, 2003), 'entry' => 'Conference call with Widget Inc.'), array('eventtime' => mktime(15, 0, 0, 10, 24, 2003), 'entry' => 'Presentation to board of directors')); // An array to place selected hours in $selection = array(); // Loop through the "database result" foreach ($result as $row) { $Hour = new Calendar_Hour(2000, 1, 1, 1); // Create Hour with dummy values $Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp // Create the decorator, passing it the Hour $DiaryEvent = new DiaryEvent($Hour); // Attach the payload $DiaryEvent->setEntry($row['entry']); // Add the decorator to the selection $selection[] = $DiaryEvent; } // Build the hours in that day, passing the selection $Day->build($selection); ?> <!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> <caption><b>Your Schedule for <?php
function renderDayView($y, $m, $d, &$used_hours_arr) { global $TemplateDir, $template, $WebUploadDir, $WebTemplateDir, $WebBaseDir, $ClassDir, $i18n, $ActiveOption, $userid; include_once $ClassDir . "URLHelper.class.php"; // Create a day to view the hours for $Day =& new Calendar_Day($y, $m, $d); $selection = array(); // search specify day webcasts $apf_schedule = DB_DataObject::factory('ApfSchedule'); $apf_schedule->setPublishDate(DB_DataObject_Cast::date($y, $m, $d)); // $apf_schedule->debugLevel(4); $apf_schedule->setUserid($userid); $apf_schedule->find(); $result = array(); $SHOW_CONFIRM_BUTTON = true; $selected_hours = 0; while ($apf_schedule->fetch()) { $row = $apf_schedule->toArray(); // Var_Dump::display($row); $start_hour = $this->getHourByTime($apf_schedule->getPublishStarttime()); $end_hour = $this->getHourByTime($apf_schedule->getPublishEndtime()); if ($row['webcast_status'] != 'file' && !$row['webcast_file']) { $SHOW_CONFIRM_BUTTON = false; } for ($index = $start_hour; $index <= $end_hour; $index++) { $used_hours_arr["{$index}:00:00"] = "{$index}:00"; } $selected_hours += $end_hour - $start_hour + 1; $Hour = new Calendar_Hour(2000, 1, 1, 1); // Create Hour with dummy values $Hour->setTimeStamp(mktime($start_hour, 0, 0, $m, $d, $y)); // Set the real time with setTimeStamp // Create the decorator, passing it the Hour $DiaryEvent = new DiaryEvent($Hour); // Attach the payload $DiaryEvent->setEndHour($end_hour); $DiaryEvent->setID($row['id']); $DiaryEvent->setStatu($row['active']); $DiaryEvent->setImages($row['image'] ? popFile($WebUploadDir . $row['image']) : ""); $DiaryEvent->setEntry("<a href=\"{$WebBaseDir}/schedule/apf_schedule/list/" . $row['id'] . "?y={$y}&m={$m}&d={$d}\">" . $apf_schedule->getTitle() . "</a>"); // Add the decorator to the selection $selection[] = $DiaryEvent; } if ($selected_hours < 24) { $SHOW_CONFIRM_BUTTON = false; } if ($SHOW_CONFIRM_BUTTON) { $template->setVar(array("CONFIRM_LINK" => '<li><input type="submit" name="save" value="Status To Confirm" class="admin_action_cancel" onclick="if (confirm(\'Are you sure?\')) { document.admin_list_form.todo.value=\'confirm\';document.admin_list_form.submit(); };return false;" /></li>')); } $Day->build($selection); $Day_String = ""; $DayViewTitle = date('D d F Y', $Day->thisDay(TRUE)); $temp_end_hour = ""; while ($Hour =& $Day->fetch()) { $hour = $Hour->thisHour(); $minute = $Hour->thisMinute(); // Office hours only... if ($hour >= 0 && $hour <= 24) { $Day_String .= "<tr class=\"calnone\">\n"; $Day_String .= "<td>{$hour}:{$minute}</td>\n"; // If the hour is selected, call the decorator method... if ($Hour->isSelected()) { $temp_end_hour = $Hour->getEndHour(); $merge_hour = $temp_end_hour - $hour + 1; $css_class_name = "calentryfilled_" . $Hour->getStatu(); $Day_String .= "<td rowspan=\"{$merge_hour}\" class=\"{$css_class_name}\"><INPUT TYPE=\"checkbox\" NAME=\"SelectID[]\" value=\"" . $Hour->getID() . "\"></td><td class=\"{$css_class_name}\" rowspan=\"{$merge_hour}\">" . $Hour->getEntry() . "</td><td rowspan=\"{$merge_hour}\"> " . $Hour->getImages() . "</td><td rowspan=\"{$merge_hour}\"> " . $ActiveOption[$Hour->getStatu()] . "</td><td rowspan=\"{$merge_hour}\"><ul class=\"admin_td_actions\">\n <li><a onclick=\"if (confirm('Are you sure?')) { f = document.createElement('form'); document.body.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;\" href=\"{$WebBaseDir}/schedule/apf_schedule/del/" . $Hour->getID() . "?y={$y}&m={$m}&d={$d}\"><img alt=\"delete\" title=\"delete\" src=\"" . URLHelper::getWebBaseURL() . $WebTemplateDir . "/images/delete_icon.png\" /></a></li>\n</ul></td>\n"; } else { if ($temp_end_hour && $hour <= $temp_end_hour) { $Day_String .= ""; } else { $Day_String .= "<td> </td><td> </td><td> </td><td> </td><td> </td>\n"; } } $Day_String .= "</tr>\n"; } } $header_time = $i18n->_("Time"); $header_entry = $i18n->_("Entry"); $header_image = $i18n->_("Image"); $header_status = $i18n->_("Status"); $header_action = $i18n->_("Action"); $header_schedule_for = $i18n->_("YourScheduleFor"); $calendar_str = <<<EOD <table> <caption><b>{$header_schedule_for}{$DayViewTitle} </b></caption> <tr class="calentryhead"> <th width="8%">{$header_time}</th> <th width="1%"> <input type="checkbox" onClick="selectAll(this.checked,'SelectID[]')"/></th> <th>{$header_entry}</th> <th width="10%">{$header_image}</th> <th width="10%">{$header_status}</th> <th width="10%">{$header_action}</th> </tr> {$Day_String} </table> EOD; return $calendar_str; }