You are here

public static function BiblioStyleBase::generateBiblioMd5 in Bibliography Module 7.3

Generates an md5 string based on a biblio object. The md5 is later used to determine whether or not two Biblio objects are the same and prevent duplications.

Parameters

$biblio: Biblio object.

Return value

MD5 string that represents the given biblio.

2 calls to BiblioStyleBase::generateBiblioMd5()
Biblio::save in includes/biblio.controller.inc
Override Entity:save().
BiblioStyleBase::isDuplicate in plugins/biblio_style/abstract.inc
Searches for a biblio object identical to the given one.

File

plugins/biblio_style/abstract.inc, line 104

Class

BiblioStyleBase
An abstract implementation of MessageNotifierInterface.

Code

public static function generateBiblioMd5(Biblio $biblio) {
  $clone = clone $biblio;

  // Remove unique or temporary data.
  unset($clone->bid);
  unset($clone->cache);
  unset($clone->cache_id);
  unset($clone->changed);
  unset($clone->created);
  unset($clone->is_new);
  unset($clone->md5);
  unset($clone->_skip_cache);
  unset($clone->biblio_status);
  if (!empty($clone->contributor_field_collection)) {

    // Run through field collection items and get the contributor's target
    // IDs. We can't use the wrapper, as the entities might not be saved yet
    // so we access the fields directly.
    $contributors = array();
    foreach ($clone->contributor_field_collection[LANGUAGE_NONE] as $value) {
      $entity = !empty($value['entity']) ? $value['entity'] : entity_load_single('field_collection_item', $value['value']);
      $contributors[] = array(
        $entity->biblio_contributor[LANGUAGE_NONE][0]['target_id'],
        $entity->biblio_contributor_role[LANGUAGE_NONE][0]['target_id'],
      );
    }

    // Replace field collection item in clone with the contributor's target IDs.
    $clone->contributor_field_collection = $contributors;
  }
  $md5 = md5(serialize($clone));
  return $md5;
}