function chado_featuremap_form
2.x tripal_featuremap.chado_node.inc | chado_featuremap_form($node, &$form_state) |
3.x tripal_featuremap.chado_node.inc | chado_featuremap_form($node, & |
1.x tripal_featuremap.form.inc | chado_featuremap_form($node) |
When editing or creating a new node of type 'chado_featuremap' we need a form. This function creates the form that will be used for this.
Related topics
File
- tripal_featuremap/
includes/ tripal_featuremap.form.inc, line 8
Code
function chado_featuremap_form($node) {
tripal_core_ahah_init_form();
$form = array();
$featuremap = $node->featuremap;
$featuremap_id = $featuremap->featuremap_id;
$d_title = $form_state['values']['title'] ? $form_state['values']['title'] : $featuremap->name;
$d_description = $form_state['values']['description'] ? $form_state['values']['description'] : $featuremap->description;
$d_unittype_id = $form_state['values']['unittype_id'] ? $form_state['values']['unittype_id'] : $featuremap->unittype_id->cvterm_id;
// 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 unit types
$values = array(
'cv_id' => array(
'name' => 'featuremap_units',
)
);
$columns = array('cvterm_id', 'name');
$options = array('order_by' => array('name' => 'ASC'));
$featuremap_units = tripal_core_chado_select('cvterm', $columns, $values, $options);
$units = array();
$units[''] = '';
foreach ($featuremap_units as $unit) {
$units[$unit->cvterm_id] = $unit->name;
}
// get the featuremap properties
$properties_select = array();
$properties_select[] = 'Select a Property';
$properties_list = array();
$sql = "
SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
FROM {cvterm} CVT
INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
WHERE
CV.name = 'featuremap_property' AND
NOT CVT.is_obsolete = 1
ORDER BY CVT.name ASC
";
$prop_types = chado_query($sql);
while ($prop = db_fetch_object($prop_types)) {
$properties_select[$prop->cvterm_id] = $prop->name;
$properties_list[$prop->cvterm_id] = $prop;
}
// keep track of the map id if we have. If we do have one then
// this is an update as opposed to an insert.
$form['featuremap_id'] = array(
'#type' => 'hidden',
'#value' => $featuremap_id,
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Map Name'),
'#description' => t('Please enter a name for this map'),
'#required' => TRUE,
'#default_value' => $d_title,
'#maxlength' => 255
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Map Description'),
'#description' => t('A description of the map.'),
'#required' => TRUE,
'#default_value' => $d_description,
);
$form['unittype_id'] = array(
'#title' => t('Map Units'),
'#type' => t('select'),
'#description' => t("Chose the units for this map"),
'#required' => TRUE,
'#default_value' => $d_unittype_id,
'#options' => $units,
);
// add in the properties from the featuremapprop table
$num_properties += chado_featuremap_node_form_add_featuremapprop_table_props($form, $form_state, $featuremap_id, $d_properties, $d_removed);
// add in any new properties that have been added by the user through an AHAH callback
$num_new = chado_featuremap_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_featuremap_node_form_add_new_empty_props($form, $properties_select);
return $form;
}