function availability_calendars_get_node_states in Availability Calendars 6.2
Same name and namespace in other branches
- 7.2 availability_calendars.inc \availability_calendars_get_node_states()
Returns the states for the calendar for the given node in the given month. The returned array will be completely filled, so no checking is necessary.
Parameters
int $nid:
int $year:
int $month:
object $settings settings (containing among others the default status):
Return value
array array with 28 to 31 day states (string) keyed by the day of the month number (int).
2 calls to availability_calendars_get_node_states()
- availability_calendars_node_edit_calendar_month_form in ./
availability_calendars.node.inc - Populates the node edit calendar month form.
- theme_availability_calendars_month in ./
availability_calendars.page.inc - Themes the calendar for a given month.
File
- ./
availability_calendars.inc, line 184 - General helper methods for Availability Calendars, like database access and settings.
Code
function availability_calendars_get_node_states($nid, $year, $month, $settings) {
$start_date = date(AC_ISODATE, mktime(0, 0, 0, $month, 1, $year));
$end_date = date(AC_ISODATE, mktime(0, 0, 0, $month + 1, 0, $year));
// Works
$number_of_days = (int) substr($end_date, 8);
// Create an array for all days of the month with the default status.
$states = array();
for ($day = 1; $day <= $number_of_days; $day++) {
$states[date(AC_ISODATE, mktime(0, 0, 0, $month, $day, $year))] = $settings->defaultstatus;
}
$result = db_query("SELECT date, status FROM {availability_calendars_day} WHERE nid = %d AND date BETWEEN '%s' AND '%s'", $nid, $start_date, $end_date);
while ($state = db_fetch_array($result)) {
$states[$state['date']] = $state['status'];
}
return $states;
}