You are here

function availability_calendar_get_referring_field in Availability Calendars 7.5

Returns the field name of the field that refers to the given calendar id.

The search can be restricted to a given set of fields by passing in a 2nd parameter.

Parameters

int $cid:

array|NULL $restrict: An array of fields to restrict the search to. NULL if the search should not be restricted. An empty array restricts the search to NO fields at all and thus will always return FALSE!

Return value

string|false The name of the field or false if no field refers to this calendar.

2 calls to availability_calendar_get_referring_field()
AvailabilityCalendarAlterFieldFilter::alterItems in ./availability_calendar_alter_field_filter.inc
Alter items before indexing.
availability_calendar_calendar_entity_property_filtered_availability_get in ./availability_calendar.entity.inc
Entity property getter callback for the 'filtered availability' property.

File

./availability_calendar.entity.inc, line 260
Contains Entity API and Search API hooks and callbacks.

Code

function availability_calendar_get_referring_field($cid, $restrict = NULL) {
  $fields = is_array($restrict) ? $restrict : availability_calendar_get_fields_by_type('availability_calendar_calendar');
  foreach ($fields as $field_name) {
    $query = new EntityFieldQuery();
    $query
      ->fieldCondition($field_name, 'cid', $cid, '=');
    $result = $query
      ->execute();
    if (!empty($result)) {
      return $field_name;
    }
  }
  return FALSE;
}