فهرست منبع

Fixed a misnamed element in the CV module, and continued development with pub module. Committing at end of day

spficklin 12 سال پیش
والد
کامیت
d37752c492
4فایلهای تغییر یافته به همراه282 افزوده شده و 127 حذف شده
  1. 2 2
      tripal_cv/includes/tripal_cv_admin.inc
  2. 27 9
      tripal_pub/includes/pubmed.inc
  3. 224 113
      tripal_pub/includes/remote_search.inc
  4. 29 3
      tripal_pub/tripal_pub.module

+ 2 - 2
tripal_cv/includes/tripal_cv_admin.inc

@@ -7,7 +7,7 @@
  */
 function tripal_cv_edit_page() {
   $output .= drupal_get_form('tripal_cv_select_form');
-  $output .= '<div id="db-edit-div">Please select a vocabulary above to view or edit</div>';
+  $output .= '<div id="cv-edit-div">Please select a vocabulary above to view or edit</div>';
 
   return $output;
 }
@@ -37,7 +37,7 @@ function tripal_cv_select_form() {
     '#options' => $cvs,
     '#ahah' => array(
       'path' => 'admin/tripal/tripal_cv/cv/edit/js',
-      'wrapper' => 'db-edit-div',
+      'wrapper' => 'cv-edit-div',
       'effect' => 'fade',
       'event' => 'change',
       'method' => 'replace',

+ 27 - 9
tripal_pub/includes/pubmed.inc

@@ -14,16 +14,34 @@ function tripal_pub_remote_search_pubmed($search_array, $num_to_retrieve, $pager
   
   // convert the terms list provicded by the caller into a string with words
   // separated by a '+' symbol.
-  $terms = '';
-  if ($search_array['search_terms']) {
-    $terms = '(' . implode("+", preg_split('/\s+/', trim($search_array['search_terms']))) . '[Title/Abstract]) AND ';
-  }
-  if ($search_array['author']) {
-    $terms = "(" . $search_array . "[Author]) AND ";
-  }
-  $terms = substr($terms, 0, -4);
-  
+  $num_criteria = $search_array['num_criteria'];
+  $days = $search_array['num_criteria'];
+
+  $search_str = '';
+  for ($i = 0; $i <= $num_criteria; $i++) {
+    $search_terms = $search_array['criteria'][$i]['search_terms'];
+    $scope = $search_array['criteria'][$i]['scope'];
+    $op = $search_array['criteria'][$i]['operation'];
+    
+    if ($op) {
+      $search_str .= "$op";
+    }
+    
+    $search_str .= '(';
+    $search_str .= implode("+", preg_split('/\s+/', trim($search_terms)));
+    if($scope == 'title') {
+      $search_str .= '[Title]';
+    }    
+    elseif($scope == 'author') {
+      $search_str .= '[Author]';
+    }    
+    elseif($scope == 'abstract') {
+      $search_str .= '[Title/Abstract]';
+    }
+    $search_str .= ')'; 
+  }  
   $search_array['limit'] = $num_to_retrieve;
+  $search_array['search_terms'] = $search_str;
 
   // we want to get the list of pubs using the search terms but using a Drupal style pager
   $pubs = tripal_pager_callback('tripal_pub_remote_search_pubmed_range',  

+ 224 - 113
tripal_pub/includes/remote_search.inc

@@ -1,16 +1,77 @@
 <?php
+
+/*
+ * 
+ */
+function tripal_pub_remote_search_page() {
+  global $pager_total, $pager_total_items;
+  
+  $pager_id = 0;
+  $limit = 10;
+  
+  // generate the search form 
+  $form = drupal_get_form('tripal_pub_remote_search_form');
+
+  // retrieve any results
+  $remote_db = $_SESSION['tripal_pub_search']['remote_db'];
+  $num_criteria = $_SESSION['tripal_pub_search']['num_criteria'];
+  $days = $_SESSION['tripal_pub_search']['days'];
+ 
+  $search_array = array();
+  $search_array['remote_db'] = $remote_db;
+  $search_array['num_criteria'] = $num_criteria;
+  $search_array['days'] = $days; 
+  for ($i = 0; $i <= $num_criteria; $i++) {
+    $search_array['criteria'][$i]['search_terms'] = $_SESSION['tripal_pub_search']['criteria'][$i]['search_terms'];
+    $search_array['criteria'][$i]['scope'] = $_SESSION['tripal_pub_search']['criteria'][$i]['scope'];  
+    $search_array['criteria'][$i]['operation'] = $_SESSION['tripal_pub_search']['criteria'][$i]['operation'];
+  }
+    
+  // 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);
+
+  // 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) {
+      $rows[] = array(number_format($i), $pub['citation']);
+      $i++;
+    }
+  }
+  $headers = array('', 'Citation');
+  $table = theme('table', $headers, $rows);
+  
+  
+  // join all to form the final page
+  $output =  $form . "<p><b>Found " . number_format($total_items) .  
+    ". Page " . ($page + 1) . " of $total_pages. " .
+    " Results</b></br>" . $table . '</p>' . $pager;    
+  
+  return $output;
+}
 /*
  * 
  */
 function theme_tripal_pub_remote_search_form($form) {
-  $rows = array(
-    array(            
-      drupal_render($form['scope']),
-      drupal_render($form['operation']),
-      drupal_render($form['search_terms']),
-    ),
-  );
-  $headers = array('Search Terms', 'Scope', 'Operation');
+  $rows = array();
+  foreach ($form['criteria'] as $i => $element) {
+    if(is_numeric($i)) {
+      $rows[] = array(  
+        array('data' => drupal_render($element["operation-$i"]), 'width' => '10%'),    
+        array('data' => drupal_render($element["scope-$i"]), 'width' => '10%'),
+        drupal_render($element["search_terms-$i"]),
+        array('data' => drupal_render($element["add-$i"]) . drupal_render($element["remove-$i"]), 'width' => '5%'),
+      );
+    }
+  }
+  $headers = array('Operation','Scope', 'Search Terms', '');
   $form['criteria'] = array(
     '#type' => 'markup',
     '#value' =>  theme('table', $headers, $rows),
@@ -24,12 +85,32 @@ function theme_tripal_pub_remote_search_form($form) {
   * @ingroup tripal_pub
  */
 function tripal_pub_remote_search_form(&$form_state = NULL) {
-  $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
-  $search_terms = $_SESSION['tripal_pub_search_criteria']['search_terms'];
-  $days = $_SESSION['tripal_pub_search_criteria']['days'];
-  $scope = $_SESSION['tripal_pub_search_criteria']['scope'];
-  $operation = $_SESSION['tripal_pub_search_criteria']['operation'];
+  tripal_core_ahah_init_form();
+
+  // set default values.  First use what is in the form_state['values'] array. If nothing there then use the session variable.
+  $remote_db = $form_state['values']['remote_db'] ? $form_state['values']['remote_db'] : $_SESSION['tripal_pub_search']['remote_db'];
+  $days = $form_state['values']['days'] ? $form_state['values']['days'] : $_SESSION['tripal_pub_search']['days']; 
+  $num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $_SESSION['tripal_pub_search']['num_criteria'];
+  $loader_name = $form_state['values']['loader_name'];
   
+  // change the number of criteria based on form_state post data.
+  if (!$num_criteria) {
+    $num_criteria = 0;
+  }
+  if($form_state['post']["add-$num_criteria"]) {    
+    $num_criteria++;
+  }
+  if($form_state['post']["remove-$num_criteria"]) {    
+    $num_criteria--;
+  }
+  
+  $form['loader_name'] = array(
+    '#type'          => 'textfield',
+    '#title'         => t('Loader Name'),
+    '#description'   => t('Please provide a name for this loader setup..'),
+    '#default_value' => $loader_name,
+  );
+   
   $remote_dbs = array('Pubmed' => 'Pubmed');
   $form['remote_db'] = array(
     '#title' => t('Remote Publication Database'),
@@ -38,28 +119,79 @@ function tripal_pub_remote_search_form(&$form_state = NULL) {
     '#default_value' => $remote_db,
   );
 
-  $form['search_terms']= array(
-    '#type'          => 'textfield',
-    '#description'   => t('Please provide a list of words, separated by spaces for searching.'),
-    '#default_value' => $search_terms,
-  );
-  $form['scope']= array(
-    '#type'          => 'select',
-    '#description'   => t('Please select the fields to search for this term.'),
-    '#options'       => array('title'    => 'Title',
-                              'abstract' => 'Title/Abstract',
-                              'author'   => 'Author'),
-    '#default_value' => $scope,
-  );
-  $form['operation']= array(
-    '#type'          => 'select',
-    '#options'       => array('AND' => 'AND',
-                              'OR'  => 'OR',
-                              'NOT' => 'NOT'),
-    '#default_value' => $operation,
+  $form['num_criteria']= array(
+    '#type'          => 'hidden',
+    '#default_value' => $num_criteria,
   );
+  
+  for($i = 0; $i <= $num_criteria; $i++) {
+    $search_terms = $form_state['values']["search_terms-$i"] ? $form_state['values']["search_terms-$i"] : $_SESSION['tripal_pub_search']['criteria'][$i]['search_terms'];
+    $scope = $form_state['values']["scope-$i"] ? $form_state['values']["scope-$i"] : $_SESSION['tripal_pub_search']['criteria'][$i]['scope'];
+    $operation = $form_state['values']["operation-$i"] ? $form_state['values']["operation-$i"] : $_SESSION['tripal_pub_search']['criteria'][$i]['operation'];
+    
+    // default to searching the title and abstract
+    if (!$scope) {
+      $scope = 'abstract';
+    }
+  
+    $form['criteria'][$i]["search_terms-$i"] = array(
+      '#type'          => 'textfield',
+      '#description'   => t('Please provide a list of words, separated by spaces for searching.'),
+      '#default_value' => $search_terms,
+    );
+    $form['criteria'][$i]["scope-$i"] = array(
+      '#type'          => 'select',
+      '#description'   => t('Please select the fields to search for this term.'),
+      '#options'       => array(
+        'any'      => 'Any Field',
+        'title'    => 'Title',
+        'abstract' => 'Title/Abstract',
+        'author'   => 'Author'),
+      '#default_value' => $scope,
+    );    
+    
+    if ($i > 0) {
+      $form['criteria'][$i]["operation-$i"] = array(
+        '#type'          => 'select',
+        '#options'       => array(
+          'AND' => 'AND',
+          'OR'  => 'OR',
+          'NOT' => 'NOT'),
+        '#default_value' => $operation,
+      );
+    }
+    if ($i == $num_criteria) {    
+      if($i > 0) {
+        $form['criteria'][$i]["remove-$i"] = array(
+          '#type'         => 'image_button',
+          '#value'        => t('Remove'),
+          '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
+          '#ahah' => array(
+            'path'    => "admin/tripal/tripal_pub/import_setup/criteria/minus/$i",
+            'wrapper' => 'tripal-pub-remote-search-form',
+            'event'   => 'click',
+            'method'  => 'replace',
+          ), 
+          '#attributes' => array('onClick' => 'return false;'),
+        );
+      }
+      $form['criteria'][$i]["add-$i"] = array(
+        '#type'         => 'image_button',      
+        '#value'        => t('Add'),
+        '#src'          => drupal_get_path('theme', 'tripal') . '/images/add.png',
+        '#ahah' => array(
+          'path'    => "admin/tripal/tripal_pub/import_setup/criteria/add/$i",
+          'wrapper' => 'tripal-pub-remote-search-form',
+          'event'   => 'click',
+          'method'  => 'replace',          
+        ),   
+        '#attributes' => array('onClick' => 'return false;'),
+      );
+    }
+  }
 
-  $form['days']= array(
+  
+  $form['days'] = array(
     '#type'          => 'textfield',
     '#title'         => t('Number of Days'),
     '#description'   => t('Please provide the number of days to limit your search.  For example, to search only the last 60 days, enter the number 60 in the field.'),
@@ -68,8 +200,11 @@ function tripal_pub_remote_search_form(&$form_state = NULL) {
   
   $form['submit'] = array(
     '#type'         => 'submit',
-    '#value'        => t('Submit'),
-    '#executes_submit_callback' => TRUE,
+    '#value'        => t('Test Criteria'),
+  );
+  $form['submit'] = array(
+    '#type'         => 'submit',
+    '#value'        => t('Save Criteria'),
   );
 
   return $form;
@@ -79,14 +214,21 @@ function tripal_pub_remote_search_form(&$form_state = NULL) {
  *
  */
 function tripal_pub_remote_search_form_validate($form, &$form_state) {
-  $remote_db =  $form_state['values']['remote_db'];
-  $search_terms =  $form_state['values']['search_terms'];
-  $scope =  $form_state['values']['scope'];
-  $operation =  $form_state['values']['operation'];
-  $days =  $form_state['values']['days'];
-  
-  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.");
+  $num_criteria = $form_state['values']['num_criteria'];
+  $remote_db =  $form_state['values']["remote_db"];
+  $days =  trim($form_state['values']["days"]);
+
+  for ($i = 0; $i <= $num_criteria; $i++) {            
+    $search_terms =  trim($form_state['values']["search_terms-$i"]);
+    $scope =  $form_state['values']["scope-$i"];
+    $operation =  $form_state['values']["operation-$i"];
+    
+    if ($days and !is_numeric($days) or preg_match('/\./', $days)) {
+      form_set_error("days-$i", "Please enter a numeric, non decimal value, for the number of days.");
+    }
+    if (!$search_terms) {
+      form_set_error("search_terms-$i", "Please enter a value for searching.");
+    }
   }
 }
 
@@ -94,79 +236,25 @@ function tripal_pub_remote_search_form_validate($form, &$form_state) {
  *
  */
 function tripal_pub_remote_search_form_submit($form, &$form_state) {
-  
-  $remote_db =  $form_state['values']['remote_db'];
-  $search_terms =  $form_state['values']['search_terms'];
-  $scope =  $form_state['values']['scope'];
-  $operation =  $form_state['values']['operation'];
-  $days =  $form_state['values']['days'];
-  
-  // store the search settings in a session variable. Then when the page
-  // is refreshed these values will be available for the page to 
-  // generate results. 
-  if ($op == 'Reset') {   
-    unset($_SESSION['tripal_pub_search_criteria']); 
-    unset($form_state['values']);
-  }
-  else {
-    $_SESSION['tripal_pub_search_criteria'] = array(
-      'remote_db' => $remote_db,
+ 
+  $num_criteria = $form_state['values']['num_criteria'];
+  $remote_db =  $form_state['values']["remote_db"];
+  $days =  trim($form_state['values']["days"]);
+    
+  $_SESSION['tripal_pub_search']['remote_db'] = $remote_db;
+  $_SESSION['tripal_pub_search']['days'] = $days;
+  $_SESSION['tripal_pub_search']['num_criteria'] = $num_criteria;
+  for ($i = 0; $i <= $num_criteria; $i++) {
+    $search_terms =  trim($form_state['values']["search_terms-$i"]);
+    $scope =  $form_state['values']["scope-$i"];
+    $operation =  $form_state['values']["operation-$i"];
+    
+    $_SESSION['tripal_pub_search']['criteria'][$i] = array(
       'search_terms' => $search_terms,
       'scope' => $scope,
-      'operation' => $operation,
-      'days' => $days
+      'operation' => $operation
     );
-  }  
-}
-/*
- * 
- */
-function tripal_pub_remote_search_page() {
-  global $pager_total, $pager_total_items;
-  
-  $pager_id = 0;
-  $limit = 10;
-  
-  // generate the search form 
-  $form = drupal_get_form('tripal_pub_remote_search_form');
-
-  // retrieve any results
-  $remote_db = $_SESSION['tripal_pub_search_criteria']['remote_db'];
-  
-  $search_array['search_terms'] = $_SESSION['tripal_pub_search_criteria']['search_terms'];
-  $search_array['days'] = $_SESSION['tripal_pub_search_criteria']['days'];  
-  $search_array['scope'] = $_SESSION['tripal_pub_search_criteria']['scope'];  
-  $search_array['operation'] = $_SESSION['tripal_pub_search_criteria']['operation'];
-    
-  // 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);
-
-  // 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) {
-      $rows[] = array(number_format($i), $pub['citation']);
-      $i++;
-    }
-  }
-  $headers = array('', 'Citation');
-  $table = theme('table', $headers, $rows);
-  
-
-  
-  // join all to form the final page
-  $output = $form . "<p><b>Found " . number_format($total_items) .  
-    ". Page " . ($page + 1) . " of $total_pages. " .
-    " Results</b></br>" . $table . '</p>' . $pager;    
-  
-  return $output;
+  } 
 }
 /*
  * 
@@ -185,3 +273,26 @@ function tripal_pub_get_remote_search_results($remote_db, $search_array, $num_to
   return $pubs;  
 }
 
+/*
+ * AHAH callback
+ */
+function tripal_pub_remote_search_page_update_criteria($action, $i) {
+  $status = TRUE;
+
+  // prepare and render the form
+  $form = tripal_core_ahah_prepare_form();   
+  $data = theme('tripal_pub_remote_search_form', $form);  
+
+  // bind javascript events to the new objects that will be returned 
+  // so that AHAH enabled elements will work.
+  $settings = tripal_core_ahah_bind_events();
+
+  // return the updated JSON
+  drupal_json(
+    array(
+      'status'   => $status, 
+      'data'     => $data,
+      'settings' => $settings,
+    )  
+  );
+}

+ 29 - 3
tripal_pub/tripal_pub.module

@@ -15,6 +15,15 @@ require_once "includes/remote_search.inc";
  */
 
 
+/**
+ *
+ * @ingroup tripal_pub
+ */
+function tripal_pub_init() {
+  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_pub.js');
+}
+
+
 /**
  * Implementation of hook_tripal_pub_node_info().
  *
@@ -69,10 +78,17 @@ function tripal_pub_menu() {
   );
 
   $items['admin/tripal/tripal_pub/import_setup'] = array(
-    'title' => t('Publication Finder'),
+    'title' => t('Pub Loader Setup'),
     'description' => t('Finds publications using remote publication databases (e.g. PubMed).'),
     'page callback' => 'tripal_pub_remote_search_page',
-    'access arguments' => array('access content'),
+    'access arguments' => array('administer tripal pubs'),
+    'type ' => MENU_CALLBACK,
+  );
+  
+  $items['admin/tripal/tripal_pub/import_setup/criteria/%/%'] = array(
+    'page callback' => 'tripal_pub_remote_search_page_update_criteria',
+    'page arguments' => array(5, 6),
+    'access arguments' => array('administer tripal pubs'),    
     'type ' => MENU_CALLBACK,
   );
   
@@ -1246,5 +1262,15 @@ function publication_author_validate($element) {
   }
 }
 
+/*
+ * 
+ */
 
-
+function tripal_pub_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == "tripal_pub_remote_search_form") {    
+    // updating the form through the ahah callback sets the action of
+    // the form to the ahah callback URL. We need to set it back
+    // to the normal form URL
+    $form['#action'] = url("admin/tripal/tripal_pub/import_setup");
+  }
+}