function facetapi_requirement_property in Facet API 7
Same name and namespace in other branches
- 6.3 facetapi.requirements.inc \facetapi_requirement_property()
 - 7.2 facetapi.requirements.inc \facetapi_requirement_property()
 
Checks the equality of one or more properties.
Parameters
array $definition: The facet or realm definition.
array $options: An array of values keyed by properties that are being compared.
Return value
TRUE if all property values are equal, FALSE otherwise.
2 calls to facetapi_requirement_property()
- facetapi_requirement_facet_property in ./
facetapi.requirements.inc  - Checks equality of one or more facet properties.
 - facetapi_requirement_realm_property in ./
facetapi.requirements.inc  - Checks equality of one or more realm properties.
 
File
- ./
facetapi.requirements.inc, line 53  - Requirement checking callbacks.
 
Code
function facetapi_requirement_property(array $definition, array $options, $operator) {
  $passed = TRUE;
  foreach ($options as $key => $requirement) {
    $condition = $definition[$key];
    // we always expect an array
    if (!is_array($requirement)) {
      $requirement = array(
        $requirement,
      );
    }
    // we always expect an array
    if (!is_array($condition)) {
      $condition = array(
        $condition,
      );
    }
    // if the keys are numeric, map assoc them so intersect works
    if (is_int(key($requirement))) {
      $requirement = drupal_map_assoc($requirement);
    }
    // if the keys are numeric, map assoc them so intersect works
    if (is_int(key($condition))) {
      $condition = drupal_map_assoc($condition);
    }
    // Check if it is either an AND or OR operation and act accordingly
    if ($operator == 'AND') {
      if (array_intersect_key($condition, $requirement) != $requirement) {
        $passed = FALSE;
        break;
      }
    }
    elseif ($operator == 'OR') {
      if (!array_intersect_key($condition, $requirement)) {
        $passed = FALSE;
        break;
      }
    }
  }
  return $passed;
}