function chado_analysis_form

2.x tripal_analysis.chado_node.inc chado_analysis_form($node, &$form_state)
3.x tripal_analysis.chado_node.inc chado_analysis_form($node, &$form_state)
1.x tripal_analysis.form.inc chado_analysis_form(&$node, $form_state = NULL)

When editing or creating a new node of type 'chado_analysis' we need a form. This function creates the form that will be used for this.

Related topics

File

tripal_analysis/includes/tripal_analysis.form.inc, line 8

Code

function chado_analysis_form(&$node, $form_state = NULL) {
  tripal_core_ahah_init_form();
  $form = array();

  $analysis = $node->analysis;

  // add in the description column. It is a text field and may not be included
  // if the text is too big.
  $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');

  // get form defaults
  $analysis_id = $node->analysis_id;
  if (!$analysis_id) {
    $analysis_id = $analysis->analysis_id;
  }
  $analysisname = $node->analysisname;
  if (!$analysisname) {
    $analysisname = $analysis->name;
  }
  $program = $node->program;
  if (!$program) {
    $program = $analysis->program;
  }
  $programversion = $node->programversion;
  if (!$programversion) {
    $programversion = $analysis->programversion;
  }
  $algorithm = $node->algorithm;
  if (!$algorithm) {
    $algorithm = $analysis->algorithm;
  }
  $sourcename = $node->sourcename;
  if (!$sourcename) {
    $sourcename = $analysis->sourcename;
  }
  $sourceversion = $node->sourceversion;
  if (!$sourceversion) {
    $sourceversion = $analysis->sourceversion;
  }
  $sourceuri = $node->sourceuri;
  if (!$sourceuri) {
    $sourceuri = $analysis->sourceuri;
  }
  $timeexecuted = $node->timeexecuted;
  if (!$timeexecuted) {
    $timeexecuted = $analysis->timeexecuted;
  }
  $description = $node->description;
  if (!$description) {
    $description = $analysis->description;
  }

  // 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();


  $form['title'] = array(
    '#type' => 'hidden',
    '#default_value' => $node->title,
  );
  $form['analysis_id'] = array(
    '#type' => 'hidden',
    '#default_value' => $analysis_id,
  );
  $form['analysisname'] = array(
    '#type' => 'textfield',
    '#title' => t('Analysis Name'),
    '#required' => TRUE,
    '#default_value' => $analysisname,
    '#description' => t("This should be a brief name that
         describes the analysis succintly. This name will helps the user find analyses."),
  );
  $form['program'] = array(
    '#type' => 'textfield',
    '#title' => t('Program'),
    '#required' => TRUE,
    '#default_value' => $program,
    '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
  );
  $form['programversion'] = array(
    '#type' => 'textfield',
    '#title' => t('Program Version'),
    '#required' => TRUE,
    '#default_value' => $programversion,
    '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
  );
  $form['algorithm'] = array(
    '#type' => 'textfield',
    '#title' => t('Algorithm'),
    '#required' => FALSE,
    '#default_value' => $algorithm,
    '#description' => t("Algorithm name, e.g. blast."),
  );
  $form['sourcename'] = array(
    '#type' => 'textfield',
    '#title' => t('Source Name'),
    '#required' => TRUE,
    '#default_value' => $sourcename,
    '#description' => t('The name of the source data.  This could be a file name, data set name or a
           small description for how the data was collected.  For long descriptions use the description field below'),

  );
  $form['sourceversion'] = array(
    '#type' => 'textfield',
    '#title' => t('Source Version'),
    '#required' => FALSE,
    '#default_value' => $sourceversion,
    '#description' => t('If the source dataset has a version, include it here'),
  );
  $form['sourceuri'] = array(
    '#type' => 'textfield',
    '#title' => t('Source URI'),
    '#required' => FALSE,
    '#default_value' => $sourceuri,
    '#description' => t("This is a permanent URL or URI for the source of the analysis.
         Someone could recreate the analysis directly by going to this URI and
         fetching the source data (e.g. the blast database, or the training model)."),
  );
  // Get time saved in chado
  $default_time = $timeexecuted;
  $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  // If the time is not set, use current time
  if (!$default_time) {
    $default_time = time();
    $year = format_date($default_time, 'custom', 'Y');
    $month = format_date($default_time, 'custom', 'n');
    $day = format_date($default_time, 'custom', 'j');
  }
  $form['timeexecuted'] = array(
    '#type' => 'date',
    '#title' => t('Time Executed'),
    '#required' => TRUE,
    '#default_value' => array(
      'year' => $year,
      'month' => $month,
      'day' => $day,
    ),
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#rows' => 15,
    '#title' => t('Materials & Methods (Description and/or Program Settings)'),
    '#required' => FALSE,
    '#default_value' => $description,
    '#description' => t('Please provide all necessary information to allow
         someone to recreate the analysis, including materials and methods
         for collection of the source data and performing the analysis'),
  );

  // get the analysis 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 = 'analysis_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;
  }

  $form['properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('Analysis Details'),
    '#description' => t('You may add additional 
      properties by
      selecting a property type from the dropdown and adding text.  You may add 
      as many properties as desired by clicking the plus button on the right.  To 
      remove a property, click the minus button.  If a property is not available
      you may add it by ' . l('adding the term', 'admin/tripal/tripal_cv/cvterm/add') . '
      to the <b>analysis_property</b> vocabulary within the <b>tripal</b> database'),
  );
  $form['properties']['table'] = array(
    '#type' => 'markup',
    '#value' => '',
    '#prefix' => '<div id="tripal-analysis-edit-properties-table">',
    '#suffix' => '</div>',
  );

  // add in the properties from the analysisprop table
  $num_properties += chado_analysis_node_form_add_analysisprop_table_props($form, $form_state, $analysis_id, $d_properties, $d_removed);

  // add in any new properties that have been added by the user through an AHAH callback
  $num_new = chado_analysis_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_analysis_node_form_add_new_empty_props($form, $properties_select);

  return $form;
}