You are here

function properties_compare_is_comparable in Dynamic properties 7

Checks if two entites can be compared.

Parameters

$entity_type1: Entity type of first entity.

$entity1: Object of first entity.

$entity_type2: Entity type of second entity.

$entity2: Object of second entity.

Return value

TRUE if entities can be compared, FALSE otherwise.

2 calls to properties_compare_is_comparable()
properties_compare_list_form in properties_compare/properties_compare.module
Form builder function; display comparison list.
properties_compare_page in properties_compare/properties_compare.pages.inc
Page callback, display comparison table.

File

properties_compare/properties_compare.module, line 377
Module file for privatemsg_compare module.

Code

function properties_compare_is_comparable($entity_type1, $entity1, $entity_type2, $entity2) {

  // First, check entity type.
  if ($entity_type1 != $entity_type2) {
    return FALSE;
  }

  // Loop over hook implementations. They can either return TRUE (allow), FALSE
  // (deny) or NULL (ignore). Access is allowed if at least one implementation
  // returns TRUE and none returns FALSE. If neither happens, the check falls
  // back to the default category check.
  $allow = FALSE;
  foreach (module_implements('properties_compare_comparable') as $module) {
    $return = module_invoke($module, 'properties_compare_comparable', $entity_type1, $entity1, $entity_type2, $entity2);
    if ($return === FALSE) {
      return FALSE;
    }
    elseif ($return === TRUE) {
      $allow = TRUE;
    }
  }
  if ($allow) {
    return TRUE;
  }

  // No hook returned something, check if there are any shared categories, if
  // yes, allow comparing.
  $shared_category = FALSE;
  foreach (properties_extract_fields($entity_type1, $entity1) as $field_content1) {
    foreach ($field_content1 as $property1) {
      foreach (properties_extract_fields($entity_type2, $entity2) as $field_content2) {
        foreach ($field_content2 as $property2) {
          if ($property1['category'] == $property2['category']) {
            $shared_category = TRUE;
            break 4;
          }
        }
      }
    }
  }
  if (!$shared_category) {
    return FALSE;
  }
  return TRUE;
}