function tripal_chado_pub_search_page
3.x tripal_chado.pub_search.inc | tripal_chado_pub_search_page() |
The page that contains the publication search form and the results for the search
1 string reference to 'tripal_chado_pub_search_page'
- tripal_chado_menu in tripal_chado/
tripal_chado.module - Implements hook_menu().
File
- tripal_chado/
includes/ tripal_chado.pub_search.inc, line 71 - Functions responsible for creating the publication search form that allows a user of the site to search for publications that are currently in Chado.
Code
function tripal_chado_pub_search_page() {
// This line may not be required, but on some sites the $_SESSION
// variable wasn't being set for anonymous users. This line solves that
// problem
drupal_session_start();
$limit = 25;
// generate the search form
$form = drupal_get_form('tripal_chado_pub_search_form');
$output = drupal_render($form);
// retrieve any results
if (array_key_exists('tripal_chado_pub_search_form', $_SESSION) and
$_SESSION['tripal_chado_pub_search_form']['perform_search']) {
$num_criteria = $_SESSION['tripal_chado_pub_search_form']['num_criteria'];
$from_year = $_SESSION['tripal_chado_pub_search_form']['from_year'];
$to_year = $_SESSION['tripal_chado_pub_search_form']['to_year'];
$search_array = array();
$search_array['num_criteria'] = $num_criteria;
$search_array['from_year'] = $from_year;
$search_array['to_year'] = $to_year;
for ($i = 0; $i <= $num_criteria; $i++) {
$search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['search_terms'];
$search_array['criteria'][$i]['scope'] = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['scope'];
$search_array['criteria'][$i]['mode'] = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['mode'];
$search_array['criteria'][$i]['operation'] = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['operation'];
}
// get the list of publications from the remote database using the search criteria.
$page = isset($_GET['page']) ? $_GET['page'] : '0';
$offset = $page * $limit;
$total_records = 0;
$pubs = tripal_search_publications($search_array, $offset, $limit, $total_records);
pager_default_initialize($total_records, $limit, 0);
// iterate through the results and construct the table displaying the publications
$rows = array();
$i = $page * $limit + 1;
foreach ($pubs as $pub) {
// get the citation for this publication
$values = array(
'pub_id' => $pub->pub_id,
'type_id' => array(
'name' => 'Citation',
),
);
$citation_rec = chado_generate_var('pubprop', $values);
$citation_rec = chado_expand_var($citation_rec, 'field', 'pubprop.value');
// if we have the citation then use it, otherwise, just use the title
$title = htmlspecialchars($pub->title);
$result = $title;
$link = NULL;
// tripal v2 link (node)
if (module_exists('tripal_pub')) {
$nid = chado_get_nid_from_id('pub', $pub->pub_id);
if ($nid) {
$link = "/node/$nid";
}
}
// try tripal v3 link (entity), if it exists, update the link to entity
$entity_id = chado_get_record_entity_by_table('pub', $pub->pub_id);
if ($entity_id) {
$link = "/bio_data/$entity_id";
}
if ($link) {
$result = l($title, $link, array('attributes' => array('target' => '_blank')));
}
if ($citation_rec->value) {
$citation = htmlspecialchars($citation_rec->value);
$result .= '<br>' . $citation;
}
$rows[] = array(
number_format($i) . ".",
$pub->pyear,
$result
);
$i++;
}
$headers = array('', 'Year', 'Reference');
$table = array(
'header' => $headers,
'rows' => $rows,
'attributes' => array(
'id' => 'tripal-pub-search-results-table',
'border' => '0',
'class' => array('tripal-data-table')
),
'sticky' => TRUE,
'caption' => '',
'colgroups' => array(),
'empty' => 'No publications found',
);
$results = theme_table($table);
// generate the pager
$pager = array(
'tags' => array(),
'element' => 0,
'parameters' => array(),
'quantity' => $limit,
);
$pager = theme_pager($pager);
// join all to form the results
$output .= "<p><b>Found " . number_format($total_records) .
" Results</b></br>" . $results . $pager;
}
return $output;
}