You are here

function biblio_diff in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 biblio.module \biblio_diff()

An implementation of hook_diff (from the diff module)

Parameters

$old_node:

$new_node:

Return value

unknown_type

File

./biblio.module, line 2295

Code

function biblio_diff(&$old_node, &$new_node) {
  require_once drupal_get_path('module', 'biblio') . '/biblio.contributors.inc';
  $result = array();
  $old_type = db_fetch_object(db_query('SELECT name FROM {biblio_types} where tid = %d', $old_node->biblio_type));
  $new_type = db_fetch_object(db_query('SELECT name FROM {biblio_types} where tid = %d', $new_node->biblio_type));
  $result['biblio_type'] = array(
    '#name' => 'Publication Type',
    '#old' => array(
      $old_type->name,
    ),
    '#new' => array(
      $new_type->name,
    ),
    '#format' => array(
      'show_header' => FALSE,
    ),
  );
  $old_node->biblio_contributors = biblio_load_contributors($old_node->vid);
  $new_node->biblio_contributors = biblio_load_contributors($new_node->vid);
  $db_result = db_query('SELECT b.name, btd.title, bt.weight
                      FROM {biblio_fields} b
                      INNER JOIN {biblio_field_type} bt ON bt.fid=b.fid
                      INNER JOIN {biblio_field_type_data} btd ON btd.ftdid=bt.ftdid
                      WHERE bt.tid=%d ORDER BY weight', $old_node->biblio_type);
  while ($field = db_fetch_object($db_result)) {
    $name = $field->name;
    $old = $new = '';
    if ($field->type == 'contrib_widget') {
      foreach ((array) $old_node->biblio_contributors[$field->fid] as $auth) {
        $old .= $auth['name'] . ' ';
      }
      foreach ((array) $old_node->biblio_contributors[$field->fid] as $auth) {
        $new .= $auth['name'] . ' ';
      }
    }
    else {
      $old = $old_node->{$name};
      $new = $new_node->{$name};
    }
    $result[$name] = array(
      '#name' => $field->title,
      '#old' => explode("\n", $old),
      '#new' => explode("\n", $new),
    );
  }
  return $result;
}