remote_search.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. *
  4. */
  5. function tripal_pub_remote_search_page() {
  6. global $pager_total;
  7. // generate the search form
  8. $form = drupal_get_form('tripal_pub_remote_search_form');
  9. // retrieve any results
  10. $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
  11. $search_terms = $_SESSION['tripal_pub_search_criteria']['search_terms'];
  12. $results = tripal_pub_get_remote_search_results($remote_db, $search_terms, 10, 0);
  13. // iterate through the results and construct the table displaying the publications
  14. if (count($results) > 0) {
  15. }
  16. // generate the pager
  17. $total_items = $pager_total[0];
  18. $pager = theme('pager');
  19. // join all to form the final page
  20. $output = $form . "<p><b>Found " . number_format($total_items) . " Results</b></br>" . $table . '</p>' . $pager;
  21. dpm($results);
  22. return $output;
  23. }
  24. /*
  25. *
  26. */
  27. function tripal_pub_get_remote_search_results($remote_db, $search_terms, $num_to_retrieve, $pager_id) {
  28. $results = array();
  29. $callback = 'tripal_pub_remote_search_' . strtolower($remote_db);
  30. if (function_exists($callback) and $search_terms) {
  31. $results = call_user_func($callback, $search_terms, $num_to_retrieve, $pager_id);
  32. }
  33. return $results;
  34. }
  35. /**
  36. * Purpose: Provides the form to search pubmed
  37. *
  38. * @ingroup tripal_pub
  39. */
  40. function tripal_pub_remote_search_form(&$form_state = NULL) {
  41. $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
  42. $search_terms = $_SESSION['tripal_pub_search_criteria']['search_terms'];
  43. $remote_dbs = array('Pubmed' => 'Pubmed');
  44. $form['remote_db'] = array(
  45. '#title' => t('Remote Publication Database'),
  46. '#type' => 'select',
  47. '#options' => $remote_dbs,
  48. '#default_value' => $remote_db,
  49. );
  50. $form['search_terms']= array(
  51. '#type' => 'textfield',
  52. '#title' => t('Search Terms'),
  53. '#description' => t('Please provide a list of words, separated by spaces for searching'),
  54. '#default_value' => $search_terms,
  55. );
  56. $form['submit'] = array(
  57. '#type' => 'submit',
  58. '#value' => t('Submit'),
  59. '#executes_submit_callback' => TRUE,
  60. );
  61. return $form;
  62. }
  63. /**
  64. *
  65. */
  66. function tripal_pub_remote_search_form_validate($form, &$form_state) {
  67. $remote_db = $form_state['values']['remote_db'];
  68. $search_terms = $form_state['values']['search_terms'];
  69. }
  70. /**
  71. *
  72. */
  73. function tripal_pub_remote_search_form_submit($form, &$form_state) {
  74. $remote_db = $form_state['values']['remote_db'];
  75. $search_terms = $form_state['values']['search_terms'];
  76. // store the search settings in a session variable. Then when the page
  77. // is refreshed these values will be available for the page to
  78. // generate results.
  79. if ($op == 'Reset') {
  80. unset($_SESSION['tripal_pub_search_criteria']);
  81. unset($form_state['values']);
  82. }
  83. else {
  84. $_SESSION['tripal_pub_search_criteria'] = array(
  85. 'remote_db' => $remote_db,
  86. 'search_terms' => $search_terms,
  87. );
  88. }
  89. }