Browse Source

Working on moving pub search from legacy to core

Stephen Ficklin 7 years ago
parent
commit
d679211286

+ 0 - 45
legacy/tripal_pub/includes/tripal_pub.admin.inc

@@ -66,42 +66,6 @@ function tripal_pub_admin() {
   // This sub-form handles it's own validation & submit
   chado_add_admin_form_set_title($form, $form_state, $details);
 
-  // -----------------------------------------
-  // add in the fields for selecting which fields are used when search for pubs
-  $form['searching'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Searching Options'),
-    '#description' => t("The list of checkboxes below indicate which fields a user
-      can search with when using the publication search tool.  Check the fields that you want
-      to allow users to search with.  Click the 'Save configuration' button below to save changes."),
-  );
-
-  // 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 = $prop_types->fetchObject()) {
-    $properties[$prop->cvterm_id] = $prop->name;
-  }
-  $form['searching']['allowed_search_fields'] = array(
-    '#type'    => 'checkboxes',
-    '#options' => $properties,
-    '#prefix'  => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
-    '#suffix'  => '</div>',
-    '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
-  );
-
   // -----------------------------------------
   // add the field set for syncing publications
   $form['import'] = array(
@@ -179,15 +143,6 @@ 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);
-
   $import_duplicate_check = $form_state['values']['import_duplicate_check'];
   variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
 

+ 2 - 2
legacy/tripal_pub/theme/templates/tripal_pub_help.tpl.php

@@ -29,7 +29,7 @@ have been added to Chado database.</p>
   </li>
   <li>
   <p><b>Configure the Search Behavior</b>: Before allowing site visitors
-  to search for publications visit the <?php print l('configuration page', 'admin/tripal/tripal_pub/configuration') ?>
+  to search for publications visit the <?php print l('configuration page', 'admin/tripal/storage/chado/pub-search-config') ?>
   to disable or enable fields for searching. Tripal uses its own ontology
   for storing publication information in Chado, and all child terms of
   the "Publication Details" are made available for searching. However,
@@ -48,7 +48,7 @@ have been added to Chado database.</p>
     <li>Install the PHP YAZ extension: sudo pecl install yaz</li>
     <li>Add the text 'extension=yaz.so' to the appropriate php.ini file
     (e.g. /etc/php5/apache2filter/php.ini). On Ubuntu you may need to
-    add it to the php.ini file specfic for the Apache webserver and 
+    add it to the php.ini file specfic for the Apache webserver and
     also to the php.ini specific for the command-line.</li>
     <li>Restart the webserver</li>
   </ol>

+ 0 - 14
legacy/tripal_pub/tripal_pub.module

@@ -10,7 +10,6 @@ require_once 'theme/tripal_pub.theme.inc';
 
 require_once 'includes/tripal_pub.admin.inc';
 require_once 'includes/tripal_pub.chado_node.inc';
-require_once 'includes/tripal_pub.pub_search.inc';
 
 /**
  * @defgroup tripal_pub Publication Module
@@ -53,20 +52,7 @@ function tripal_pub_menu() {
 
   // for backwards compatibility the same chado/publications is also found
   // at find/publications
-  $items['find/publications' ]= array(
-    'title' => 'Publication Search',
-    'description' => ('Search for publications'),
-    'page callback' => 'tripal_pub_search_page',
-    'access arguments' => array('access chado_pub content'),
-    'type' => MENU_CALLBACK
-  );
 
-  $items['find/publications/criteria/%/%'] = array(
-    'page callback' => 'tripal_pub_search_page_update_criteria',
-    'page arguments' => array(5, 6),
-    'access arguments' => array('access chado_pub content'),
-    'type ' => MENU_CALLBACK,
-  );
 
   $items['admin/tripal/legacy/tripal_pub']= array(
     'title' => 'Publications',

+ 214 - 165
legacy/tripal_pub/includes/tripal_pub.pub_search.inc → tripal_chado/includes/tripal_chado.pub_search.inc

@@ -7,12 +7,68 @@
  * in Chado.
  */
 
+function tripal_chado_pub_search_admin_form($form, &$form_state) {
+  // -----------------------------------------
+  // add in the fields for selecting which fields are used when search for pubs
+  $form['searching'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Searching Options'),
+    '#description' => t("The list of checkboxes below indicate which fields a user
+      can search with when using the publication search tool.  Check the fields that you want
+      to allow users to search with.  Click the 'Save configuration' button below to save changes."),
+  );
+
+  // 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 = $prop_types->fetchObject()) {
+    $properties[$prop->cvterm_id] = $prop->name;
+  }
+  $form['allowed_search_fields'] = array(
+    '#type'    => 'checkboxes',
+    '#options' => $properties,
+    '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
+  );
+
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => 'Save configuration',
+    '#name' => 'sumbit',
+  );
+  return $form;
+}
+/**
+ *
+ */
+function tripal_chado_pub_search_admin_form_submit($form, &$form_state) {
+  // 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);
+  drupal_set_message('Changes saved.');
+}
 /**
  * The page that contains the publication search form and the results for the search
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_page() {
+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
@@ -22,117 +78,111 @@ function tripal_pub_search_page() {
   $limit = 25;
 
   // generate the search form
-  $form = drupal_get_form('tripal_pub_search_form');
+  $form = drupal_get_form('tripal_chado_pub_search_form');
   $output = drupal_render($form);
 
   // retrieve any results
-  if (array_key_exists('tripal_pub_search_form', $_SESSION) and
-      $_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'];
-    }
+  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 = tripal_get_chado_entity_id ('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);
 
-    // 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)
-      $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 = tripal_get_chado_entity_id ('pub', $pub->pub_id);
-      if ($entity_id) {
-        $link = "/bio_data/$entity_id";
+        // join all to form the results
+        $output .= "<p><b>Found " . number_format($total_records) .
+        " Results</b></br>" . $results . $pager;
       }
-      
-      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++;
-    }
-
-    if (count($rows) == 0) {
-      $rows[] = array(
-        array(
-          'data' => 'No results found',
-          'colspan' => 3
-        )
-      );
-    }
-
-    $headers = array('', 'Year', 'Publication');
-    $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' => '',
-    );
-    $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;
+      return $output;
 }
 
 /**
@@ -140,7 +190,7 @@ function tripal_pub_search_page() {
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_form($form, &$form_state) {
+function tripal_chado_pub_search_form($form, &$form_state) {
   // Default values can come in the following ways:
   //
   // 1) as elements of the $pub_importer object.  This occurs when editing an existing importer
@@ -162,10 +212,10 @@ function tripal_pub_search_form($form, &$form_state) {
   if (array_key_exists('storage', $form_state)) {
     $num_criteria = $form_state['storage']['num_criteria'];
   }
-  if (array_key_exists('tripal_pub_search_form', $_SESSION)) {
-    $num_criteria = $_SESSION['tripal_pub_search_form']['num_criteria'] ? $_SESSION['tripal_pub_search_form']['num_criteria'] : $num_criteria;
-    $from_year    = $_SESSION['tripal_pub_search_form']['from_year']    ? $_SESSION['tripal_pub_search_form']['from_year']    : '';
-    $to_year      = $_SESSION['tripal_pub_search_form']['to_year']      ? $_SESSION['tripal_pub_search_form']['to_year']      : '';
+  if (array_key_exists('tripal_chado_pub_search_form', $_SESSION)) {
+    $num_criteria = $_SESSION['tripal_chado_pub_search_form']['num_criteria'] ? $_SESSION['tripal_chado_pub_search_form']['num_criteria'] : $num_criteria;
+    $from_year    = $_SESSION['tripal_chado_pub_search_form']['from_year']    ? $_SESSION['tripal_chado_pub_search_form']['from_year']    : '';
+    $to_year      = $_SESSION['tripal_chado_pub_search_form']['to_year']      ? $_SESSION['tripal_chado_pub_search_form']['to_year']      : '';
   }
   if (array_key_exists('values', $form_state)) {
     $from_year    = $form_state['values']['from_year']    ? $form_state['values']['from_year']    : $from_year;
@@ -178,27 +228,27 @@ function tripal_pub_search_form($form, &$form_state) {
 
   if (array_key_exists('triggering_element', $form_state) and
       $form_state['triggering_element']['#name'] == 'add') {
-    $num_criteria++;
+        $num_criteria++;
   }
   if (array_key_exists('triggering_element', $form_state) and
       $form_state['triggering_element']['#name'] == 'remove') {
-    $num_criteria--;
+        $num_criteria--;
   }
 
   $form_state['storage']['num_criteria'] = $num_criteria;
 
   $form['admin-instructions'] = array(
     '#markup'  =>  tripal_set_message(
-      t('Administrators, you can select the fields with which a user can use to search, by checking the desired fields on the ' .
-        l('Publication Module Settings Page', 'admin/tripal/legacy/tripal_pub/configuration', array('attributes' => array('target' => '_blank'))) . '
-        in the section titled "Search Options".  The selected fields will appear in the dropdowns below.'),
+        t('Administrators, you can select the fields with which a user can use to search, by checking the desired fields on the ' .
+        l('Publication Search Settings Page', 'admin/tripal/storage/chado/pub-search-config', array('attributes' => array('target' => '_blank'))) . '
+      in the section titled "Search Options".  The selected fields will appear in the dropdowns below.'),
       TRIPAL_INFO,
       array('return_html' => 1)),
   );
   $form['instructions'] = array(
     '#markup'  =>  t('To search for publications enter keywords in the text boxes below.
-        You can limit your search by selecting the field in the dropdown box. Click the
-        add and remove buttons to add additional fields for searching. '),
+    You can limit your search by selecting the field in the dropdown box. Click the
+    add and remove buttons to add additional fields for searching. '),
   );
 
   // get publication properties list
@@ -230,11 +280,11 @@ function tripal_pub_search_form($form, &$form_state) {
     $mode = '';
 
     // first populate defaults using any values in the SESSION variable
-    if (array_key_exists('tripal_pub_search_form', $_SESSION)) {
-      $search_terms = $_SESSION['tripal_pub_search_form']['criteria'][$i]['search_terms'] ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['search_terms'] : $search_terms;
-      $scope        = $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope']        ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['scope']        : $scope;
-      $mode         = $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode']         ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['mode']         : $mode;
-      $operation    = $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation']    ? $_SESSION['tripal_pub_search_form']['criteria'][$i]['operation']    : $operation;
+    if (array_key_exists('tripal_chado_pub_search_form', $_SESSION)) {
+      $search_terms = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['search_terms'] ? $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['search_terms'] : $search_terms;
+      $scope        = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['scope']        ? $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['scope']        : $scope;
+      $mode         = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['mode']         ? $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['mode']         : $mode;
+      $operation    = $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['operation']    ? $_SESSION['tripal_chado_pub_search_form']['criteria'][$i]['operation']    : $operation;
     }
     if (array_key_exists('values', $form_state)) {
       $search_terms = array_key_exists("search_terms-$i", $form_state['values']) ? $form_state['values']["search_terms-$i"] : $search_terms;
@@ -306,8 +356,8 @@ function tripal_pub_search_form($form, &$form_state) {
           // but we need it or Drupal will run the default validate anyway.
           // we also set #limit_validation_errors to empty so fields that
           // are required that don't have values won't generate warnings.
-          '#submit'   => array('tripal_pub_search_form_ajax_button_submit'),
-          '#validate' => array('tripal_pub_search_form_ajax_button_validate'),
+          '#submit'   => array('tripal_chado_pub_search_form_ajax_button_submit'),
+          '#validate' => array('tripal_chado_pub_search_form_ajax_button_validate'),
           '#limit_validation_errors' => array(),
         );
       }
@@ -329,16 +379,16 @@ function tripal_pub_search_form($form, &$form_state) {
         // but we need it or Drupal will run the default validate anyway.
         // we also set #limit_validation_errors to empty so fields that
         // are required that don't have values won't generate warnings.
-        '#submit'   => array('tripal_pub_search_form_ajax_button_submit'),
-        '#validate' => array('tripal_pub_search_form_ajax_button_validate'),
+        '#submit'   => array('tripal_chado_pub_search_form_ajax_button_submit'),
+        '#validate' => array('tripal_chado_pub_search_form_ajax_button_validate'),
         '#limit_validation_errors' => array(),
       );
     }
   }
   $form['criteria']["date"] = array(
-      '#type'          => 'select',
-      '#options'       => array('Years' => 'Years'),
-      '#attributes'    => array('class' => array('tripal-pub-search-form-scope-select')),
+    '#type'          => 'select',
+    '#options'       => array('Years' => 'Years'),
+    '#attributes'    => array('class' => array('tripal-pub-search-form-scope-select')),
   );
   $form['criteria']["from_year"] = array(
     '#type'          => 'textfield',
@@ -366,7 +416,7 @@ function tripal_pub_search_form($form, &$form_state) {
     '#value'        => t('Reset'),
   );
 
-  $form['criteria']['#theme'] = 'tripal_pub_search_setup_form_elements';
+  $form['criteria']['#theme'] = 'tripal_chado_pub_search_setup_form_elements';
 
   return $form;
 }
@@ -379,7 +429,7 @@ function tripal_pub_search_form($form, &$form_state) {
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_form_ajax_button_submit() {
+function tripal_chado_pub_search_form_ajax_button_submit() {
   $form_state['rebuild'] = TRUE;
 }
 
@@ -388,16 +438,16 @@ function tripal_pub_search_form_ajax_button_submit() {
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_form_ajax_button_validate() {
+function tripal_chado_pub_search_form_ajax_button_validate() {
   // do nothing
 }
 
 /**
- * Validate the tripal_pub_search_form form
+ * Validate the tripal_chado_pub_search_form form
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_form_validate($form, &$form_state) {
+function tripal_chado_pub_search_form_validate($form, &$form_state) {
   $num_criteria = $form_state['storage']['num_criteria'];
   $from_year    = $form_state['values']['from_year'];
   $to_year      = $form_state['values']['to_year'];
@@ -423,11 +473,11 @@ function tripal_pub_search_form_validate($form, &$form_state) {
 }
 
 /**
- * Submit the tripal_pub_search_form form
+ * Submit the tripal_chado_pub_search_form form
  *
  * @ingroup tripal_pub
  */
