function tripal_pub_importer_setup
1.x pub_importers.inc | tripal_pub_importer_setup($action = 'new', $pub_import_id = NULL) |
1 string reference to 'tripal_pub_importer_setup'
- tripal_pub_menu in tripal_pub/
tripal_pub.module - Tripal-Publication-Menu
File
- tripal_pub/
includes/ pub_importers.inc, line 52
Code
function tripal_pub_importer_setup($action = 'new', $pub_import_id = NULL) {
global $pager_total, $pager_total_items;
$pager_id = 0;
$limit = 20;
// make sure the tripal_pub and tripal_contact ontologies are loaded
$values = array('name' => 'tripal_pub');
$tpub_cv = tripal_core_chado_select('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 = tripal_core_chado_select('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');
}
// generate the search form
$form = drupal_get_form('tripal_pub_importer_setup_form', $pub_import_id, $action);
$output = l("Return to publication importers list", "admin/tripal/tripal_pub/import_list");
$output .= $form;
// retrieve any results
$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']) {
// get the list of publications from the remote database using the search criteria.
$pubs = tripal_pub_get_remote_search_results($remote_db, $search_array, $limit, $pager_id);
//dpm($pubs);
// generate the pager
$total_pages = $pager_total[$pager_id];
$total_items = $pager_total_items[$pager_id];
$page = isset($_GET['page']) ? $_GET['page'] : '0';
$pager = theme('pager');
// iterate through the results and construct the table displaying the publications
$rows = array();
$i = $page * $limit + 1;
if (count($pubs) > 0) {
foreach ($pubs as $pub) {
$citation = htmlspecialchars($pub['Citation']);
$raw_link = '';
if ($pub['Publication Dbxref']) {
$raw_link = l('raw', 'admin/tripal/tripal_pub/import/raw/' . $pub['Publication Dbxref'], array('attributes' => array('target' => '_blank')));
}
$rows[] = array(
number_format($i),
$citation,
$raw_link,
);
$i++;
}
}
$headers = array('', 'Publication', '');
$table = theme('table', $headers, $rows);
// join all to form the results
$output .= "<br><p><b>Found " . number_format($total_items) .
". Page " . ($page + 1) . " of $total_pages. " .
" Results</b></br>" . $table . '</p>' . $pager;
}
return $output;
}