function tripal_pub_get_publication_array
2.x tripal_pub.pub_importers.inc | tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) |
3.x tripal_chado.pub_importers.inc | tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) |
1.x tripal_pub.api.inc | tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) |
This function generates an array suitable for use with the tripal_pub_create_citation function for any publication already stored in the Chado tables.
Parameters
$pub_id: The publication ID
$skip_existing: Set to TRUE to skip publications that already have a citation in the pubprop table. Set to FALSE to generate a citation regardless if the citation already exists.
Return value
An array suitable for the trpial_pub_create_citation function. On failure returns FALSE.
1 call to tripal_pub_get_publication_array()
- chado_pub_create_citations in tripal_chado/
api/ modules/ tripal_chado.pub.api.inc - Launch the Tripal job to generate citations.
File
- tripal_chado/
includes/ loaders/ tripal_chado.pub_importers.inc, line 1305 - Management of importers
Code
function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
$options = array('return_array' => 1);
// ---------------------------------
// get the publication
// ---------------------------------
$values = array('pub_id' => $pub_id);
$pub = chado_generate_var('pub', $values);
// expand the title
$pub = chado_expand_var($pub, 'field', 'pub.title');
$pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
$pub = chado_expand_var($pub, 'field', 'pub.uniquename');
$pub_array = array();
if (trim($pub->title)) {
$pub_array['Title'] = $pub->title;
}
if (trim($pub->volumetitle)) {
$pub_array['Volume Title'] = $pub->volumetitle;
}
if (trim($pub->volume)) {
$pub_array['Volume'] = $pub->volume;
}
if (trim($pub->series_name)) {
$pub_array['Series Name'] = $pub->series_name;
}
if (trim($pub->issue)) {
$pub_array['Issue'] = $pub->issue;
}
if (trim($pub->pyear)) {
$pub_array['Year'] = $pub->pyear;
}
if (trim($pub->pages)) {
$pub_array['Pages'] = $pub->pages;
}
if (trim($pub->miniref)) {
$pub_array['Mini Ref'] = $pub->miniref;
}
if (trim($pub->uniquename)) {
$pub_array['Uniquename'] = $pub->uniquename;
}
$pub_array['Publication Type'][] = $pub->type_id->name;
// ---------------------------------
// get the citation
// ---------------------------------
$values = array(
'pub_id' => $pub->pub_id,
'type_id' => array(
'name' => 'Citation',
),
);
$citation = chado_generate_var('pubprop', $values);
if ($citation) {
$citation = chado_expand_var($citation, 'field', 'pubprop.value', $options);
if (count($citation) > 1) {
tripal_report_error('tripal_pub', TRIPAL_ERROR, "Publication has multiple citations already: %pub_id",
array('%pub_id' => $pubid));
return FALSE;
}
elseif (count($citation) == 1 and $skip_existing == TRUE) {
// skip this publication, it already has a citation
return FALSE;
}
}
// ---------------------------------
// get the publication types
// ---------------------------------
$values = array(
'pub_id' => $pub->pub_id,
'type_id' => array(
'name' => 'Publication Type',
),
);
$ptypes = chado_generate_var('pubprop', $values, $options);
if ($ptypes) {
$ptypes = chado_expand_var($ptypes, 'field', 'pubprop.value', $options);
foreach ($ptypes as $ptype) {
$pub_array['Publication Type'][] = $ptype->value;
}
}
// ---------------------------------
// get the authors list
// ---------------------------------
$values = array(
'pub_id' => $pub->pub_id,
'type_id' => array(
'name' => 'Authors',
),
);
$authors = chado_generate_var('pubprop', $values);
$authors = chado_expand_var($authors, 'field', 'pubprop.value', $options);
if (count($authors) > 1) {
tripal_report_error('tripal_pub', TRIPAL_ERROR, "Publication has multiple author lists. It should have only one list: %pub_id",
array('%pub_id' => $pubid));
return FALSE;
}
else if (trim($authors->value)) {
$pub_array['Authors'] = $authors->value;
}
// if there is no 'Author's property then try to retreive authors from the pubauthor table
else {
$sql = "
SELECT string_agg(surname || ' ' || givennames, ', ')
FROM {pubauthor}
WHERE pub_id = :pub_id
GROUP BY pub_id
";
$au = chado_query($sql, array(':pub_id' => $pub_id))->fetchField();
if ($au) {
$pub_array['Authors'] = $au;
}
}
//Get other props
$props = array(
'Journal Abbreviation',
'Elocation',
'Media Code',
'Conference Name',
'Keywords',
'Series Name',
'pISSN',
'Publication Date',
'Journal Code',
'Journal Alias',
'Journal Country',
'Published Location',
'Publication Model',
'Language Abbr',
'Alias',
'Publication Dbxref',
'Copyright',
'Abstract',
'Notes',
'Citation',
'Language',
'URL',
'eISSN',
'DOI',
'ISSN',
'Publication Code',
'Comments',
'Publisher',
'Media Alias',
'Original Title'
);
foreach ($props as $prop) {
$sql =
"SELECT value FROM {pubprop}
WHERE type_id =
(SELECT cvterm_id
FROM {cvterm}
WHERE name = :cvtname AND cv_id =
(SELECT cv_id
FROM {cv}
WHERE name = 'tripal_pub'
)
)
AND pub_id = :pub_id
";
$val = trim(chado_query($sql, array(':cvtname' => $prop, ':pub_id' => $pub->pub_id))->fetchField());
if ($val) {
$pub_array[$prop] = $val;
}
}
return $pub_array;
}