function availability_calendars_get_node_states in Availability Calendars 7.2
Same name and namespace in other branches
- 6.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 $calendar_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 337 - General helper methods for Availability Calendars, like database access and settings.
Code
function availability_calendars_get_node_states($calendar_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;
}
// Get the states from the database.
$states_db = db_select('availability_calendars_day')
->fields('availability_calendars_day', array(
'date',
'status',
))
->condition('nid', $calendar_nid)
->condition('date', array(
$start_date,
$end_date,
), 'BETWEEN')
->execute()
->fetchAllKeyed();
// Merge the 2 arrays.
$states = array_merge($states, $states_db);
return $states;
}