function tripal_pub_search_form
2.x tripal_pub.pub_search.inc | tripal_pub_search_form( |
1.x pub_search.inc | tripal_pub_search_form(&$form_state = NULL) |
Purpose: Provides the form to search pubmed
4 string references to 'tripal_pub_search_form'
- tripal_pub_search_form_submit in tripal_pub/
includes/ pub_search.inc - tripal_pub_search_page in tripal_pub/
includes/ pub_search.inc - tripal_pub_search_page_update_criteria in tripal_pub/
includes/ pub_search.inc - tripal_pub_theme in tripal_pub/
tripal_pub.module - Implements hook_theme(): Register themeing functions for this module
File
- tripal_pub/
includes/ pub_search.inc, line 88
Code
function tripal_pub_search_form(&$form_state = NULL) {
tripal_core_ahah_init_form();
// Set the default values. If the pub_import_id isn't already defined by the form values
// and one is provided then look it up in the database
$criteria = NULL;
// if the session has variables then use those. This should only happen when
// the 'Test Criteria' button is clicked.
$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 the form_state has variables then use those. This happens when an error occurs on the form or the
// form is resbumitted using AJAX
$num_criteria = $form_state['values']['num_criteria'] ? $form_state['values']['num_criteria'] : $num_criteria;
// change the number of criteria based on form_state post data.
if (!$num_criteria) {
$num_criteria = 2;
}
if ($form_state['post']["add-$num_criteria"]) {
$num_criteria++;
}
if ($form_state['post']["remove-$num_criteria"]) {
$num_criteria--;
}
$form['num_criteria'] = array(
'#type' => 'hidden',
'#default_value' => $num_criteria,
);
$form['instructions'] = array(
'#type' => 'item',
'#value' => 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 plus and minus symbols to add additional fields for searching. '),
);
// 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
";
$allowed_fields = variable_get('tripal_pub_allowed_search_fields', array());
$prop_types = chado_query($sql);
while ($prop = db_fetch_object($prop_types)) {
if ($allowed_fields[$prop->cvterm_id] > 0) {
$properties[$prop->cvterm_id] = $prop->name;
}
}
for ($i = 1; $i <= $num_criteria; $i++) {
$search_terms = '';
$scope = '';
$operation = '';
$mode = '';
// if we have criteria supplied from the database then use that, othrewise look from the form_state or the session
if ($criteria) {
$search_terms = $criteria['criteria'][$i]['search_terms'];
$scope = $criteria['criteria'][$i]['scope'];
$mode = $criteria['criteria'][$i]['mode'];
$operation = $criteria['criteria'][$i]['operation'];
}
// first populate defaults using any values in the SESSION variable
$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;
// next populate defaults using any form values
$search_terms = $form_state['values']["search_terms-$i"] ? $form_state['values']["search_terms-$i"] : $search_terms;
$scope = $form_state['values']["scope-$i"] ? $form_state['values']["scope-$i"] : $scope;
$mode = $form_state['values']["mode-$i"] ? $form_state['values']["mode-$i"] : $mode;
$operation = $form_state['values']["operation-$i"] ? $form_state['values']["operation-$i"] : $operation;
// default to searching the title and abstract
if (!$scope) {
$scope = 'abstract';
}
$form['criteria'][$i]["search_terms-$i"] = array(
'#type' => 'textfield',
'#default_value' => $search_terms,
'#required' => FALSE,
);
$form['criteria'][$i]["scope-$i"] = array(
'#type' => 'select',
'#options' => $properties,
'#default_value' => $scope,
'#attributes' => array('class' => 'tripal-pub-search-form-scope-select'),
);
/*
$form['criteria'][$i]["mode-$i"] = array(
'#type' => 'select',
'#options' => array(
'Contains' => 'Contains',
'Starts With' => 'Starts With',
'Ends With' => 'Ends With',
'Exactly' => 'Exactly'),
'#default_value' => $mode,
);*/
if ($i > 1) {
$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 > 1) {
$form['criteria'][$i]["remove-$i"] = array(
'#type' => 'image_button',
'#value' => t('Remove'),
'#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
'#ahah' => array(
'path' => "find/publications/criteria/minus/$i",
'wrapper' => 'tripal-pub-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' => "find/publications/criteria/add/$i",
'wrapper' => 'tripal-pub-search-form',
'event' => 'click',
'method' => 'replace',
),
'#attributes' => array('onClick' => 'return false;'),
);
}
}
$form['criteria']["date"] = array(
'#type' => 'select',
'#options' => array('Years' => 'Years'),
'#attributes' => array('class' => 'tripal-pub-search-form-scope-select'),
);
$form['criteria']["from_year"] = array(
'#type' => 'textfield',
'#default_value' => $from_year,
'#required' => FALSE,
'#title' => 'from',
'#size' => 4,
'#maxlength' => 4,
);
$form['criteria']["to_year"] = array(
'#type' => 'textfield',
'#default_value' => $to_year,
'#required' => FALSE,
'#title' => 'to',
'#size' => 4,
'#maxlength' => 4,
);
$form['search'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
);
return $form;
}