You are here

function availability_calendar_get_states in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 availability_calendar.inc \availability_calendar_get_states()
  2. 7.4 availability_calendar.inc \availability_calendar_get_states()

Returns an array of records (or labels) of states keyed by sid.

The results can be processed or filtered based on arguments passed in:

  • bool: filter on is_available
  • string: process array based on the value of the string: 'label': only return label, not a record array 'JavaScript': convert to JavaScript syntax: real booleans and camelCase
  • array: filter on sid (array keys should be a list of the allowed sid's)

Multiple filters/processors can be passed.

Parameters

boolean|string|array $filter,...: Processing or filtering to be done on the list of states.

Return value

array Array of records keyed by the sid.

22 calls to availability_calendar_get_states()
AvailabilityCalendarCssGenerator::createStatesCss in ./availability_calendar.styles.inc
AvailabilityCalendarCssGenerator::createStatesRtlCss in ./availability_calendar.styles.inc
AvailabilityCalendarFieldHandler::prepare in ./availability_calendar_migrate_field_handlers.inc
Prepares data accordingly for the field API.
AvailabilityCalendarICalFeedsProcessor::configDefaults in ./AvailabilityCalendarICalFeedsProcessor.inc
AvailabilityCalendarICalFeedsProcessor::configForm in ./AvailabilityCalendarICalFeedsProcessor.inc

... See full list

1 string reference to 'availability_calendar_get_states'
availability_calendar_update_states in ./availability_calendar.inc
Updates the set of states.

File

./availability_calendar.inc, line 355

Code

function availability_calendar_get_states($filter = NULL) {
  $states =& drupal_static(__FUNCTION__);
  if ($states === NULL) {
    $states = db_select('availability_calendar_state')
      ->fields('availability_calendar_state')
      ->orderBy('weight')
      ->execute()
      ->fetchAllAssoc('sid', PDO::FETCH_ASSOC);
  }
  $result = $states;
  foreach (func_get_args() as $arg) {
    if (is_bool($arg)) {

      // filter out non-available states
      $result = array_filter($result, $arg ? 'availability_calendar_filter_available' : 'availability_calendar_filter_non_available');
    }
    else {
      if (is_array($arg)) {

        // Filter out non-allowed states. If no states are passed in, all states
        // are allowed.
        if (!empty($arg)) {
          $result = array_intersect_key($result, $arg);
        }
      }
      else {
        if ($arg !== NULL) {
          array_walk($result, 'availability_calendar_convert_state', $arg);
        }
      }
    }
  }

  // Users may expect the array to be in its "initial" state.
  reset($result);
  return $result;
}