1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699 |
- <?php
- require_once('tripal_chado.pub_importer_AGL.inc');
- require_once('tripal_chado.pub_importer_PMID.inc');
- function tripal_pub_importers_list() {
-
-
- $pub_cv = chado_select_record('cv', array('cv_id'), array('name' => 'tripal_pub'));
- if (count($pub_cv) == 0) {
- drupal_set_message(t('The Tripal Pub vocabulary is currently not loaded. ' .
- 'This vocabulary is required to be loaded before importing of ' .
- 'publications. <br>Please !import',
- array('!import' => l('load the Tripal Publication vocabulary', 'admin/tripal/loaders/obo_loader'))), 'warning');
- }
-
- unset($_SESSION['tripal_pub_import']);
- $headers = array('', 'Importer Name', 'Database', 'Search String', 'Disabled', 'Create Contact', '');
- $rows = array();
- $importers = db_query("SELECT * FROM {tripal_pub_import} ORDER BY name");
- while ($importer = $importers->fetchObject()) {
- $criteria = unserialize($importer->criteria);
- $num_criteria = $criteria['num_criteria'];
- $criteria_str = '';
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_terms = $criteria['criteria'][$i]['search_terms'];
- $scope = $criteria['criteria'][$i]['scope'];
- $is_phrase = $criteria['criteria'][$i]['is_phrase'];
- $operation = $criteria['criteria'][$i]['operation'];
- $criteria_str .= "$operation ($scope: $search_terms) ";
- }
- $rows[] = array(
- array(
- 'data' => l(t('Edit/Test'), "admin/tripal/loaders/pub/edit/$importer->pub_import_id") . '<br>' .
- l(t('Import Pubs'), "admin/tripal/loaders/pub/submit/$importer->pub_import_id"),
- 'nowrap' => 'nowrap'
- ),
- $importer->name,
- $criteria['remote_db'],
- $criteria_str,
- $importer->disabled ? 'Yes' : 'No',
- $importer->do_contact ? 'Yes' : 'No',
- l(t('Delete'), "admin/tripal/loaders/pub/delete/$importer->pub_import_id"),
- );
- }
- $page = "<ul class='action-links'>";
- $page .= ' <li>' . l('New Importer', 'admin/tripal/loaders/pub/new') . '</li>';
- $page .= '</ul>';
- $page .= '<p>' . t(
- "A publication importer is used to create a set of search criteria that can be used
- to query a remote database, find publications that match the specified criteria
- and then import those publications into the Chado database. An example use case would
- be to peridocially add new publications to this Tripal site that have appeared in PubMed
- in the last 30 days. You can import publications in one of two ways:
- <ol>
- <li>Create a new importer by clicking the 'New Importer' link above, and after saving it should appear in the list below. Click the
- link labeled 'Import Pubs' to schedule a job to import the publications</li>
- <li>The first method only performs the import once. However, you can schedule the
- importer to run peridically by adding a cron job. See the " .
- l("Pub Module help instructions", "admin/tripal/legacy/tripal_pub/help") . " to learn how to
- set the importers to run automatically.") . '</li>
- </ol><br>';
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- ),
- 'caption' => '',
- 'sticky' => TRUE,
- 'colgroups' => array(),
- 'empty' => 'There are no currently importers',
- );
- $page .= theme_table($table);
- return $page;
- }
- function tripal_pub_importer_setup_page($action = 'new', $pub_import_id = NULL) {
- global $base_path;
-
- $values = array('name' => 'tripal_pub');
- $tpub_cv = chado_select_record('cv', array('cv_id'), $values);
- if (count($tpub_cv) == 0) {
- drupal_set_message(t('Before importing publications you must first ') . l(t('load the Tripal Pub Ontology'), 'admin/tripal/tripal_cv/obo_loader'), 'error');
- }
- $values = array('name' => 'tripal_contact');
- $tpub_cv = chado_select_record('cv', array('cv_id'), $values);
- if (count($tpub_cv) == 0) {
- drupal_set_message(t('If you want to create contact pages for authors, you must first ') . l(t('load the Tripal Contact Ontology'), 'admin/tripal/tripal_cv/obo_loader'), 'error');
- }
- if(!extension_loaded ('yaz')){
- drupal_set_message(t('<b>Note:</b> In order to create an importer using the USDA National Agricultural Library (AGL) you must install the yaz libraries. See the ') . l(t('Pub Module help page'), 'admin/tripal/legacy/tripal_pub/help') . ' for assistance. If you do not want to use AGL you can ignore this warning.', 'warning');
- }
-
- $form = drupal_get_form('tripal_pub_importer_setup_form', $pub_import_id, $action);
- $output = l("Return to publication importers list", "admin/tripal/loaders/pub");
- $output .= drupal_render($form);
-
- if (array_key_exists('tripal_pub_import', $_SESSION)) {
- $remote_db = $_SESSION['tripal_pub_import']['remote_db'];
- $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
- $days = $_SESSION['tripal_pub_import']['days'];
- $search_array = array();
- $search_array['remote_db'] = $remote_db;
- $search_array['num_criteria'] = $num_criteria;
- $search_array['days'] = $days;
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'];
- $search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_import']['criteria'][$i]['scope'];
- $search_array['criteria'][$i]['is_phrase'] = $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'];
- $search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_import']['criteria'][$i]['operation'];
- }
-
- if ($_SESSION['tripal_pub_import']['perform_search']) {
- $limit = 25;
-
- $page = isset($_GET['page']) ? $_GET['page'] : '0';
- $results = tripal_get_remote_pubs($remote_db, $search_array, $limit, $page);
- $total_records = $results['total_records'];
- $search_str = $results['search_str'];
- $pubs = $results['pubs'];
-
- $rows = array();
- $i = $page * $limit + 1;
- if (count($pubs) > 0) {
- foreach ($pubs as $pub) {
- $citation = array_key_exists('Citation', $pub) ? htmlspecialchars($pub['Citation']) : 'Unable to generate citation';
- $raw_link = '';
- if(array_key_exists('Publication Dbxref', $pub) and $pub['Publication Dbxref']) {
- $raw_link = l('raw', 'admin/tripal/loaders/pub/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
- }
- $rows[] = array(
- number_format($i),
- $citation,
- $raw_link,
- );
- $i++;
- }
- }
- if (count($rows) == 0) {
- $rows[] = array(
- array(
- 'data' => 'No results found',
- 'colspan' => 3,
- ),
- );
- }
- $headers = array('', 'Publication', 'Raw Results');
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- 'id' => 'tripal_pub-importer-test',
- 'class' => 'tripal-data-table'
- ),
- 'sticky' => FALSE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
-
-
- $table = theme_table($table);
-
- pager_default_initialize($total_records, $limit);
- $pager = array(
- 'tags' => array(),
- 'element' => 0,
- 'parameters' => array(),
- 'quantity' => $limit,
- );
- $pager = theme_pager($pager);
-
-
- $pager = str_replace($base_path . "system/ajax", "", $pager) ;
-
- $total_pages = (int) ($total_records / $limit) + 1;
- $page = isset($_GET['page']) ? $_GET['page'] : '0';
- $output .= "$pager<br><b>Found " . number_format($total_records) . " publications. Page " . ($page + 1) . " of $total_pages.</b> " .
- "<br>$remote_db Search String: $search_str $table<br>$pager";
- }
- }
- return $output;
- }
- function tripal_pub_importer_setup_form($form, &$form_state = NULL, $pub_import_id = NULL, $action = 'new') {
-
-
-
-
-
-
-
-
-
-
-
- $criteria = NULL;
- $remote_db = '';
- $days = '';
- $disabled = '';
- $do_contact = '';
- $num_criteria = 1;
- $loader_name = '';
-
- if ($action == "edit") {
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
- $importer = db_query($sql, array(':pub_import_id' => $pub_import_id))->fetchObject();
- $criteria = unserialize($importer->criteria);
- $remote_db = $criteria['remote_db'];
- $days = $criteria['days'];
- $disabled = $criteria['disabled'];
- $do_contact = $criteria['do_contact'];
- $num_criteria = $criteria['num_criteria'];
- $loader_name = $criteria['loader_name'];
- }
-
- if (array_key_exists('tripal_pub_import', $_SESSION)) {
- $remote_db = $_SESSION['tripal_pub_import']['remote_db'];
- $days = $_SESSION['tripal_pub_import']['days'];
- $disabled = $_SESSION['tripal_pub_import']['disabled'];
- $do_contact = $_SESSION['tripal_pub_import']['do_contact'];
- $num_criteria = $_SESSION['tripal_pub_import']['num_criteria'];
- $loader_name = $_SESSION['tripal_pub_import']['loader_name'];
-
-
- if ($pub_import_id and $pub_import_id != $_SESSION['tripal_pub_import']['pub_import_id']) {
- unset($_SESSION['tripal_pub_import']);
- }
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $remote_db = $form_state['values']['remote_db'];
- $days = $form_state['values']['days'];
- $disabled = $form_state['values']['disabled'];
- $do_contact = $form_state['values']['do_contact'];
- $num_criteria = $form_state['values']['num_criteria'];
- $loader_name = $form_state['values']['loader_name'];
- }
-
-
- if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
- $remote_db = $form_state['input']['remote_db'];
- $days = $form_state['input']['days'];
- $disabled = $form_state['input']['disabled'];
- $do_contact = $form_state['input']['do_contact'];
- $loader_name = $form_state['input']['loader_name'];
-
-
- $num_criteria = $form_state['complete form']['num_criteria']['#value'];
- }
- if (array_key_exists('triggering_element', $form_state) and
- $form_state['triggering_element']['#name'] == 'add') {
- $num_criteria++;
- }
- if (array_key_exists('triggering_element', $form_state) and
- $form_state['triggering_element']['#name'] == 'remove') {
- $num_criteria--;
- }
-
- $form['num_criteria']= array(
- '#type' => 'value',
- '#value' => $num_criteria,
- );
- $form['pub_import_id'] = array(
- '#type' => 'value',
- '#value' => $pub_import_id,
- );
- $form['action'] = array(
- '#type' => 'value',
- '#value' => $action,
- );
-
- $form['themed_element']['loader_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Loader Name'),
- '#description' => t('Please provide a name for this loader setup.'),
- '#default_value' => $loader_name,
- '#required' => TRUE,
- );
- $supported_dbs = variable_get('tripal_pub_supported_dbs', array('PMID'));
- $remote_dbs = array();
- $values = array(
- 'name' => $supported_dbs,
- );
- $dbs = chado_select_record('db', array('*'), $values);
- foreach ($dbs as $index => $db) {
- $remote_dbs[$db->name] = $db->description;
- };
-
- if (!$remote_db) {
- $remote_db = 'PMID';
- }
- $form['themed_element']['remote_db'] = array(
- '#title' => t('Remote Database'),
- '#type' => 'select',
- '#options' => $remote_dbs,
- '#default_value' => $remote_db,
- '#ajax' => array(
- 'callback' => "tripal_pubs_setup_form_ajax_update",
- 'wrapper' => 'tripal-pubs-importer-setup',
- 'effect' => 'fade',
- 'method' => 'replace',
- ),
- );
- $form['themed_element']['days'] = array(
- '#type' => 'textfield',
- '#title' => t('Days since record modified'),
- '#description' => t('Limit the search to include pubs that have been added no more than this many days before today.'),
- '#default_value' => $days,
- '#size' => 5,
- );
- $form['themed_element']['disabled'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disabled'),
- '#description' => t('Check to disable this importer.'),
- '#default_value' => $disabled,
- );
- $form['themed_element']['do_contact'] = array(
- '#type' => 'checkbox',
- '#title' => t('Create Contact'),
- '#description' => t('Check to create an entry in the contact table for each author of a matching publication during import. This allows storage of
- additional information such as affilation, etc. Otherwise, only authors names are retrieved.'),
- '#default_value' => $do_contact,
- );
-
- tripal_pub_importer_setup_add_criteria_fields($form, $form_state, $num_criteria, $criteria);
-
- $form['save'] = array(
- '#type' => 'submit',
- '#value' => t('Save Importer'),
- );
- $form['test'] = array(
- '#type' => 'submit',
- '#value' => t('Test Importer'),
- );
- $form['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete Importer'),
- '#attributes' => array('style' => 'float: right;')
- );
-
- $form['results'] = array(
- '#markup' => '<div id="tripal-pub-importer-test-section"></div>',
- );
-
- $callback = "tripal_pub_remote_alter_form_$remote_db";
- $form = call_user_func($callback, $form, $form_state, $num_criteria);
- $form['themed_element']['#theme'] = 'tripal_pub_importer_setup_form_elements';
- return $form;
- }
- function tripal_pub_importer_setup_add_criteria_fields(&$form, &$form_state, $num_criteria, $criteria){
-
- $scope_choices = array(
- 'any' => 'Any Field',
- 'abstract' => 'Abstract',
- 'author' => 'Author',
- 'id' => 'Accession',
- 'title' => 'Title',
- 'journal' => 'Journal Name'
- );
- $first_op_choices = array(
- '' => '',
- 'NOT' => 'NOT'
- );
- $op_choices = array(
- 'AND' => 'AND',
- 'OR' => 'OR',
- 'NOT' => 'NOT'
- );
- for($i = 1; $i <= $num_criteria; $i++) {
- $is_phrase = 1;
- $search_terms = '';
- $scope = '';
- $is_phrase = '';
- $operation = '';
-
- if ($criteria) {
- $search_terms = $criteria['criteria'][$i]['search_terms'];
- $scope = $criteria['criteria'][$i]['scope'];
- $is_phrase = $criteria['criteria'][$i]['is_phrase'];
- $operation = $criteria['criteria'][$i]['operation'];
- }
-
- if (array_key_exists('tripal_pub_import', $_SESSION)) {
- $search_terms = isset($_SESSION['tripal_pub_import']['criteria'][$i]['search_terms']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['search_terms'] : $search_terms;
- $scope = isset($_SESSION['tripal_pub_import']['criteria'][$i]['scope']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['scope'] : $scope;
- $is_phrase = isset($_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['is_phrase'] : $is_phrase;
- $operation = isset($_SESSION['tripal_pub_import']['criteria'][$i]['operation']) ? $_SESSION['tripal_pub_import']['criteria'][$i]['operation'] : $operation;
- }
-
-
- if (array_key_exists('values', $form_state)) {
- $search_terms = $form_state['values']["search_terms-$i"];
- $scope = $form_state['values']["scope-$i"];
- $is_phrase = $form_state['values']["is_phrase-$i"];
- $operation = $form_state['values']["operation-$i"];
- }
- $form['themed_element']['criteria'][$i]["scope-$i"] = array(
- '#type' => 'select',
- '#description' => t('Please select the fields to search for this term.'),
- '#options' => $scope_choices,
- '#default_value' => $scope,
- );
- $form['themed_element']['criteria'][$i]["search_terms-$i"] = array(
- '#type' => 'textfield',
- '#description' => t('<span style="white-space: normal">Please provide a list of words for searching. You may use
- conjunctions such as "AND" or "OR" to separate words if they are expected in
- the same scope, but do not mix ANDs and ORs. Check the "Is Phrase" checkbox to use conjunctions as part of the text to search</span>'),
- '#default_value' => $search_terms,
- '#required' => TRUE,
- '#maxlength' => 2048,
- );
- $form['themed_element']['criteria'][$i]["is_phrase-$i"] = array(
- '#type' => 'checkbox',
- '#title' => t('Is Phrase?'),
- '#default_value' => $is_phrase,
- );
- if ($i == 1) {
-
- }
- if ($i > 1) {
- $form['themed_element']['criteria'][$i]["operation-$i"] = array(
- '#type' => 'select',
- '#options' => $op_choices,
- '#default_value' => $operation,
- );
- }
- if ($i == $num_criteria) {
- if($i > 1) {
- $form['themed_element']['criteria'][$i]["remove-$i"] = array(
- '#type' => 'button',
- '#name' => 'remove',
- '#value' => t('Remove'),
- '#ajax' => array(
- 'callback' => "tripal_pubs_setup_form_ajax_update",
- 'wrapper' => 'tripal-pubs-importer-setup',
- 'effect' => 'fade',
- 'method' => 'replace',
- 'prevent' => 'click'
- ),
-
-
-
-
-
-
-
- '#submit' => array('tripal_pub_setup_form_ajax_button_submit'),
- '#validate' => array('tripal_pub_setup_form_ajax_button_validate'),
- '#limit_validation_errors' => array(),
- );
- }
- $form['themed_element']['criteria'][$i]["add-$i"] = array(
- '#type' => 'button',
- '#name' => 'add',
- '#value' => t('Add'),
- '#ajax' => array(
- 'callback' => "tripal_pubs_setup_form_ajax_update",
- 'wrapper' => 'tripal-pubs-importer-setup',
- 'effect' => 'fade',
- 'method' => 'replace',
- 'prevent' => 'click'
- ),
-
-
-
-
-
-
-
- '#submit' => array('tripal_pub_setup_form_ajax_button_submit'),
- '#validate' => array('tripal_pub_setup_form_ajax_button_validate'),
- '#limit_validation_errors' => array(),
- );
- }
- }
- }
- function tripal_pub_setup_form_ajax_button_validate($form, &$form_state){
- $form_state['rebuild'] = TRUE;
- }
- function tripal_pub_setup_form_ajax_button_submit($form, &$form_state){
-
- }
- function tripal_pub_importer_setup_form_validate($form, &$form_state) {
- $num_criteria = $form_state['values']['num_criteria'];
- $remote_db = $form_state['values']["remote_db"];
- $days = trim($form_state['values']["days"]);
- $disabled = $form_state['values']["disabled"];
- $do_contact = $form_state['values']["do_contact"];
- $loader_name = trim($form_state['values']["loader_name"]);
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_terms = trim($form_state['values']["search_terms-$i"]);
- $scope = $form_state['values']["scope-$i"];
- $is_phrase = $form_state['values']["is_phrase-$i"];
- $operation = '';
- if($i > 1) {
- $operation = $form_state['values']["operation-$i"];
- }
- if (!$is_phrase) {
- if (preg_match('/and/i', $search_terms) and preg_match('/or/i', $search_terms)) {
- form_set_error("search_terms-$i", "You may use 'AND' or 'OR' but cannot use both. Add a new entry below with the same scope for the other conunction.");
- $_SESSION['tripal_pub_import']['perform_search'] = 0;
- }
- }
- }
- if ($days and !is_numeric($days) or preg_match('/\./', $days)) {
- form_set_error("days", "Please enter a numeric, non decimal value, for the number of days.");
- $_SESSION['tripal_pub_import']['perform_search'] = 0;
- }
-
- $callback = "tripal_pub_remote_validate_form_$remote_db";
- $form = call_user_func($callback, $form, $form_state);
- }
- function tripal_pub_importer_setup_form_submit($form, &$form_state) {
- $pub_import_id = $form_state['values']['pub_import_id'];
- $num_criteria = $form_state['values']['num_criteria'];
- $remote_db = $form_state['values']["remote_db"];
- $days = trim($form_state['values']["days"]);
- $loader_name = trim($form_state['values']["loader_name"]);
- $disabled = $form_state['values']["disabled"];
- $do_contact = $form_state['values']["do_contact"];
-
- $_SESSION['tripal_pub_import']['remote_db'] = $remote_db;
- $_SESSION['tripal_pub_import']['days'] = $days;
- $_SESSION['tripal_pub_import']['num_criteria'] = $num_criteria;
- $_SESSION['tripal_pub_import']['loader_name'] = $loader_name;
- $_SESSION['tripal_pub_import']['disabled'] = $disabled;
- $_SESSION['tripal_pub_import']['do_contact'] = $do_contact;
- $_SESSION['tripal_pub_import']['pub_import_id'] = $pub_import_id;
- unset($_SESSION['tripal_pub_import']['criteria']);
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_terms = trim($form_state['values']["search_terms-$i"]);
- $scope = $form_state['values']["scope-$i"];
- $is_phrase = $form_state['values']["is_phrase-$i"];
- $operation = '';
- if ($i > 1) {
- $operation = $form_state['values']["operation-$i"];
- }
- $_SESSION['tripal_pub_import']['criteria'][$i] = array(
- 'search_terms' => $search_terms,
- 'scope' => $scope,
- 'is_phrase' => $is_phrase,
- 'operation' => $operation
- );
- }
-
- if ($form_state['values']['op'] == 'Test Importer') {
- $_SESSION['tripal_pub_import']['perform_search'] = 1;
- }
- if ($form_state['values']['op'] == 'Save Importer' or
- $form_state['values']['op'] == 'Save & Import Now') {
- $record = array(
- 'name' => $loader_name,
- 'criteria' => serialize($_SESSION['tripal_pub_import']),
- 'disabled' => $disabled,
- 'do_contact' => $do_contact
- );
-
-
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
- $importer = db_query($sql, array(':pub_import_id' => $pub_import_id))->fetchObject();
- if($importer) {
-
- $record['pub_import_id'] = $pub_import_id;
- if(drupal_write_record('tripal_pub_import', $record, 'pub_import_id')){
- unset($_SESSION['tripal_pub_import']);
- drupal_set_message('Publication import settings updated.');
- drupal_goto('admin/tripal/loaders/pub');
- }
- else {
- drupal_set_message('Could not update publication import settings.', 'error');
- }
- }
- else {
-
- if(drupal_write_record('tripal_pub_import', $record)){
- unset($_SESSION['tripal_pub_import']);
- drupal_set_message('Publication import settings saved.');
-
-
- if ($form_state['values']['op'] == 'Save & Import Now') {
- tripal_execute_pub_importer($record['pub_import_id']);
- }
- drupal_goto('admin/tripal/loaders/pub');
- }
- else {
- drupal_set_message('Could not save publication import settings.', 'error');
- }
- }
- }
- if ($form_state['values']['op'] == 'Delete Importer') {
- $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = :pub_import_id";
- $success = db_query($sql, array(':pub_import_id' => $pub_import_id));
- if ($success) {
- drupal_set_message('Publication importer deleted.');
- drupal_goto('admin/tripal/loaders/pub');
- }
- else {
- drupal_set_message('Could not delete publication importer.', 'error');
- }
- }
- }
- function tripal_pubs_setup_form_ajax_update($form, $form_state) {
- return $form['themed_element'];
- }
- function theme_tripal_pub_importer_setup_form_elements($variables) {
- $form = $variables['form'];
-
- $markup = '';
- $markup .= '<div id="pub-search-form-row0">';
- $markup .= ' <div id="pub-search-form-row0-col1" style="float: left">' . drupal_render($form['remote_db']) . '</div>';
- $markup .= ' <div id="pub-search-form-row0-col2" style="float: left; margin-left: 10px">' . drupal_render($form['loader_name']) . '</div>';
- $markup .= '</div>';
- $markup .= '<div id="pub-search-form-row1" style="clear:both">';
- $markup .= ' <div id="pub-search-form-row1-col1">' . drupal_render($form['days']) . '</div>';
- $markup .= '</div>';
- $markup .= '<div id="pub-search-form-row2">' . drupal_render($form['disabled']) . '</div>';
- $markup .= '<div id="pub-search-form-row3">' . drupal_render($form['do_contact']) . '</div>';
-
- $rows = array();
- foreach ($form['criteria'] as $i => $element) {
- if(is_numeric($i)) {
- $rows[] = array(
- drupal_render($element["operation-$i"]),
- drupal_render($element["scope-$i"]),
- drupal_render($element["search_terms-$i"]),
- drupal_render($element["is_phrase-$i"]),
- drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]),
- );
- }
- }
- $headers = array('Operation','Scope', 'Search Terms', '','');
- $table = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(
- 'class' => array('tripal-data-table')
- ),
- 'sticky' => TRUE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $criteria_table = theme_table($table);
- $markup .= $criteria_table;
-
- $form = array(
- '#markup' => $markup,
- '#prefix' => '<div id="tripal-pubs-importer-setup">',
- '#suffix' => '</div>',
- );
- return drupal_render($form);
- }
- function tripal_pub_importer_submit_job($import_id) {
- global $user;
-
- $args = array(':import_id' => $import_id);
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
- $import = db_query($sql, $args)->fetchObject();
- $args = array($import_id);
- $includes = array();
- $includes[] = module_load_include('inc', 'tripal_chado', 'includes/loaders/tripal_chado.pub_importers');
- tripal_add_job("Import publications $import->name", 'tripal_chado',
- 'tripal_execute_pub_importer', $args, $user->uid, 10, $includes);
- drupal_goto('admin/tripal/loaders/pub');
- }
- function tripal_pub_importer_delete($import_id) {
- $args = array(':import_id' => $import_id);
- $sql = "DELETE FROM {tripal_pub_import} WHERE pub_import_id = :import_id";
- $success = db_query($sql, $args);
- if ($success) {
- drupal_set_message('Publication importer deleted.');
- drupal_goto('admin/tripal/loaders/pub');
- }
- else {
- drupal_set_message('Could not delete publication importer.', 'error');
- }
- }
- function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) {
- $report = array();
- $report['error'] = 0;
- $report['inserted'] = array();
- $report['skipped'] = array();
- $total_pubs = count($pubs);
-
- $i = 1;
- foreach ($pubs as $pub) {
- $memory = number_format(memory_get_usage()) . " bytes";
- print "Processing $i of $total_pubs. Memory usage: $memory.\r";
-
- $action = '';
- $pub_id = tripal_pub_add_publication($pub, $action, $do_contact, $update);
- if ($pub_id){
-
- if ($pub_id and $pub['Publication Dbxref']) {
- $dbxref = array();
- if (preg_match('/^(.*?):(.*?)$/', trim($pub['Publication Dbxref']), $matches)) {
- $dbxref['db_name'] = $matches[1];
- $dbxref['accession'] = $matches[2];
- }
- else {
- tripal_report_error(
- 'tripal_pub',
- TRIPAL_ERROR,
- 'Unable to extract the dbxref to be associated with the publication (pub ID=@pub_id) from @dbxref. This reference should be [database-name]:[accession]',
- array('@pub_id' => $pub_id, '@dbxref' => $pub['Publication Dbxref'])
- );
- }
- $pub_dbxref = tripal_associate_dbxref('pub', $pub_id, $dbxref);
- }
- $pub['pub_id'] = $pub_id;
- }
- switch ($action) {
- case 'error':
- $report['error']++;
- break;
- case 'inserted':
- $report['inserted'][] = $pub;
- break;
- case 'updated':
- $report['updated'][] = $pub;
- break;
- case 'skipped':
- $report['skipped'][] = $pub;
- break;
- }
- $i++;
- }
- print "\n";
- return $report;
- }
- function tripal_pub_add_publication($pub_details, &$action, $do_contact = FALSE, $update_if_exists = FALSE) {
- $pub_id = 0;
- if (!is_array($pub_details)) {
- return FALSE;
- }
-
-
- $pub_ids = tripal_publication_exists($pub_details);
- if(count($pub_ids) == 1 and !$update_if_exists) {
- tripal_report_error('tripal_pub', TRIPAL_NOTICE,
- "There is a publication that is a duplicate of this publication. Cannot continue. It either ".
- "has a matching Dbxref (e.g. PubMed ID), a non-unique citation or matches on the unique " .
- "constraint set by the Tripal publication module configuration page. \nCitation: %title %dbxref.\nMatching Pub id: %ids",
- array(
- '%title' => $pub_details['Citation'],
- '%dbxref' => $pub_details['Publication Dbxref'],
- '%ids' => implode(",", $pub_ids),
- )
- );
- $action = 'skipped';
- return FALSE;
- }
-
-
- if(count($pub_ids) > 1) {
- tripal_report_error('tripal_pub', TRIPAL_NOTICE,
- "There are %num publications that are duplicates of this publication. They either " .
- "have a matching Dbxref (e.g. PubMed ID) or match on the unique constraint set by the Tripal publication module ".
- "configuration page. \nCitation: %title %dbxref.\nMatching Pub ids: %ids",
- array(
- '%num' => count($pub_ids),
- '%title' => $pub_details['Citation'],
- '%dbxref' => $pub_details['Publication Dbxref'],
- '%ids' => implode(",", $pub_ids),
- )
- );
- $action = 'skipped';
- return FALSE;
- }
- if(count($pub_ids) == 1 and $update_if_exists) {
- $pub_id = $pub_ids[0];
- }
-
- if (array_key_exists('Publication Type', $pub_details)) {
- $pub_type = '';
- if(is_array($pub_details['Publication Type'])) {
- $pub_type = $pub_details['Publication Type'][0];
- }
- else {
- $pub_type = $pub_details['Publication Type'];
- }
- $identifiers = array(
- 'name' => $pub_type,
- 'cv_id' => array(
- 'name' => 'tripal_pub'
- ),
- );
- $pub_type = tripal_get_cvterm($identifiers);
- }
- else {
- tripal_report_error('tripal_pub', TRIPAL_ERROR,
- "The Publication Type is a required property but is missing", array());
- $action = 'error';
- return FALSE;
- }
- if (!$pub_type) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot find publication type: '%type'",
- array('%type' => $pub_details['Publication Type'][0]));
- $action = 'error';
- return FALSE;
- }
-
- $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);
- }
-
- $values = array(
- 'title' => $pub_details['Title'],
- 'volume' => (isset($pub_details['Volume'])) ? $pub_details['Volume'] : '',
- 'series_name' => $series_name,
- 'issue' => (isset($pub_details['Issue'])) ? $pub_details['Issue'] : '',
- 'pyear' => (isset($pub_details['Year'])) ? $pub_details['Year'] : '',
- 'pages' => (isset($pub_details['Pages'])) ? $pub_details['Pages'] : '',
- 'uniquename' => $pub_details['Citation'],
- 'type_id' => $pub_type->cvterm_id,
- );
-
- if (!$pub_id) {
- $options = array('statement_name' => 'ins_pub_tivoseispypaunty');
- $pub = chado_insert_record('pub', $values, $options);
- if (!$pub) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot insert the publication with title: %title",
- array('%title' => $pub_details['Title']));
- $action = 'error';
- return FALSE;
- }
- $pub_id = $pub['pub_id'];
- $action = 'inserted';
- }
-
- if ($pub_id and $update_if_exists) {
- $match = array('pub_id' => $pub_id);
- $options = array('statement_name' => 'up_pub_tivoseispypaunty');
- $success = chado_update_record('pub', $match, $values, $options);
- if (!$success) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot update the publication with title: %title",
- array('%title' => $pub_details['Title']));
- $action = 'error';
- return FALSE;
- }
- $action = 'updated';
- }
-
-
- if ($update_if_exists) {
- $sql = "
- DELETE FROM {pubprop}
- WHERE
- pub_id = :pub_id AND
- NOT type_id in (
- SELECT cvterm_id
- FROM {cvterm}
- WHERE name = 'Publication Dbxref'
- )
- ";
- chado_query($sql, array(':pub_id' => $pub_id));
- }
-
- foreach ($pub_details as $key => $value) {
-
- if($key == 'raw') {
- continue;
- }
-
- $identifiers = array(
- 'name' => $key,
- 'cv_id' => array(
- 'name' => 'tripal_pub'
- ),
- );
- $cvterm = tripal_get_cvterm($identifiers);
-
-
- if (!$cvterm) {
- $identifiers = array(
- 'synonym' => array(
- 'name' => $key,
- 'cv_name' => 'tripal_pub'
- )
- );
- $cvterm = tripal_get_cvterm($identifiers);
- }
- if (!$cvterm) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot find term: '%prop'. Skipping.", array('%prop' => $key));
- continue;
- }
-
- if ($key == 'Author List') {
- tripal_pub_add_authors($pub_id, $value, $do_contact);
- continue;
- }
- if ($key == 'Title' or $key == 'Volume' or $key == 'Journal Name' or $key == 'Issue' or
- $key == 'Year' or $key == 'Pages') {
- continue;
- }
- $success = 0;
- if (is_array($value)) {
- foreach ($value as $subkey => $subvalue) {
-
-
- if(is_int($subkey)) {
- $success = chado_insert_property(
- array('table' => 'pub', 'id' => $pub_id),
- array('type_name' => $key, 'cv_name' => 'tripal_pub', 'value' => $subvalue)
- );
- }
- else {
- $success = chado_insert_property(
- array('table' => 'pub', 'id' => $pub_id),
- array('type_name' => $subkey, 'cv_name' => 'tripal_pub', 'value' => $subvalue)
- );
- }
- }
- }
- else {
- $success = chado_insert_property(
- array('table' => 'pub', 'id' => $pub_id),
- array('type_name' => $key, 'cv_name' => 'tripal_pub', 'value' => $value),
- array('update_if_present' => TRUE)
- );
- }
- if (!$success) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot add property '%prop' to publication. Skipping.",
- array('%prop' => $key));
- continue;
- }
- }
- return $pub_id;
- }
- function tripal_pub_add_authors($pub_id, $authors, $do_contact) {
- $rank = 0;
-
- $sql = "DELETE FROM {pubauthor} WHERE pub_id = :pub_id";
- chado_query($sql, array(':pub_id' => $pub_id));
-
-
-
- foreach ($authors as $author) {
-
- if (isset($author['valid']) AND $author['valid'] == 'N') {
- continue;
- }
-
- unset($author['valid']);
- $values = array(
- 'pub_id' => $pub_id,
- 'rank' => $rank,
- );
-
- $name = '';
- $type = 'Person';
- if (isset($author['Given Name'])) {
- $name .= $author['Given Name'];
- $values['givennames'] = $author['Given Name'];
- }
- if (isset($author['Surname'])) {
- $name .= ' ' . $author['Surname'];
- $values['surname'] = substr($author['Surname'], 0, 100);
- }
- if (isset($author['Suffix'])) {
- $name .= ' ' . $author['Suffix'];
- $values['suffix'] = $author['Suffix'];
- }
- if (isset($author['Collective'])) {
- $name = $author['Collective'];
- $type = 'Collective';
- if (!isset($author['Surname']))
- $values['surname'] = substr($author['Collective'], 0, 100);
- }
- $name = trim($name);
-
- $options = array('statement_name' => 'ins_pubauthor_idrasugisu');
- $pubauthor = chado_insert_record('pubauthor', $values, $options);
-
- if ($do_contact) {
-
- $contact = tripal_insert_contact(array(
- 'name' => $name,
- 'description' => '',
- 'type_name' => $type,
- 'properties' => $author
- ));
-
-
- if ($contact and $pubauthor) {
-
- $values = array(
- 'pubauthor_id' => $pubauthor['pubauthor_id'],
- 'contact_id' => $contact['contact_id'],
- );
- $options = array('statement_name' => 'ins_pubauthorcontact_puco');
- $pubauthor_contact = chado_insert_record('pubauthor_contact', $values, $options);
- if (!$pubauthor_contact) {
- tripal_report_error('tripal_pub', TRIPAL_ERROR, "Cannot link pub authro and contact.", array());
- }
- }
- }
- $rank++;
- }
- }
- function tripal_pub_get_publication_array($pub_id, $skip_existing = TRUE) {
- $options = array('return_array' => 1);
-
-
-
- $values = array('pub_id' => $pub_id);
- $pub = chado_generate_var('pub', $values);
-
- $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;
-
-
-
- $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) {
-
- return FALSE;
- }
- }
-
-
-
- $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;
- }
- }
-
-
-
- $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;
- }
-
- 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;
- }
- }
-
- $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;
- }
- function tripal_execute_pub_importer($import_id, $job_id = 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 {
- $page = 0;
- $do_contact = FALSE;
- $num_to_retrieve = 100;
-
- $args = array(':import_id' => $import_id);
- $sql = "SELECT * FROM {tripal_pub_import} WHERE pub_import_id = :import_id ";
- $import = db_query($sql, $args)->fetchObject();
- print "Executing Importer: '" . $import->name . "'\n";
- $criteria = unserialize($import->criteria);
- $remote_db = $criteria['remote_db'];
- $total_pubs = 0;
- do {
-
- $results = tripal_get_remote_pubs($remote_db, $criteria, $num_to_retrieve, $page);
- $pubs = $results['pubs'];
- $num_pubs = $rseults['total_records'];
- $total_pubs += $num_pubs;
- tripal_pub_add_publications($pubs, $import->do_contact);
- $page++;
- }
-
-
- while (count($pubs) == $num_to_retrieve);
-
-
- if (module_exists('tripal_pub')) {
-
-
-
- print "Syncing publications with Drupal...\n";
- chado_node_sync_records('pub');
-
- if($import->do_contact) {
- print "Syncing contacts with Drupal...\n";
- chado_node_sync_records('contact');
- }
- }
- tripal_set_job_progress($job_id, '100');
- }
- 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_get_remote_pub($dbxref) {
- if(preg_match('/^(.*?):(.*?)$/', $dbxref, $matches)) {
- $remote_db = $matches[1];
- $accession = $matches[2];
-
- $supported_dbs = variable_get('tripal_pub_supported_dbs', array('PMID'));
- if(!in_array($remote_db, $supported_dbs)) {
- return FALSE;
- }
- $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);
- return $pubs['pubs'][0];
- }
- return FALSE;
- }
- function tripal_get_remote_pubs($remote_db, $search_array, $num_to_retrieve, $page = 0) {
-
- $callback = "tripal_pub_remote_search_$remote_db";
- $pubs = array(
- 'total_records' => 0,
- 'search_str' => '',
- 'pubs' => array(),
- );
- if (function_exists($callback)) {
- $pubs = call_user_func($callback, $search_array, $num_to_retrieve, $page);
- }
- return $pubs;
- }
- function tripal_pub_citation_form($form, &$form_state) {
- $form['instructions'] = array(
- '#markup' => '<p>Use this form to unify publication citations. Citations are created automtically when
- importing publications but citations are set by the user when publications are added manually.
- Or publications added to the Chado database by tools other than the Tripal Publication Importer may
- not have citations set. If you are certain that all necessary information for all publications is present (e.g.
- authors, volume, issue, page numbers, etc.) but citations are not consistent, then you can
- choose to update all citations for all publications using the form below. Alternatively, you
- can update citations only for publication that do not already have one.</p>'
- );
- $form['options'] = array(
- '#type' => 'radios',
- '#options' => array(
- 'all' => 'Create citation for all publications. Replace the existing citation if it exists.',
- 'new' => 'Create citation for publication only if it does not already have one.'),
- '#default_value' => 'all'
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
- }
- function tripal_pub_citation_form_submit(&$form_state) {
- $options [0] = $form_state['options']['#value'];
- tripal_add_job("Create citations ($options[0])", 'tripal_pub', 'tripal_pub_create_citations', $options, $user->uid);
- }
|