function chado_pub_validate_check_duplicate
2.x tripal_pub.chado_node.inc | chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) |
3.x tripal_pub.chado_node.inc | chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) |
Check for duplicate publications. To be called from hook_validate(). Sets the form error if a duplicate
Parameters
$title: The title of the publication
$pyear: The year the publication was published
$series_name: The series name of the publication
$cvterm: The type of publication
$pub_id: the unique id of the publication
Related topics
1 call to chado_pub_validate_check_duplicate()
- chado_pub_validate in legacy/
tripal_pub/ includes/ tripal_pub.chado_node.inc - Implements hook_validate().
File
- legacy/
tripal_pub/ includes/ tripal_pub.chado_node.inc, line 493 - Implements Drupal Node hooks to create the chado_analysis node content type.
Code
function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvterm, $pub_id = NULL) {
$pub_details = array(
'Title' => $title,
'Year' => $pyear,
'Series Name' => $series_name,
'Publication Type' => $cvterm->name,
);
// TODO: need to include the Publication Dbxref in the $pub_details as well
$pub_ids = tripal_publication_exists($pub_details);
// if we found only one publication and it is our publication then return, we're good.
if (count($pub_ids) == 1 and in_array($pub_id, $pub_ids)) {
return;
}
if (count($pub_ids) == 0) {
// there is no match so return
return;
}
// return an appropriate message based on the unique constraint settings
$import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
switch ($import_dups_check) {
case 'title_year':
$message = t('A publication with this title and publication year already exists.');
form_set_error('pubtitle', $message);
break;
case 'title_year_type':
$message = t('A publication with this title, type and publication year already exists.');
form_set_error('pubtitle', $message);
break;
case 'title_year_media':
$message = t('A publication with this title, media name (e.g. Journal Name) and publication year already exists.');
form_set_error('pubtitle', $message);
break;
}
}