-function tripal_pub_search_form_submit($form, &$form_state) {
+function tripal_chado_pub_search_form_submit($form, &$form_state) {
   $num_criteria = $form_state['storage']['num_criteria'];
   $from_year    = $form_state['values']['from_year'];
   $to_year      = $form_state['values']['to_year'];
@@ -435,8 +485,8 @@ function tripal_pub_search_form_submit($form, &$form_state) {
 
   // set the session variables
   if($op == 'Search') {
-    $_SESSION['tripal_pub_search_form']['num_criteria'] = $num_criteria;
-    unset($_SESSION['tripal_pub_search_form']['criteria']);
+    $_SESSION['tripal_chado_pub_search_form']['num_criteria'] = $num_criteria;
+    unset($_SESSION['tripal_chado_pub_search_form']['criteria']);
     for ($i = 0; $i <= $num_criteria; $i++) {
       $search_terms = '';
       $scope = '';
@@ -453,7 +503,7 @@ function tripal_pub_search_form_submit($form, &$form_state) {
       }
       //$mode =  $form_state['values']["mode-$i"];
 
-      $_SESSION['tripal_pub_search_form']['criteria'][$i] = array(
+      $_SESSION['tripal_chado_pub_search_form']['criteria'][$i] = array(
         'search_terms' => $search_terms,
         'scope' => $scope,
         'mode' => $mode,
@@ -461,12 +511,12 @@ function tripal_pub_search_form_submit($form, &$form_state) {
       );
 
     }
-    $_SESSION['tripal_pub_search_form']['from_year'] = $from_year;
-    $_SESSION['tripal_pub_search_form']['to_year'] = $to_year;
-    $_SESSION['tripal_pub_search_form']['perform_search'] = 1;
+    $_SESSION['tripal_chado_pub_search_form']['from_year'] = $from_year;
+    $_SESSION['tripal_chado_pub_search_form']['to_year'] = $to_year;
+    $_SESSION['tripal_chado_pub_search_form']['perform_search'] = 1;
   }
   if($op == 'Reset') {
-    unset($_SESSION['tripal_pub_search_form']);
+    unset($_SESSION['tripal_chado_pub_search_form']);
   }
 }
 
@@ -486,11 +536,11 @@ function tripal_pubs_search_form_ajax_update($form, $form_state) {
 }
 
 /**
- * Theme the tripal_pub_search_setup_form form
+ * Theme the tripal_chado_pub_search_setup_form form
  *
  * @ingroup tripal_pub
  */
-function theme_tripal_pub_search_setup_form_elements($variables) {
+function theme_tripal_chado_pub_search_setup_form_elements($variables) {
   $form = $variables['form'];
 
   $rows = array();
@@ -516,13 +566,13 @@ function theme_tripal_pub_search_setup_form_elements($variables) {
     drupal_render($form['date']),
     array(
       'data' =>
-        "<div id=\"pub-search-form-dates-row\">
-           <div id=\"pub-search-form-dates\"> ".
-             drupal_render($form['from_year']) .
-             drupal_render($form['to_year']) . "
-           </div>
+      "<div id=\"pub-search-form-dates-row\">
+         <div id=\"pub-search-form-dates\"> ".
+           drupal_render($form['from_year']) .
+           drupal_render($form['to_year']) . "
          </div>
-        ",
+       </div>
+      ",
     ),
     ''
   );
@@ -551,19 +601,21 @@ function theme_tripal_pub_search_setup_form_elements($variables) {
 /**
  * Builds the SQL statement need to search Chado for the publications
  * that match the user supplied criteria.  Tpyically, this function is
- * called by the search form generated by the tripal_pub_search_form() function
- * but this function is included in the API for calling by anyone.
+ * called by the search form generated by the tripal_chado_pub_search_form()
+ * function but this function is included in the API for calling by anyone.
  *
  * @param $search_array
  *   An array of search criteria provided by the user. The search array is
  *   an associative array with the following keys:
- *     'num_criteria': an integer indicating the number of search criteria supplied
+ *     'num_criteria': an integer indicating the number of search criteria
+ *        supplied
  *     'from_year':    filters records by a start year
  *     'to_year':      filters records by an end year
  *     'criteria':     an array of criteria. Each criteria is an associative
  *                     array with the following keys:
  *                     'search_terms':   The text used for searching
- *                     'scope':          The cvterm_id of the property used for filtering
+ *                     'scope':          The cvterm_id of the property used for
+ *                        filtering
  *                     'mode':           The operation (e.g. AND, OR or NOT)
  * @param $offset
  *   The offset for paging records.  The first record returned will be
@@ -584,15 +636,12 @@ function theme_tripal_pub_search_setup_form_elements($variables) {
  */
 function tripal_search_publications($search_array, $offset, $limit, &$total_records) {
 
-  // build the SQL based on the criteria provided by the user
-  $select = "SELECT DISTINCT P.*, CP.nid ";
-  $from   = "FROM {pub} P
-               LEFT JOIN [chado_pub] CP on P.pub_id = CP.pub_id
-               INNER JOIN {cvterm} CVT on CVT.cvterm_id = P.type_id
-            ";
-  $where  = "WHERE (NOT P.title = 'null') "; // always exclude the dummy pub
+  // Build the SQL based on the criteria provided by the user
+  $select = "SELECT DISTINCT P.* ";
+  $from   = "FROM {pub} P INNER JOIN {cvterm} CVT on CVT.cvterm_id = P.type_id ";
+  $where  = "WHERE (NOT P.title = 'null') ";
   $order  = "ORDER BY P.pyear DESC, P.title ASC";
-  $args = array();  // arguments for where clause
+  $args = array();
   $join = 0;
 
   $num_criteria = $search_array['num_criteria'];

+ 35 - 2
tripal_chado/tripal_chado.module

@@ -705,6 +705,39 @@ function tripal_chado_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  //////////////////////////////////////////////////////////////////////////////
+  //                           Publications
+  //////////////////////////////////////////////////////////////////////////////
+  $items['find/publications' ]= array(
+    'title' => 'Publication Search',
+    'description' => ('Search for publications'),
+    'page callback' => 'tripal_chado_pub_search_page',
+    'access arguments' => array('access chado_pub content'),
+    'file' =>  'includes/tripal_chado.pub_search.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK
+  );
+
+  $items['find/publications/criteria/%/%'] = array(
+    'page callback' => 'tripal_chado_pub_search_page_update_criteria',
+    'page arguments' => array(5, 6),
+    'access arguments' => array('access chado_pub content'),
+    'file' =>  'includes/tripal_chado.pub_search.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type ' => MENU_CALLBACK,
+  );
+
+  $items['admin/tripal/storage/chado/pub-search-config'] = array(
+    'title' => 'Publication Search Settings',
+    'description' => 'Configure the settings for the publication search.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_chado_pub_search_admin_form'),
+    'file' =>  'includes/tripal_chado.pub_search.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_NORMAL_ITEM,
+    'access arguments' => array('administer tripal'),
+  );
+
   return $items;
 }
 
@@ -757,9 +790,9 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
       'render element' => 'form',
       'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     ),
-    'tripal_pub_search_setup_form_elements' => array(
+    'tripal_chado_pub_search_setup_form_elements' => array(
       'render element' => 'form',
-      'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
+      'file' => 'includes/tripal_chado.pub_search.inc',
     ),
   );
 

+ 5 - 179
tripal_chado_views/api/tripal_chado_views.api.inc

@@ -4,181 +4,6 @@
  * API functions for Chado Views Integration
  */
 
- /**
- * @defgroup tripal_chado_views_api Tripal Views Module API
- * @ingroup tripal_api
- * @{
- * Provides functions to help extension modules add their own tripal views integrations
- * as well as functions for managing default views.
- *
- * Managing Default Views:
- *
- * When you create administrative default views (or really any default view) you really
- * have no way to ensure that the site administrator keeps these views enabled. In some
- * cases this is a good thing and provides the site administrator the ability to disable
- * views that don't apply to their particular installation or to replace your default view
- * with a custom view of their own. But in other cases, particularily for administration
- * views, you want to gaurd against accidental disabling of your views.
- *
- * One way to do this is to add a landing page using a heook_menu() definition to a custom
- * callback returning HTML. You can use this page to render the view if it is enabled but
- * provide logic to display a message if the view is disabled. Furthermore, it's often
- * helpful to provide a link allowing site administrators to enable the view from your
- * page rather than expecting them to go to the views administration UI. This is done for
- * all the administration views provided by Tripal. The following is an example of how to
- * achomplish this functionality for your own module:
- * @code
-function mymodule_menu() {
-  $items = array();
-
-  // Create the landing page
-  $items['admin/tripal/<PATH-TO-YOUR-LANDING-PAGE>'] = array(
-    'title' => 'MyModule Administration',
-    'description' => 'Administration of my module.',
-    'page callback' => 'mymodule_admin_landing_page',
-    'access arguments' => array('<YOUR-PERMISSION-KEY>'),
-    'type' => MENU_NORMAL_ITEM,
-  );
-
-  // Create one of these for each of your default views
-  $items['admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/enable'] = array(
-    'title' => 'Enable <VIEW-HUMAN-READABLE-NAME>',
-    'page callback' => 'tripal_enable_view',
-    'page arguments' => array('<VIEW-MACHINE-NAME>', '<PATH-TO-REDIRECT-TO-AFTERWARDS>'),
-    'access arguments' => array('<YOUR-PERMISSION-KEY>'),
-    'type' => MENU_CALLBACK,
-  );
-
-  return $items;
-}
-
-function mymodule_admin_landing_page() {
-
-  // Get the View Embed Code
-  // This function will return FALSE if your view is not enabled
-  $view_code = views_embed_view('<VIEW-MACHINE-NAME>', '<DISPLAY-MACHINE-NAME');
-  // If your view is enabled then embed it in this page by returning the embed code
-  if (isset($view_code)) {
-    $output .= $view_code;
-  }
-  else {
-    // Provide the landing page with links to the menu item created in hook_menu to
-    // to enable your view
-    $output .= '<p>The My Module module uses primarily views to provide an '
-      . 'administrative interface. Currently one or more views needed for this '
-      . 'administrative interface are disabled. <strong>Click each of the following links to '
-      . 'enable the pertinent views</strong>:</p>';
-    $output .= '<ul>';
-    // NOTE: <URL-FROM-MENU-TO-ENABLE-VIEW> is
-    // admin/tripal/<PATH-TO-YOUR-ADMIN-SECTION>/views/<VIEW-MACHINE-NAME>/enable
-    // from above hook_menu().
-    $output .= '<li>' . l('<VIEW-HUMAN-RADABLE-NAME>', '<URL-FROM-MENU-TO-ENABLE-VIEW>') . '</li>';
-    $output .= '</ul>';
-  }
-
-  return $output;
-}
-
- * @endcode
- *
- * Adding your own Chado Views Integrations:
- *
- * One of the main ways the Tripal View API is likely to be used is if your module needs
- * to create it's own tripal views integration. You might need to do this for any number of
- * reasons but the following examples are thought to be the most common:
- *
- *   1) Your module wants to add handlers with better functionality to fields it has more
- *       knowledge of than the general integration for all tables
- * @code
-   mymodule_views_data() {
-
-    // First check that your integration has not already been added
-    // When selecting a priority, do not choose -10 or -9 and make sure it is below 0
-    // so that individual sites still have the ability to override it, if needed
-    $table_name = 'my_chado_table';
-    $priority = -5;
-    if (!tripal_is_table_integrated($table_name, $priority)) {
-
-      // If you really only need to tweak an existing integration you can clone it
-      // If you want to clone the integration that is currently taking priority
-      // then use tripal_get_lightest_views_integration_priority() as below
-      $lightest_priority = tripal_get_lightest_views_integration_priority($table_name);
-      $setup_id = tripal_clone_views_integration($table_name, $priority, $lightest_priority);
-
-      // And then make a few changes
-      // First get the definition array created via the clone above
-      $defn_array = tripal_export_views_integration($setup_id);
-
-      // Then make some changes to the array here
-
-      // And finally save the changes to the integration
-      tripal_update_views_integration($setup_id, $defn_array);
-
-    }
-
-  }
- * @endcode
- *   2) Your module creates a chado table that is not already integrated.
- * @code
-  mymodule_views_data() {
-
-    // First check that your integration has not already been added
-    // When selecting a priority, do not choose 10 or 9 and make sure it is below 0
-    // so that individual sites still have the ability to override it, if needed
-    $table_name = 'my_chado_table';
-    $priority = 5;
-    if (!tripal_is_table_integrated($table_name, $priority)) {
-
-      // Describe your table using a large array as specified by tripal_add_views_integration().
-      $defn_array = array(
-        'table' => $table_name, //tablename or materialized view name
-        'name' => 'My Chado Table', // Human readable name
-        'type' => 'chado', //either chado or mview depending on tablename
-        'description' => 'Create a listing from my chado table.', //description seen when creating a view of this type
-        'priority' => $priority, //For Base tripal modules: 10; custom modules: 9 to 0;
-        'base_table' => TRUE //either TRUE or FALSE depending on whether the current table should show up in the add view list
-        'fields' => array(
-          'feature_id' => array(
-            'name' => 'feature_id', //field name in database
-            'title' => 'Feature ID', //human-readable name -seen in Views UI
-            'description' => 'This is the unique identifier for features', //help/description seen in Views UI
-            'type' => 'int', // the type of field
-            'handlers' => array(  //possible keys are field, filter, sort, argument, relationship
-              'field' => array(
-                'name' => 'chado_views_handler_numeric' //name of handler
-              ),
-              'filter' => array( ... ),
-              ...
-            ),
-            // Describe any joins involving this field.
-            // Note: you can include both foreign keys (feature.type_id => cvterm.cvterm_id)
-            // and referring tables (ie: feature.feature_id <= feature_relationship.subject_id)
-            'joins' => array(
-              'feature_relationship' => array( //table to join to.
-                'subject_id' => array( //field in above table (feature_relationship)
-                  'table' => 'featureprop', //table to join to
-                  'field' => 'feature_id', //field in above table (feature_relationship)
-                  'handler' => 'views_join', //handler to use for joining
-                  'relationship_handler' => 'views_handler_relationship', //handler to use when a relationship is added.
-                  'relationship_only' => FALSE, //whether to join automatically (FALSE) or not (TRUE)
-                ),
-                ...
-              ),
-              ...
-            ),
-          )
-        ),
-      );
-      // Actually create the entry
-      tripal_add_views_integration($defn_array);
-
-    }
-
-  }
- * @endcode
- * @}
- */
-
 /**
  * Programatically enable view
  *
@@ -839,10 +664,11 @@ function tripal_add_views_integration($defn_array, $setup_id = FALSE) {
 /**
  * Export Views integration records.
  *
- * This is a great way to create your own integration since it returns an already defined
- * integration in array form that you can modify. After modifications simply set the
- * priority to something lighter (but still below 0) than any existing integrations
- * and use tripal_add_views_integration() to add it to the list of integrations.
+ * This is a great way to create your own integration since it returns an
+ * already defined integration in array form that you can modify. After
+ * modifications simply set the priority to something lighter (but still
+ * below 0) than any existing integrations and use
+ * tripal_add_views_integration() to add it to the list of integrations.
  *
  * @param $setup_id
  *   The unique setup id of the tripal views integration