function tripal_pub_search_page
2.x tripal_pub.pub_search.inc | tripal_pub_search_page() |
1.x pub_search.inc | tripal_pub_search_page() |
1 string reference to 'tripal_pub_search_page'
- tripal_pub_menu in tripal_pub/
tripal_pub.module - Tripal-Publication-Menu
File
- tripal_pub/
includes/ pub_search.inc, line 5
Code
function tripal_pub_search_page() {
global $pager_total, $pager_total_items;
$pager_id = 0;
$limit = 25;
// generate the search form
$form = drupal_get_form('tripal_pub_search_form');
$output .= $form;
// retrieve any results
if ($_SESSION['tripal_pub_search_form']['perform_search']) {
$num_criteria = $_SESSION['tripal_pub_search_form']['num_criteria'];
$from_year = $_SESSION['tripal_pub_search_form']['from_year'];
$to_year = $_SESSION['tripal_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_pub_search_form']['criteria'][$i]['search_terms'];
$search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope'];
$search_array['criteria'][$i]['mode'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode'];
$search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation'];
}
// get the list of publications from the remote database using the search criteria.
$pubs = tripal_pub_get_search_results($search_array, $limit, $pager_id);
// 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;
while ($pub = db_fetch_object($pubs)) {
// get the citation for this publication
$values = array(
'pub_id' => $pub->pub_id,
'type_id' => array(
'name' => 'Citation',
),
);
$citation_rec = tripal_core_generate_chado_var('pubprop', $values);
$citation_rec = tripal_core_expand_chado_vars($citation_rec, 'field', 'pubprop.value');
// if we have the citation then use it, otherwise, just use the title
$title = htmlspecialchars($pub->title);
$result = $title;
if ($pub->nid) {
$result = l($title, 'node/' . $pub->nid, 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', '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;
}