room_id, $this->start_date, $this->end_date);
// We want to build an array containing all the data we want to show and then spit it out.
$this->map = new Map($this->start_date, $this->end_date, $resolution);
$this->map->addEntries($entries);
}
public function innerHTML(): string
{
global $column_labels_both_ends;
// Table header
$thead = 'headerRowHTML();
$thead .= $header_row;
$thead .= "\n";
// Table body
$tbody = $this->bodyHTML();
// Table footer
$tfoot = ($column_labels_both_ends) ? "
\n$header_row\n" : '';
return $thead . $tfoot . $tbody;
}
private function bodyHTML(): string
{
global $year_start, $datetime_formats, $row_labels_both_sides;
$html = "\n";
// The variables for the link query string
$vars = [
'view_all' => $this->view_all,
'area' => $this->area_id,
'room' => $this->room_id
];
$date = (new DateTime())->setDate($this->year, $this->month, 1); // Set to first day of month
$date->setMonthYearStart($year_start);
$d = 0; // Need to keep track of the day in the Calendar interval (zero indexed)
for ($i=0; $i<$this->n_months; $i++)
{
$html .= "\n";
$vars['page_date'] = $date->getISODate();
$vars['view'] = 'month';
$link = 'index.php?' . http_build_query($vars, '', '&');
$link = multisite($link);
$month_name = datetime_format($datetime_formats['month_name_year_view'], $date->getTimestamp());
$first_last_html = '| ' . escape_html($month_name) . " | \n";
$html .= $first_last_html;
for ($j=1; $j<=$date->getDaysInMonth(); $j++)
{
$date->setDay($j);
// Although it's possible to add date classes (eg for weekends and holidays) the result
// doesn't look very good on the screen because the weekdays aren't all in the same column.
$html .= "";
$vars['page_date'] = $date->getISODate();
$vars['view'] = 'day';
$link = 'index.php?' . http_build_query($vars, '', '&');
$link = multisite($link);
$html .= '';
$html .= $this->flexDivsHTML($this->room_id, $d, $d);
$html .= '';
$html .= " | ";
$d++;
}
// Fill in the remaining, invalid, days
while ($j <= 31)
{
$html .= ' | ';
$j++;
}
// The right-hand header column, if required
if ($row_labels_both_sides)
{
$html .= $first_last_html;
}
$html .= "
\n";
$date->modify('+1 day'); // Advance to the next month
}
$html .= "\n";
return $html;
}
private function headerRowHTML(string $label='') : string
{
global $row_labels_both_sides;
$html = "\n";
// The left-hand header column
$first_last_html = '| ' . escape_html($label) . " | \n";
$html .= $first_last_html;
// Choose a month (January) with 31 days and cycle through all the days.
// We can't add a link to the header cells because we don't know which month they refer to.
for ($d=1; $d <= 31; $d++)
{
$t = mktime(12, 0, 0, 1, $d, $this->year);
$html .= "" . escape_html($this->getDate($t)) . " | \n";
}
// The right-hand header column, if required
if ($row_labels_both_sides)
{
$html .= $first_last_html;
}
$html .= "
\n";
return $html;
}
}