function chado_pub_form
2.x tripal_pub.chado_node.inc | chado_pub_form($node, $form_state) |
3.x tripal_pub.chado_node.inc | chado_pub_form($node, $form_state) |
1.x pub_form.inc | chado_pub_form($node, $form_state) |
File
- tripal_pub/
includes/ pub_form.inc, line 8
Code
function chado_pub_form($node, $form_state) {
tripal_core_ahah_init_form();
$form = array();
$pub = $node->pub;
$pub_id = $pub->pub_id;
$d_title = $form_state['values']['pubtitle'] ? $form_state['values']['pubtitle'] : $pub->title;
$d_uniquename = $form_state['values']['uniquename'] ? $form_state['values']['uniquename'] : $pub->uniquename;
$d_type_id = $form_state['values']['type_id'] ? $form_state['values']['type_id'] : $pub->type_id->cvterm_id;
$d_volume = $form_state['values']['volume'] ? $form_state['values']['volume'] : $pub->volume;
$d_volumetitle = $form_state['values']['volumetitle'] ? $form_state['values']['volumetitle'] : $pub->volumetitle;
$d_series_name = $form_state['values']['series_name'] ? $form_state['values']['series_name'] : $pub->series_name;
$d_issue = $form_state['values']['issue'] ? $form_state['values']['issue'] : $pub->issue;
$d_pyear = $form_state['values']['pyear'] ? $form_state['values']['pyear'] : $pub->pyear;
$d_pages = $form_state['values']['pages'] ? $form_state['values']['pages'] : $pub->pages;
$d_miniref = $form_state['values']['miniref'] ? $form_state['values']['miniref'] : $pub->miniref;
$d_publisher = $form_state['values']['publisher'] ? $form_state['values']['publisher'] : $pub->publisher;
$d_pubplace = $form_state['values']['pubplace'] ? $form_state['values']['pubplace'] : $pub->pubplace;
$d_is_obsolete = $form_state['values']['is_obsolete'] ? $form_state['values']['is_obsolete'] : $pub->is_obsolete;
// if the obsolete value is set by the database then it is in the form of
// 't' or 'f', we need to convert to 1 or 0
$d_is_obsolete = $d_is_obsolete == 't' ? 1 : $d_is_obsolete;
$d_is_obsolete = $d_is_obsolete == 'f' ? 0 : $d_is_obsolete;
// on AHAH callbacks we want to keep a list of all the properties that have been removed
// we'll store this info in a hidden field and retrieve it here
$d_removed = $form_state['values']['removed'];
// get the number of new fields that have been aded via AHAH callbacks
$num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
// initialze default properties array. This is where we store the property defaults
$d_properties = array();
// get the list of publication types. In the Tripal publication
// ontologies these are all grouped under the term 'Publication Type'
// we want the default to be 'Journal Article'
$sql = "
SELECT CVTS.cvterm_id, CVTS.name
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 Type' and
NOT CVTS.is_obsolete = 1
ORDER BY CVTS.name ASC
";
$results = chado_query($sql);
$pub_types = array();
while ($pub_type = db_fetch_object($results)) {
$pub_types[$pub_type->cvterm_id] = $pub_type->name;
// if we don't have a default type then set the default to be 'Journal Article'
if (strcmp($pub_type->name, "Journal Article") == 0 and !$d_type_id) {
$d_type_id = $pub_type->cvterm_id;
}
}
// reset the default to use the stored variable if one exists
$d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
// get publication properties list
$properties_select = array();
$properties_select[] = 'Select a Property';
$properties_list = array();
$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)) {
// the 'Citation' term is special because it serves
// both as a property and as the uniquename for the publiation table
if ($prop->name != "Citation") {
$properties_select[$prop->cvterm_id] = $prop->name;
}
$properties_list[$prop->cvterm_id] = $prop;
}
$form['pub_id'] = array(
'#type' => 'hidden',
'#value' => $pub_id,
);
// a drupal title can only be 255 characters, but the Chado title can be much longer.
// we use the publication title as the drupal title, but we'll need to truncate it.
$form['title'] = array(
'#type' => 'hidden',
'#value' => substr($d_title, 0, 255),
);
$form['pubtitle'] = array(
'#type' => 'textarea',
'#title' => t('Publication Title'),
'#default_value' => $d_title,
'#required' => TRUE,
);
$form['type_id'] = array(
'#type' => 'select',
'#title' => t('Publication Type'),
'#options' => $pub_types,
'#required' => TRUE,
'#default_value' => $d_type_id,
);
$form['pyear'] = array(
'#type' => 'textfield',
'#title' => t('Publication Year'),
'#default_value' => $d_pyear,
'#required' => TRUE,
'#size' => 5,
'#description' => t('Enter the year of publication. Also, if available, please add a <b>Publication Date</b> property to specify the full date of publication.'),
);
$form['uniquename'] = array(
'#type' => 'textarea',
'#title' => t('Citation'),
'#default_value' => $d_uniquename,
'#description' => t('All publications must have a unique citation.
<b>Please enter the full citation for this publication or leave blank and one will be generated
automatically if possible</b>. For PubMed style citations list
the last name of the author followed by initials. Each author should be separated by a comma. Next comes
the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>'),
);
// add in the properties that are actually stored in the pub table fields.
$num_properties = chado_pub_node_form_add_pub_table_props($form, $form_state, $properties_list,
$d_properties, $d_removed, $d_volume, $d_volumetitle, $d_issue, $d_pages, $d_series_name);
// add in the properties from the pubprop table
$num_properties += chado_pub_node_form_add_pubprop_table_props($form, $form_state, $pub_id, $d_properties, $d_removed);
// add in any new properties that have been added by the user through an AHAH callback
$num_new = chado_pub_node_form_add_new_props($form, $form_state, $d_properties, $d_removed);
// add an empty row of field to allow for addition of a new property
chado_pub_node_form_add_new_empty_props($form, $properties_select);
$form['removed'] = array(
'#type' => 'hidden',
'#value' => $d_removed,
);
$form['num_new'] = array(
'#type' => 'hidden',
'#value' => $num_new,
);
$form['num_properties'] = array(
'#type' => 'hidden',
'#value' => $num_properties,
);
$form['is_obsolete'] = array(
'#type' => 'checkbox',
'#title' => t('Is Obsolete? (Check for Yes)'),
'#required' => TRUE,
'#default_value' => $d_is_obsolete,
);
return $form;
}