فهرست منبع

Added ability for admin to limit which fields users can search by. Helps simplify the list

spficklin 12 سال پیش
والد
کامیت
45de9114aa
2فایلهای تغییر یافته به همراه54 افزوده شده و 3 حذف شده
  1. 5 1
      tripal_pub/includes/pub_search.inc
  2. 49 2
      tripal_pub/includes/tripal_pub.admin.inc

+ 5 - 1
tripal_pub/includes/pub_search.inc

@@ -136,9 +136,13 @@ function tripal_pub_search_form(&$form_state = NULL) {
       NOT CVTS.is_obsolete = 1
     ORDER BY CVTS.name ASC 
   ";
+  $allowed_fields = variable_get('tripal_pub_allowed_search_fields', array());
+  dpm($allowed_fields);
   $prop_types = chado_query($sql); 
   while ($prop = db_fetch_object($prop_types)) {
-    $properties[$prop->cvterm_id] = $prop->name;
+    if($allowed_fields[$prop->cvterm_id] > 0) {
+      $properties[$prop->cvterm_id] = $prop->name;
+    }
   }
   
   for($i = 1; $i <= $num_criteria; $i++) {

+ 49 - 2
tripal_pub/includes/tripal_pub.admin.inc

@@ -18,6 +18,7 @@ function tripal_pub_admin() {
 
   // add the field set for syncing publications
   if (!$active_jobs) {
+    get_tripal_pub_admin_form_select_search_list($form);    
     get_tripal_pub_admin_form_cleanup_set($form);
   }
   else {
@@ -60,6 +61,44 @@ function get_tripal_pub_admin_form_cleanup_set(&$form) {
   );
 }
 
+/**
+ *
+ *
+ * @ingroup tripal_pub
+ */
+function get_tripal_pub_admin_form_select_search_list(&$form) {
+  $form['searching'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Searching Options')
+  );
+  // get publication properties list 
+  $properties = array();
+  $properties[] = 'Any Field';
+  $sql = "
+    SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
+    FROM {cvtermpath} CVTP
+      INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
+      INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
+      INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
+    WHERE CV.name = 'tripal_pub' and 
+      (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and 
+      NOT CVTS.is_obsolete = 1
+    ORDER BY CVTS.name ASC 
+  ";
+  $prop_types = chado_query($sql); 
+  while ($prop = db_fetch_object($prop_types)) {
+    $properties[$prop->cvterm_id] = $prop->name;
+  }
+  $form['searching']['allowed_search_fields'] = array(
+     '#type'    => 'checkboxes',
+     '#options' => $properties,
+     '#description'   => t("Please select the publication details that users can search by in the publication search form.  If none are selected then all fields will be available to the user."),
+     '#prefix'  => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
+     '#suffix'  => '</div>',
+     '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
+  );
+}
+
 /**
  *
  * @ingroup tripal_pub
@@ -68,9 +107,17 @@ function tripal_pub_admin_validate($form, &$form_state) {
   global $user;  // we need access to the user info
   $job_args = array();
 
-
+  // set the allowed search fields
+  $allowed_fields = $form_state['values']['allowed_search_fields'];
+  foreach ($allowed_fields as $cvterm_id => $selected) {
+    if (!$selected) {
+      unset($allowed_fields[$cvterm_id]);
+    }  
+  }
+  variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
+    
   // -------------------------------------
-  // Submit the Cleanup Job if selected
+  // Submit the Cleanup Job if selected  
   if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
     tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
        'tripal_pub_cleanup', $job_args, $user->uid);