1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132 |
- <?php
- function tripal_get_publication($identifiers, $options = array()) {
-
- if (!is_array($identifiers)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The identifier passed in is expected to be an array with the key
- matching a column name in the pub table (ie: pub_id or name). You passed in %identifier.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
- elseif (empty($identifiers)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: You did not pass in anything to identify the publication you want. The identifier
- is expected to be an array with the key matching a column name in the pub table
- (ie: pub_id or name). You passed in %identifier.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
-
- if (array_key_exists('property', $identifiers)) {
- $property = $identifiers['property'];
- unset($identifiers['property']);
- $pub = chado_get_record_with_property(
- array('table' => 'pub', 'base_records' => $identifiers),
- array('type_name' => $property),
- $options
- );
- }
- elseif (array_key_exists('dbxref', $identifiers)) {
- if(preg_match('/^(.*?):(.*?)$/', $identifiers['dbxref'], $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
-
- $values = array(
- 'accession' => $accession,
- 'db_id' => array(
- 'name' => $dbname
- ),
- );
- $dbxref = chado_select_record('dbxref', array('dbxref_id'), $values);
- if (count($dbxref) == 0) {
- return FALSE;
- }
- $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), array('dbxref_id' => $dbxref[0]->dbxref_id));
- if (count($pub_dbxref) == 0) {
- return FALSE;
- }
- $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
- }
- else {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The dbxref identifier is not correctly formatted.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
- }
- elseif (array_key_exists('dbxref_id', $identifiers)) {
-
- $values = array('dbxref_id' => $identifiers['dbxref_id']);
- $pub_dbxref = chado_select_record('pub_dbxref', array('pub_id'), $values);
-
- if (count($pub_dbxref) > 0) {
- $pub = chado_generate_var('pub', array('pub_id' => $pub_dbxref[0]->pub_id), $options);
- }
- else {
- return FALSE;
- }
- }
-
- else {
-
- $pub = chado_generate_var('pub', $identifiers, $options);
- }
-
- if (is_array($pub)) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: The identifiers did not find a single unique record. Identifiers passed: %identifier.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
-
- elseif ($pub === FALSE) {
- tripal_report_error('tripal_pub_api', TRIPAL_ERROR,
- "chado_get_publication: Could not find a publication using the identifiers
- provided. Check that the identifiers are correct. Identifiers passed: %identifier.",
- array('%identifier'=> print_r($identifiers, TRUE))
- );
- }
-
- else {
- return $pub;
- }
- }
- function tripal_publication_exists($pub_details) {
-
- if (array_key_exists('Publication Dbxref', $pub_details)) {
- $pub = tripal_get_publication(array('dbxref' => $pub_details['Publication Dbxref']));
- if($pub) {
- return array($pub->pub_id);
- }
- }
-
- if (array_key_exists('Citation', $pub_details)) {
- $pub = tripal_get_publication(array('uniquename' => $pub_details['Citation']));
- if($pub) {
- return array($pub->pub_id);
- }
- }
-
- if (array_key_exists('Publication Type', $pub_details)) {
- $type_name = '';
- if(is_array($pub_details['Publication Type'])) {
- $type_name = $pub_details['Publication Type'][0];
- }
- else {
- $type_name = $pub_details['Publication Type'];
- }
- $identifiers = array(
- 'name' => $type_name,
- 'cv_id' => array(
- 'name' => 'tripal_pub',
- ),
- );
- $pub_type = tripal_get_cvterm($identifiers);
- }
- else {
- tripal_report_error('tripal_pub', TRIPAL_ERROR,
- "tripal_publication_exists(): The Publication Type is a " .
- "required property but is missing", array());
- return array();
- }
- if (!$pub_type) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR,
- "tripal_publication_exists(): Cannot find publication type: '%type'",
- array('%type' => $pub_details['Publication Type'][0]));
- return array();
- }
-
- $series_name = '';
- if (array_key_exists('Series Name', $pub_details)) {
- $series_name = substr($pub_details['Series Name'], 0, 255);
- }
- if (array_key_exists('Journal Name', $pub_details)) {
- $series_name = substr($pub_details['Journal Name'], 0, 255);
- }
- if (array_key_exists('Conference Name', $pub_details)) {
- $series_name = substr($pub_details['Conference Name'], 0, 255);
- }
-
- $import_dups_check = variable_get('tripal_pub_import_duplicate_check', 'title_year_media');
- $pubs = array();
- switch ($import_dups_check) {
- case 'title_year':
- $identifiers = array(
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year']
- );
- $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
- break;
- case 'title_year_type':
- $identifiers = array(
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year'],
- 'type_id' => $pub_type->cvterm_id,
- );
- $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
- break;
- case 'title_year_media':
- $identifiers = array(
- 'title' => $pub_details['Title'],
- 'pyear' => $pub_details['Year'],
- 'series_name' => $series_name,
- );
- $pubs = chado_select_record('pub', array('pub_id'), $identifiers);
- break;
- }
- $return = array();
- foreach ($pubs as $pub) {
- $return[] = $pub->pub_id;
- }
- return $return;
- }
- function tripal_autocomplete_pub($string = '') {
- $items = array();
- $sql = "
- SELECT pub_id, title, uniquename
- FROM {pub}
- WHERE lower(title) like lower(:str)
- ORDER by title
- LIMIT 25 OFFSET 0
- ";
- $pubs = chado_query($sql, array(':str' => $string . '%'));
- while ($pub = $pubs->fetchObject()) {
- $items[$pub->uniquename] = $pub->uniquename;
- }
- drupal_json_output($items);
- }
- function tripal_import_pub_by_dbxref($pub_dbxref, $do_contact = FALSE, $do_update = TRUE) {
- $num_to_retrieve = 1;
- $pager_id = 0;
- $page = 0;
- $num_pubs = 0;
- $pub_id = NULL;
- module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');
- print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
- "If the load fails or is terminated prematurely then the entire set of \n" .
- "insertions/updates is rolled back and will not be found in the database\n\n";
- $transaction = db_transaction();
- try {
- if(preg_match('/^(.*?):(.*?)$/', $pub_dbxref, $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
- $criteria = array(
- 'num_criteria' => 1,
- 'remote_db' => $dbname,
- 'criteria' => array(
- '1' => array(
- 'search_terms' => "$dbname:$accession",
- 'scope' => 'id',
- 'operation' => '',
- 'is_phrase' => 0,
- ),
- ),
- );
- $remote_db = $criteria['remote_db'];
- $results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
- $pubs = $results['pubs'];
- $search_str = $results['search_str'];
- $total_records = $results['total_records'];
- tripal_pub_add_publications($pubs, $do_contact, $do_update);
- }
-
-
- if (module_exists('tripal_pub')) {
-
- print "Syncing publications with Drupal...\n";
- chado_node_sync_records('pub');
-
- if($do_contact) {
- print "Syncing contacts with Drupal...\n";
- chado_node_sync_records('contact');
- }
- }
- }
- catch (Exception $e) {
- $transaction->rollback();
- print "\n";
- watchdog_exception('T_pub_import', $e);
- print "FAILED: Rolling back database changes...\n";
- return;
- }
- }
- function tripal_execute_active_pub_importers($report_email = FALSE, $do_update = FALSE) {
- $num_to_retrieve = 100;
- $page = 0;
- print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
- "If the load fails or is terminated prematurely then the entire set of \n" .
- "insertions/updates is rolled back and will not be found in the database\n\n";
-
- $transaction = db_transaction();
- try {
-
- $args = array();
- $sql = "SELECT * FROM {tripal_pub_import} WHERE disabled = 0 ";
- $results = db_query($sql, $args);
- $do_contact = FALSE;
- $reports = array();
- foreach ($results as $import) {
- $page = 0;
- print "Executing importer: '" . $import->name . "'\n";
-
- if ($import->do_contact == 1) {
- $do_contact = TRUE;
- }
- $criteria = unserialize($import->criteria);
- $remote_db = $criteria['remote_db'];
- do {
-
- $results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
- $pubs = $results['pubs'];
- $reports[$import->name] = tripal_pub_add_publications($pubs, $import->do_contact, $do_update);
- $page++;
- }
-
-
- while (count($pubs) == $num_to_retrieve);
- }
-
-
-
-
-
- if (module_exists('tripal_pub')) {
- print "Syncing publications with Drupal...\n";
- chado_node_sync_records('pub');
- }
-
- $HTML_report = '';
- if ($report_email) {
- $HTML_report .= "<html>";
- global $base_url;
- foreach ($reports as $importer => $report) {
- $total = count($report['inserted']);
- $HTML_report .= "<b>$total new publications from importer: $importer</b><br><ol>\n";
- foreach ($report['inserted'] as $pub) {
- $item = $pub['Title'];
- if (array_key_exists('pub_id', $pub)) {
- $item = l($pub['Title'], "$base_url/pub/" . $pub['pub_id']);
- }
- $HTML_report .= "<li>$item</li>\n";
- }
- $HTML_report .= "</ol>\n";
- }
- $HTML_report .= "</html>";
- $site_email = variable_get('site_mail', '');
- $params = array(
- 'message' => $HTML_report
- );
- drupal_mail('tripal_pub', 'import_report', $report_email, language_default(), $params, $site_email, TRUE);
- }
-
-
- if (module_exists('tripal_pub')) {
-
- if($do_contact) {
- print "Syncing contacts with Drupal...\n";
- chado_node_sync_records('contact');
- }
- }
- }
- catch (Exception $e) {
- $transaction->rollback();
- print "\n";
- watchdog_exception('T_pub_import', $e);
- print "FAILED: Rolling back database changes...\n";
- return;
- }
- print "Done.\n";
- }
- function tripal_reimport_publications($do_contact = FALSE, $dbxref = NULL, $db = NULL) {
- print "\nNOTE: Loading of publications is performed using a database transaction. \n" .
- "If the load fails or is terminated prematurely then the entire set of \n" .
- "insertions/updates is rolled back and will not be found in the database\n\n";
- $transaction = db_transaction();
- try {
-
- $sql = "
- SELECT DB.name as db_name, DBX.accession
- FROM pub P
- INNER JOIN pub_dbxref PDBX ON P.pub_id = PDBX.pub_id
- INNER JOIN dbxref DBX ON DBX.dbxref_id = PDBX.dbxref_id
- INNER JOIN db DB ON DB.db_id = DBX.db_id
- ";
- $args = array();
- if ($dbxref and preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
- $dbname = $matches[1];
- $accession = $matches[2];
- $sql .= "WHERE DBX.accession = :accession and DB.name = :dbname ";
- $args[':accession'] = $accession;
- $args[':dbname'] = $dbname;
- }
- elseif ($db) {
- $sql .= " WHERE DB.name = :dbname ";
- $args[':dbname'] = $db;
- }
- $sql .= "ORDER BY DB.name, P.pub_id";
- $results = chado_query($sql, $args);
- $num_to_retrieve = 100;
- $i = 0;
- $curr_db = '';
- $ids = array();
- $search = array();
-
- while ($pub = $results->fetchObject()) {
- $accession = $pub->accession;
- $remote_db = $pub->db_name;
-
- $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
- if(!in_array($remote_db, $supported_dbs)) {
- continue;
- }
- $search = array(
- 'num_criteria' => 1,
- 'remote_db' => $remote_db,
- 'criteria' => array(
- '1' => array(
- 'search_terms' => "$remote_db:$accession",
- 'scope' => 'id',
- 'operation' => '',
- 'is_phrase' => 0,
- ),
- ),
- );
- $pubs = tripal_get_remote_pubs($remote_db, $search, 1, 0);
- tripal_pub_add_publications($pubs, $do_contact, TRUE);
- $i++;
- }
-
-
- if (module_exists('tripal_pub')) {
-
- print "Syncing publications with Drupal...\n";
- chado_node_sync_records('pub');
-
- if ($do_contact) {
- print "Syncing contacts with Drupal...\n";
- chado_node_sync_records('contact');
- }
- }
- }
- catch (Exception $e) {
- $transaction->rollback();
- print "\n";
- watchdog_exception('T_pub_import', $e);
- print "FAILED: Rolling back database changes...\n";
- return;
- }
- print "Done.\n";
- }
- function tripal_pub_create_citations($options) {
- $skip_existing = TRUE;
- $sql = "
- SELECT cvterm_id
- FROM {cvterm}
- WHERE
- name = 'Citation' AND
- cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal_pub')
- ";
- $citation_type_id = chado_query($sql)->fetchField();
-
- if ($options == 'all') {
- $sql = "SELECT pub_id FROM {pub} P WHERE pub_id <> 1";
- $skip_existing = FALSE;
- }
-
- else if ($options == 'new') {
- $sql = "
- SELECT pub_id
- FROM {pub} P
- WHERE
- (SELECT value
- FROM {pubprop} PB
- WHERE type_id = :type_id AND P.pub_id = PB.pub_id AND rank = 0) IS NULL
- AND pub_id <> 1
- ";
- $skip_existing = TRUE;
- }
- $result = chado_query($sql, array(':type_id' => $citation_type_id));
- $counter_updated = 0;
- $counter_generated = 0;
- while ($pub = $result->fetchObject()) {
- $pub_arr = tripal_pub_get_publication_array($pub->pub_id, $skip_existing);
- if ($pub_arr) {
- $citation = tripal_pub_create_citation($pub_arr);
- print $citation . "\n\n";
-
- if ($pub_arr['Citation']) {
- $sql = "
- UPDATE {pubprop} SET value = :value
- WHERE pub_id = :pub_id AND type_id = :type_id AND rank = :rank
- ";
- chado_query($sql, array(':value' => $citation, ':pub_id' => $pub->pub_id,
- ':type_id' => $citation_type_id, ':rank' => 0));
- $counter_updated ++;
-
- } else {
- $sql = "
- INSERT INTO {pubprop} (pub_id, type_id, value, rank)
- VALUES (:pub_id, :type_id, :value, :rank)
- ";
- chado_query($sql, array(':pub_id' => $pub->pub_id, ':type_id' => $citation_type_id,
- ':value' => $citation, ':rank' => 0));
- $counter_generated ++;
- }
- }
- }
- print "$counter_generated citations generated. $counter_updated citations updated.\n";
- }
- function tripal_pub_create_citation($pub) {
- $citation = '';
- $pub_type = '';
-
-
-
-
-
- if (is_array($pub['Publication Type'])) {
- foreach ($pub['Publication Type'] as $ptype) {
- if ($ptype == 'Journal Article' ) {
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == 'Conference Proceedings'){
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == 'Review') {
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == 'Book') {
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == 'Letter') {
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == 'Book Chapter') {
- $pub_type = $ptype;
- break;
- }
- else if ($ptype == "Research Support, Non-U.S. Gov't") {
- $pub_type = $ptype;
-
-
- }
- }
-
-
- if (!$pub_type) {
- $pub_type = $pub['Publication Type'][0];
- }
- }
- else {
- $pub_type = $pub['Publication Type'];
- }
-
-
-
- if ($pub_type == 'Journal Article') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- if ($pub_type == 'Review') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == "Research Support, Non-U.S. Gov't") {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == 'Letter') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Journal Name', $pub)) {
- $citation .= $pub['Journal Name'] . '. ';
- }
- elseif (array_key_exists('Journal Abbreviation', $pub)) {
- $citation .= $pub['Journal Abbreviation'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- elseif ($pub_type == 'Conference Proceedings') {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Conference Name', $pub)) {
- $citation .= $pub['Conference Name'] . '. ';
- }
- elseif (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
-
-
-
- else {
- if (array_key_exists('Authors', $pub)) {
- $citation = $pub['Authors'] . '. ';
- }
- $citation .= $pub['Title'] . '. ';
- if (array_key_exists('Series Name', $pub)) {
- $citation .= $pub['Series Name'] . '. ';
- }
- elseif (array_key_exists('Series Abbreviation', $pub)) {
- $citation .= $pub['Series Abbreviation'] . '. ';
- }
- if (array_key_exists('Publication Date', $pub)) {
- $citation .= $pub['Publication Date'];
- }
- elseif (array_key_exists('Year', $pub)) {
- $citation .= $pub['Year'];
- }
- if (array_key_exists('Volume', $pub) or array_key_exists('Issue', $pub) or array_key_exists('Pages',$pub)) {
- $citation .= '; ';
- }
- if (array_key_exists('Volume', $pub)) {
- $citation .= $pub['Volume'];
- }
- if (array_key_exists('Issue', $pub)) {
- $citation .= '(' . $pub['Issue'] . ')';
- }
- if (array_key_exists('Pages', $pub)) {
- if (array_key_exists('Volume', $pub)) {
- $citation .= ':';
- }
- $citation .= $pub['Pages'];
- }
- $citation .= '.';
- }
- return $citation;
- }
- function tripal_get_minimal_pub_info($pub) {
- if (!$pub) {
- return array();
- }
-
- if ($pub->uniquename == 'null') {
- return array();
- }
-
- $pub = chado_expand_var($pub, 'field', 'pub.title');
- $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Citation',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $citation = chado_generate_var('pubprop', $values, $options);
- $citation = chado_expand_var($citation, 'field', 'pubprop.value');
- $citation = $citation->value;
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Abstract',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $abstract = chado_generate_var('pubprop', $values, $options);
- $abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
- $abstract_text = '';
- if ($abstract) {
- $abstract_text = htmlspecialchars($abstract->value);
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'Authors',
- ),
- );
- $options = array(
- 'include_fk' => array(
- ),
- );
- $authors = chado_generate_var('pubprop', $values, $options);
- $authors = chado_expand_var($authors, 'field', 'pubprop.value');
- $authors_list = 'N/A';
- if ($authors) {
- $authors_list = $authors->value;
- }
-
- $options = array('return_array' => 1);
- $pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
- $dbxref = NULL;
- if ($pub->pub_dbxref) {
- foreach ($pub->pub_dbxref as $index => $pub_dbxref) {
- if ($pub_dbxref->dbxref_id->db_id->urlprefix) {
- $dbxref = $pub_dbxref->dbxref_id;
- }
- }
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- 'type_id' => array(
- 'name' => 'URL',
- ),
- );
- $options = array(
- 'return_array' => 1,
- 'include_fk' => array(),
- );
- $url = '';
- $urls = chado_generate_var('pubprop', $values, $options);
- if ($urls) {
- $urls = chado_expand_var($urls, 'field', 'pubprop.value');
- if (count($urls) > 0) {
- $url = $urls[0]->value;
- }
- }
-
- $values = array(
- 'pub_id' => $pub->pub_id,
- );
- $options = array(
- 'return_array' => 1,
- );
- $pub_dbxrefs = chado_generate_var('pub_dbxref', $values, $options);
- $dbxrefs = array();
- foreach ($pub_dbxrefs as $pub_dbxref) {
- $dbxrefs[] = $pub_dbxref->dbxref_id->db_id->name . ':' . $pub_dbxref->dbxref_id->accession;
- }
- return array(
- 'TPUB:0000039' => $pub->title,
- 'TPUB:0000003' => $citation,
- 'TPUB:0000050' => $abstract_text,
- 'TPUB:0000047' => $authors_list,
- 'TPUB:0000052' => $url,
- 'SBO:0000554' => $dbxrefs,
- );
- }
|