function chado_pub_node_form_add_pubprop_table_props

1.x pub_form.inc chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_id, &$d_properties, &$d_removed)
1 call to chado_pub_node_form_add_pubprop_table_props()
chado_pub_form in tripal_pub/includes/pub_form.inc

File

tripal_pub/includes/pub_form.inc, line 529

Code

function chado_pub_node_form_add_pubprop_table_props(&$form, $form_state, $pub_id, &$d_properties, &$d_removed) {

  // get the properties for this publication
  $num_properties = 0;

  if (!$pub_id) {
    return $num_properties;
  }

  $sql = "
    SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
    FROM {pubprop} PP
      INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
    WHERE PP.pub_id = %d
    ORDER BY CVT.name, PP.rank
  ";
  $pub_props = chado_query($sql, $pub_id);
  while ($prop = db_fetch_object($pub_props)) {

    $type_id = $prop->cvterm_id;
    $rank = count($d_properties[$type_id]);

    // skip properties that are found in the pub table
    if ($prop->name == "Volume" or $prop->name == "Volume Title" or 
      $prop->name == "Issue" or $prop->name == "Pages" or 
      $prop->name == "Citation" or $prop->name == "Journal Name") {
      continue;
    }

    // skip any properties that the user requested to delete through a previous
    // AHAH callback or through the current AHAH callback
    if ($d_removed["$type_id-$rank"]) {
      continue;
    }
    if ($form_state['post']['remove-' . $type_id . '-' . $rank]) {
      $d_removed["$type_id-$rank"] = 1;
      continue;
    }

    $d_properties[$type_id][$rank]['name'] = $prop->name;
    $d_properties[$type_id][$rank]['id'] = $type_id;
    $d_properties[$type_id][$rank]['value'] = $prop->value;
    $d_properties[$type_id][$rank]['definition'] = $prop->definition;
    $num_properties++;

    // determine how many rows we need in the textarea
    $rows = 1;
    if (preg_match('/Abstract/', $prop->name)) {
      $rows = 10;
    }
    if ($prop->name == 'Authors') {
      $rows = 2;
    }

    $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
      '#type' => 'item',
      '#value' => $prop->name,
    );
    $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
      '#type' => 'textarea',
      '#default_value' => $prop->value,
      '#cols' => 50,
      '#rows' => $rows,
      '#description' => $prop->definition,
    );

    $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
      '#type' => 'image_button',
      '#value' => t('Remove'),
      '#src' => drupal_get_path('theme', 'tripal') . '/images/minus.png',
      '#ahah' => array(
        'path' => "tripal_pub/properties/minus/$type_id/$rank",
        'wrapper' => 'tripal-pub-edit-properties-table',
        'event' => 'click',
        'method' => 'replace',
      ),
      '#attributes' => array('onClick' => 'return false;'),
    );
  }
  return $num_properties;
}