function theme_availability_calendar_month in Availability Calendars 7.4
Same name and namespace in other branches
- 7.5 availability_calendar.theme.inc \theme_availability_calendar_month()
- 7.3 availability_calendar.theme.inc \theme_availability_calendar_month()
Themes the calendar for a given month.
Parameters
array $variables:
Return value
string
1 theme call to theme_availability_calendar_month()
- theme_availability_calendar_months in ./
availability_calendar.theme.inc - Themes a number of months of an availability calendar field.
File
- ./
availability_calendar.theme.inc, line 200
Code
function theme_availability_calendar_month($variables) {
$year = $variables['year'];
$month = $variables['month'];
$settings = $variables['settings'];
$availability = $variables['availability'];
// Get the parts of the table.
$caption = format_date(mktime(12, 0, 0, $month, 1, $year), 'availability_calendar_month_caption');
$header = availability_calendar_month_header($settings);
$cells = availability_calendar_month_cells($year, $month, $availability, $settings);
$rows = array_chunk($cells, 7, TRUE);
// Ensure that each month has 6 rows. The last rows can be completely empty.
while (count($rows) < 6) {
$rows[] = array(
array(
'data' => '<div></div>',
'class' => array(
'cal-empty',
),
'colspan' => 7,
),
);
}
// Prepend week numbers: we work with ISO-8601 week numbers that assume that
// a week starts on a monday. If the first_day_of_week is a friday, saturday,
// or sunday, we take the week number of the last day in that row, otherwise
// we take the week number of the first day in that row.
if ($settings['show_week_number']) {
array_unshift($header, array(
'data' => t('Nr.'),
'class' => array(
'cal-weekno-header',
),
));
foreach ($rows as &$row) {
if (count($row) > 1) {
if ($settings['first_day_of_week'] < 5) {
reset($row);
}
else {
end($row);
}
$day_to_use = new DateTime(key($row));
array_unshift($row, array(
'data' => $day_to_use
->format('W'),
'header' => TRUE,
));
}
else {
array_unshift($row, array(
'data' => ' ',
'header' => TRUE,
'class' => array(
'cal-empty',
),
));
}
}
}
// Prevent the striping that most themes add.
foreach ($rows as &$row) {
$row = array(
'no_striping' => TRUE,
'data' => $row,
);
}
// Theme the table and wrap it to allow for better styling.
$month2 = sprintf('%02d', $month);
$output = "<div class=\"cal-month\" data-cal-id=\"{$variables['cid']}\" data-cal-year=\"{$year}\" data-cal-month=\"{$month2}\">\n";
$output .= theme('table', array(
'caption' => $caption,
'header' => $header,
'rows' => $rows,
'sticky' => FALSE,
));
$output .= "\n</div>\n";
return $output;
}