Преглед изворни кода

Stock: Removed reference/properties/relationships forms since those are now handled by generic APIs and fixed a small bug in the references tpl

Lacey Sanderson пре 11 година
родитељ
комит
9935d9a380

+ 0 - 439
tripal_stock/includes/tripal_stock-db_references.inc

@@ -1,439 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- * Display the ADD Database References to Stock Page
- *
- * This page is displayed after the stock is created as part of a simulated multi-part form
- *
- * @param $node
- *   The stock node to add the database references to
- *
- * @return
- *   HTML formatted output
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ALL_dbreferences_page($node) {
-  $output = '';
-
-  $output .= tripal_stock_add_chado_properties_progress('db_references') . '<br />';
-  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br />';
-  $output .= '<br />';
-  $output .= theme('tripal_stock_references', $node);
-  $output .= '<br /><br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_dbreference_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'db_references', $node->nid);
-  return $output;
-}
-
-
-/**
- * Implements Hook_form(): Handles adding of Database References to Stocks
- *
- * @param $form_state
- *   An array describing the current state of the form
- * @param $node
- *   The stock node to add the database reference to
- *
- * @return
- *   An array describing the form to be rendered
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_dbreference_form($form_state, $node) {
-
-  $stock_id = $node->stock->stock_id;
-
-  $form['db_nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $form['add_dbreference'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Add Database References') . '<span class="form-optional" title="This field is optional">(optional)</span>',
-  );
-
-  $form['add_properties']['db_stock_id'] = array(
-    '#type' => 'value',
-    '#value' => $stock_id,
-    '#required' => TRUE
-
-  );
-
-  $form['add_dbreference']['accession'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Accession Number'),
-  );
-
-  $form['add_dbreference']['db_description'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Description of Database Reference') . '<span class="form-optional" title="This field is optional">+</span>',
-    '#description' => t('Optionally enter a description about the database accession.')
-  );
-
-  $db_options = tripal_db_get_db_options();
-  $db_options[0] = 'Select a Database';
-  ksort($db_options);
-  $form['add_dbreference']['database'] = array(
-    '#type' => 'select',
-    '#title' => t('Database'),
-    '#options' => $db_options,
-  );
-
-  $form['add_dbreference']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add Database Reference')
-  );
-
-  return $form;
-}
-
-/**
- * Implements hook_form_validate(): Validates the input from tripal_stock_add_ONE_dbreference_form()
- *
- * @param $form
- *   An array describing the form that was rendered
- * @param $form_state
- *   An array describing the current state of the form including user input
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_dbreference_form_validate($form, &$form_state) {
-
-  // Only ensure db reference valid if adding
-  if ($form_state['clicked_button']['#value'] == t('Add Database Reference') ) {
-    //Do work of required validators
-    if ($form_state['values']['accession'] == '') {
-      form_set_error('accession', 'Accession field is Required.');
-    }
-
-    // Check database is valid db_id in chado
-    if ( $form_state['values']['database'] > 0) {
-      $sql = "SELECT count(*) as count FROM {db} WHERE db_id = :db_id";
-      $tmp_obj = chado_query($sql, array(':db_id' => $form_state['values']['database']))->fetchObject();
-
-      if ($tmp_obj->count != 1) {
-        form_set_error('database', 'The database you selected is not valid. Please choose another one.');
-      }
-    }
-    else {
-      form_set_error('database', 'Please select a database');
-    }
-
-    // Check Accession is unique for database
-    $sql =  "SELECT count(*) as count FROM {dbxref} WHERE accession = :accession";
-    $tmp_obj = chado_query($sql, array(':accession' => $form_state['values']['accession']))->fetchObject();
-
-    if ($tmp_obj->count > 0) {
-      form_set_error('accession', 'This accession has already been assigned to another stock.');
-    }
-
-  } //end of if adding
-
-}
-
-/**
- * Implements hoook_form_submit(): Actually adds the db reference to the stock
- *
- * @param $form
- *   An array describing the form that was rendered
- * @param $form_state
- *   An array describing the current state of the form including user input
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_dbreference_form_submit($form, &$form_state) {
-
-  // FIX: Sometimes on programatic submission of form (drupal_execute) values in the form state get lost
-  //     however, the post values always seem to be correct
-  if (empty($form_state['values']['db_stock_id'])) {
-  $form_state['values']['db_stock_id'] = $form_state['clicked_button']['#post']['db_stock_id']; }
-
-  // Only Create if valid
-  if ($form_state['values']['database'] > 0) {
-
-
-    // create dbxref
-    $sql = "
-      INSERT INTO {dbxref} (db_id, accession, description) 
-      VALUES (:db_id, :accession, :description)
-    ";
-    chado_query($sql, array(':db_id' => $form_state['values']['database'], 
-      ':accession' => $form_state['values']['accession'], 
-      ':description' => $form_state['values']['db_description']
-    ));
-
-    //create stock_dbxref
-    $dbxref = tripal_db_get_dbxref_by_accession($form_state['values']['accession'], $form_state['values']['database']);
-    if (!empty($dbxref->dbxref_id)) {
-      $sl = "INSERT INTO {stock_dbxref} (stock_id, dbxref_id) VALUES (:stock_id, :dbxref_id)";
-      chado_query($sql, array(':stock_id' => $form_state['values']['db_stock_id'],
-        ':dbxref_id' => $dbxref->dbxref_id));
-
-      drupal_set_message(t('Successfully Added Database Reference'));
-    }
-    else {
-      drupal_set_message(t('Database reference NOT successfully created...'), 'error');
-    } //end of if dbxref was created successfully
-  } //end of if valid db reference
-
-}
-
-/**
- * Display the EDIT Database References to Stock Page
- *
- * This page is displayed as a tab on each stock details page (by default)
- *
- * @param $node
- *   The stock node to add the database references to
- *
- * @return
- *   HTML formatted output
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_dbreferences_page($node) {
-  $output = '';
-
-  $output .= drupal_get_form('tripal_stock_edit_ALL_db_references_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_dbreference_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
-
-  return $output;
-}
-
-/**
- * Implements Hook_form(): Handles adding of Database References to Stocks
- *
- * Specifically this adds dbxrefs to a current stock using the stock_dbxref table
- *
- * @param $form_state
- *   An array describing the current state of the form
- * @param $node
- *   The stock node whose database references should be edited
- *
- * @return
- *   An array describing the form to be rendered
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_db_references_form($form_state, $node) {
-  $form = array();
-
-  // Add database references to the node
-  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_dbxref');
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $i=0;
-  if (!$node->stock->stock_dbxref) {
-    $node->stock->stock_dbxref = array();
-  }
-  elseif (!is_array($node->stock->stock_dbxref)) {
-    $node->stock->stock_dbxref = array($node->stock->stock_dbxref);
-  }
-  if (sizeof($node->stock->stock_dbxref) != 0) {
-  foreach ($node->stock->stock_dbxref as $ref) {
-    $i++;
-    $form["num-$i"] = array(
-      '#type' => 'item',
-      '#value' => $i . '.'
-    );
-
-    $form["accession-$i"] = array(
-      '#type' => 'textfield',
-      //'#title' => t('Accession'),
-      '#size' => 30,
-      '#required' => TRUE,
-      '#default_value' => $ref->dbxref_id->accession
-    );
-
-    $db_options = tripal_db_get_db_options();
-    $db_options[0] = 'Select a Database';
-    ksort($db_options);
-    $form["database-$i"] = array(
-      '#type' => 'select',
-      //'#title' => t('Database'),
-      '#options' => $db_options,
-      '#default_value' => $ref->dbxref_id->db_id->db_id
-    );
-
-
-    $form["id-$i"] = array(
-      '#type' => 'hidden',
-      '#value' => $ref->dbxref_id->dbxref_id
-    );
-
-    $form["submit-$i"] = array(
-      '#type' => 'submit',
-      '#value' => t("Delete #$i")
-    );
-
-  }} //end of foreach db ref
-
-  $form['num_db_references'] = array(
-    '#type' => 'hidden',
-    '#value' => $i
-  );
-
-  $form["submit-edits"] = array(
-    '#type' => 'submit',
-    '#value' => t('Update DB References')
-  );
-
-  return $form;
-}
-
-/**
- * Implements hook_form_submit(): Actually edits the database references
- *
- * @param $form
- *   An array representing the form
- * @param $form_state
- *   An array representing the current state of the form including user input
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_db_references_form_submit($form, &$form_state) {
-
-  if ($form_state['clicked_button']['#value'] == t('Update DB References') ) {
-
-       //Update all
-    for ($i=1; $i<=$form_state['values']['num_db_references']; $i++) {
-      tripal_stock_update_db_reference(
-        $form_state['values']["id-$i"],
-        $form_state['values']["database-$i"],
-        $form_state['values']["accession-$i"]
-      );
-    }
-      drupal_set_message(t("Updated all Database References"));
-      drupal_goto('node/' . $form_state['values']['nid']);
-
-  }
-  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
-
-    $i = $matches[1];
-    tripal_stock_delete_db_reference($form_state['values']["id-$i"]);
-    drupal_set_message(t("Deleted Database Reference"));
-
-  }
-  else {
-    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
-
-  }
-}
-
-/**
- * Updates a Database Reference
- *
- * @todo Make this function more generic ie: update all parts of the dbxref and db
- *
- * @param $dbxref_id
- *   The unique chado identifier of the database reference to be updated
- * @param $database_id
- *   The new database ID
- * @param $accession
- *   The new accession
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_update_db_reference($dbxref_id, $database_id, $accession) {
-  $sql = "UPDATE {dbxref} SET db_id = :db_id, accession = :accession WHERE dbxref_id = :dbxref_id";
-  chado_query($sql, array(':db_id' => $database_id, ':accession' => $accession, ':dbxref_id' =>  $dbxref_id));
-}
-
-/**
- * Deletes a given database reference
- *
- * @param $dbxref_id
- *   The chado unique idenfier for the database reference to be deleted
- *
- * @return
- *   TRUE on success; FALSE otherwise
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_delete_db_reference($dbxref_id) {
-  chado_query("DELETE FROM {dbxref} WHERE dbxref_id = :dbxref_id", array(':dbxref_id' => $dbxref_id));
-  chado_query("DELETE FROM {stock_dbxref} WHERE dbxref_id = :dbxref_id", array(':dbxref_id' => $dbxref_id));
-}
-
-/**
- * Themes the Edit All Database References for a stock form
- *
- * @param $form
- *   An array describing the form to be themed
- *
- * @return
- *   An HTML rendering of the form
- *
- * @ingroup tripal_stock
- */
-function theme_tripal_stock_edit_ALL_db_references_form($form) {
-  $output = '';
-
-  $output .= '<br /><fieldset>';
-  $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
-  $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
-         .'is a unique identifier for this stock in the specified database.</p>';
-  $output .= '<table>';
-  $output .= '<tr><th>#</th><th>Database</th><th>Accession</th><th></th></tr>';
-
-  for ($i=1; $i<=$form['num_db_references']['#value']; $i++) {
-    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
-             . drupal_render($form["database-$i"]) . '</td><td>'
-         . drupal_render($form["accession-$i"]) . '</td><td>'
-         . drupal_render($form["submit-$i"]) . '</td></tr>';
-  }
-
-  $output .= '</table><br />';
-  $output .= drupal_render($form);
-  $output .= '</fieldset>';
-
-  return $output;
-}
-
-
-/**
- *  List all database references for a given node
- *
- * @todo Make this function a theme function
- *
- * @param $db_references
- *   An array of database references to be listed
- *
- * @return
- *   HTML representation of the list
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_list_dbreferences_for_node($db_references) {
-
-  if (!empty($db_references) ) {
-    $output = '<table>';
-    $output .= '<tr><th>Database</th><th>Accession</th></tr>';
-
-    foreach ($db_references as $db) {
-        $output .= '<tr><td>' . $db->db_name . '</td><td>' . $db->accession . '</td></tr>';
-    } // end of foreach db reference
-
-    $output .= '</table>';
-
-  }
-  else {
-    $output = 'No Database References Added to the Current Stock';
-  }
-
-  return $output;
-}

+ 0 - 405
tripal_stock/includes/tripal_stock-properties.inc

@@ -1,405 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ALL_property_page($node) {
-  $output = '';
-
-  $output .= tripal_stock_add_chado_properties_progress('properties') . '<br />';
-  $output .= '<b>All Properties should strictly pertain to THE CURRENT Individual</b><br />';
-  $output .= '<br />';
-  $output .= theme('tripal_stock_properties', $node);
-  $output .= '<br /><br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_property_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'properties', $node->nid);
-  return $output;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_property_form($form_state, $node) {
-  $form = array();
-  $stock_id = $node->stock->stock_id;
-
-  $form['add_properties'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Add Property') . '<span class="form-optional" title="This field is optional"> (optional)</span>',
-  );
-
-  $form['prop_nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $tmp_obj = tripal_cv_get_cvterm_by_name('synonym', variable_get('chado_stock_prop_types_cv', 'null'));
-  $synonym_id = $tmp_obj->cvterm_id;
-
-  $prop_type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
-  $prop_type_options[0] = 'Select a Type';
-  ksort($prop_type_options);
-  $form['add_properties']['prop_type_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Type of Property'),
-    '#options' => $prop_type_options,
-  );
-
-  $form['add_properties']['prop_value'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Value') . '<span class="form-optional" title="This field is optional">+</span>',
-  );
-
-  $form['add_properties']['preferred_synonym'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Preferred Synonym (only applicable if type is synonym)'),
-  );
-
-  $form['add_properties']['prop_stock_id'] = array(
-    '#type' => 'value',
-    '#value' => $stock_id,
-    '#required' => TRUE
-  );
-
-  $form['add_properties']['submit-add'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add Property')
-  );
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_property_form_validate($form, &$form_state) {
-
-  // Only Require if Adding Property
-  if ($form_state['clicked_button']['#value'] == t('Add Property') ) {
-
-    // Check that there is a stock
-    if ( $form_state['values']['prop_stock_id'] <= 0 ) {
-      form_set_error('prop_stock_id', 'There is no associated stock.');
-    }
-
-    // Check that Selected a type
-    if ( $form_state['values']['prop_type_id'] == 0) {
-      form_set_error('prop_type_id', 'Please select a type of property.');
-    }
-    else {
-      // Check that type is in chado
-      $num_rows = chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['prop_type_id'])->fetchObject();
-      if ( $num_rows->count != 1) {
-        form_set_error('prop_type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)");
-      } // end of if more or less than 1 row
-    } // if no prop type
-
-    // only check preferred synonym if type is synonym
-    if ($form_state['values']['preferred_synonym'] == 1) {
-      $tmp_obj = tripal_cv_get_cvterm_by_name('synonym', variable_get('chado_stock_prop_types_cv', 'null'));
-      if ($form_state['values']['prop_type_id'] != $tmp_obj->cvterm_id) {
-        form_set_error('preferred_synonym', 'Preferred Synonym Checkbox Only Applicable if Type of Property is Synonym');
-      }
-    }
-
-  } // if add Property
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_property_form_submit($form, &$form_state) {
-
-  // if there is a property add it (only won't be a property if clicked next step w/ no property)
-  if ($form_state['values']['prop_type_id'] != 0) {
-    //determine the rank for this property
-    $max_rank = get_max_chado_rank('stockprop',
-                                  array('stock_id' => array('type' => 'INT', 'value' => $form_state['values']['prop_stock_id']),
-                                        'type_id' => array('type' => 'INT', 'value' => $form_state['values']['prop_type_id']) ));
-    if ($max_rank == -1) {
-    $rank = 0;
-    }
-    else { $rank = $max_rank+1; }
-    
-    $sql = "
-      INSERT INTO {stockprop} (stock_id, type_id, value, rank) 
-      VALUES (:stock_id, :type_id, :value, :rank)
-    ";
-    chado_query($sql, array(':stock_id' => $form_state['values']['prop_stock_id'],
-      ':type_id' => $form_state['values']['prop_type_id'],
-      ':value' => $form_state['values']['prop_value'],
-      ':rank' => $rank));
-
-    drupal_set_message(t("Successfully Added Property"));
-
-    // Set Preferred Synonym
-    if ($form_state['values']['preferred_synonym'] == 1) {
-
-      //use update node form so that both title and name get set
-      $node = node_load($form_state['values']['prop_nid']);
-      $node->title = $form_state['values']['prop_value'];
-      $node_form_state = array(
-        'values' => array(
-          'title' => $form_state['values']['prop_value'],
-          'op' => 'Save'
-        )
-      );
-      module_load_include('inc', 'node', 'node.pages');
-      drupal_form_submit('chado_stock_node_form', $node_form_state, $node);
-
-    }
-
-  } //end of if property to add
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_properties_page($node) {
-  $output = '';
-
-  $output .= drupal_get_form('tripal_stock_edit_ALL_properties_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_property_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
-
-  return $output;
-}
-
-/**
- * Implements Hook_form(): Handles adding of Properties & Synonyms to Stocks
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_properties_form($form_state, $node) {
-  $form = array();
-
-  // Add properties and synonyms
-  $node = tripal_core_expand_chado_vars($node, 'table', 'stockprop');
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $i=0;
-  if (!$node->stock->stockprop) {
-    $node->stock->stockprop = array();
-  }
-  elseif (!is_array($node->stock->stockprop)) {
-    $node->stock->stockprop = array($node->stock->stockprop);
-  }
-  if (sizeof($node->stock->stockprop) != 0) {
-  foreach ($node->stock->stockprop as $property) {
-    $i++;
-    $form["num-$i"] = array(
-      '#type' => 'item',
-      '#value' => $i . '.'
-    );
-
-    $form["id-$i"] = array(
-      '#type' => 'hidden',
-      '#value' => $property->stockprop_id
-    );
-
-    $prop_type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
-    ksort($prop_type_options);
-    $form["type-$i"] = array(
-      '#type' => 'select',
-      //'#title' => t('Type of Property'),
-      '#options' => $prop_type_options,
-      '#default_value' => $property->type_id->cvterm_id
-    );
-
-    $form["value-$i"] = array(
-      '#type' => 'textfield',
-      //'#title' => t('Value'),
-      '#default_value' => $property->value
-    );
-
-    $form["submit-$i"] = array(
-      '#type' => 'submit',
-      '#value' => t("Delete #$i")
-    );
-
-  }} //end of foreach property
-
-  $form['num_properties'] = array(
-    '#type' => 'hidden',
-    '#value' => $i
-  );
-
-  $form["submit-edits"] = array(
-    '#type' => 'submit',
-    '#value' => t('Update Properties')
-  );
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_properties_form_submit($form, &$form_state) {
-
-  if ($form_state['clicked_button']['#value'] == t('Update Properties') ) {
-    //Update all
-    for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
-      tripal_stock_update_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"], $form_state['values']["preferred-$i"], $form_state['values']["nid"]);
-    }
-    drupal_set_message(t("Updated all Properties"));
-    drupal_goto('node/' . $form_state['values']['nid']);
-  }
-  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
-    $i = $matches[1];
-    tripal_stock_delete_property($form_state['values']["id-$i"], $form_state['values']["type-$i"], $form_state['values']["value-$i"]);
-    drupal_set_message(t("Deleted Property"));
-  }
-  else {
-    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
-  }
-
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_update_property($stockprop_id, $cvterm_id, $value, $preferred, $nid) {
-
-  $old_obj = chado_query("SELECT * FROM {stockprop} WHERE stockprop_id=%d", $stockprop_id)->fetchObject();
-
-  // if they changed the type need to check rank
-  //   (if there is another property of the same type then rank needs to be increased to prevent collisions)
-  if ($cvterm_id == $old_obj->type_id) {
-    $sql = "
-      UPDATE {stockprop} SET type_id = :type_id, value = :value
-      WHERE stockprop_id = :stockprop_id
-    ";
-    chado_query($sql, array(':type_id' => $cvterm_id,
-      ':value' => $value, ':stockprop_id' => $stockprop_id));
-  }
-  else {
-      //determine the rank for this property
-    $max_rank = get_max_chado_rank('stockprop', 
-      array('stock_id' => array('type' => 'INT', 'value' => $old_obj->stock_id),
-      'type_id' => array('type' => 'INT', 'value' => $cvterm_id))
-    );
-    if ($max_rank == -1) {
-      $rank = 0;
-    }
-    else { $rank = $max_rank+1; }
-      $sql = "
-        UPDATE {stockprop} SET type_id = :type_id, value = :value, rank = :rank 
-        WHERE stockprop_id = :stockprop_id
-      ";
-      chado_query($sql, array(':type_id' => $cvterm_id, ':value' => $value,
-        ':rank' => $rank, ':stockprop_id' => $stockprop_id));
-  }
-
-  // Set Preferred Synonym
-  //use update node form so that both title and name get set
-  if ($preferred) {
-    $node = node_load($nid);
-    $node->title = $value;
-    $node_form_state = array(
-      'values' => array(
-        'title' => $value,
-        'op' => 'Save'
-      )
-    );
-    module_load_include('inc', 'node', 'node.pages');
-    drupal_form_submit('chado_stock_node_form', $node_form_state, $node);
-  }
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_delete_property($stockprop_id) {
-  chado_query("DELETE FROM {stockprop} WHERE stockprop_id = :stockprop_id", array(':stockprop_id' => $stockprop_id));
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function theme_tripal_stock_edit_ALL_properties_form($form) {
-  $output = '';
-
-  $output .= '<br /><fieldset>';
-  $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
-  $output .= '<p>Below is a list of already existing properties for this stock, one property per line. The type refers to the type of ' .
-             'property and the value is the value for that property. For example, if this stock has a seed coat colour of green then ' .
-             'the property type=sead coat colour and the value=green. When the type of property is synonym, there is an extra checkbox ' .
-             'allowing you to specify which is the <b>Preferred Synonym</b>. This will change the current name of the stock.</p>';
-  $output .= '<table>';
-  $output .= '<tr><th>#</th><th>Type</th><th>Value</th><th></th></tr>';
-
-  for ($i=1; $i<=$form['num_properties']['#value']; $i++) {
-    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>' . drupal_render($form["type-$i"]) . '</td><td>' . drupal_render($form["value-$i"]) . drupal_render($form["preferred-$i"]) . '</td><td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
-  }
-
-  $output .= '</table><br />';
-  $output .= drupal_render($form);
-  $output .= '</fieldset>';
-
-  return $output;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_list_properties_for_node($properties, $synonyms) {
-
-  if (!empty($properties) OR !empty($synonyms) ) {
-    $output = '<table>';
-    $output .= '<tr><th>Type</th><th>Value</th></tr>';
-
-    if (!empty($synonyms) ) {
-      foreach ($synonyms as $s) {
-        $output .= '<tr><td>synonym</td><td>' . $s . '</td></tr>';
-      }
-    }
-
-    if (!empty($properties) ) {
-      foreach ($properties as $p) {
-        $output .= '<tr><td>' . $p->type . '</td><td>' . $p->value . '</td></tr>';
-      } // end of foreach property
-    }
-
-    $output .= '</table>';
-
-  }
-  else {
-    $output = 'No Properties Added to the Current Stock';
-  }
-
-  return $output;
-}

+ 0 - 533
tripal_stock/includes/tripal_stock-relationships.inc

@@ -1,533 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ALL_relationships_page($node) {
-  $output = '';
-
-  $output .= tripal_stock_add_chado_properties_progress('relationships') . '<br />';
-  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->stock->uniquename . ')</b><br />';
-  $output .= '<br />';
-  $output .= theme('tripal_stock_relationships', $node);
-  $output .= '<br /><br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_chado_properties_navigate', 'relationships', $node->nid);
-  return $output;
-}
-
-/**
- * Implements Hook_form(): Handles adding of Relationships to Stocks
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_relationship_form($form_state, $node) {
-
-  $stock_id = $node->stock->stock_id;
-  $organism_id = $node->stock->organism_id->organism_id;
-  $_SESSION['organism'] = $organism_id; //needed for autocomplete enter stock to work
-
-  $form['rel_nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $form['add_relationships'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Add Relationships') . '<span class="form-optional" title="This field is optional">(optional)</span>',
-  );
-
-  $form['add_relationships']['description'] = array(
-    '#type' => 'item',
-    '#value' => t('Relationships are specified as follows: (Subject) (Type of Relationship) (Object). For example, Fred is_the_paternal_parent_of Matty, where Fred & Matty are both stocks.')
-  );
-
-  $form['add_relationships']['subject_id'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Subject'),
-    '#description' => 'The Uniquename, Name, Database Reference or Synonym of a Stock can be used here',
-  );
-
-  $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
-  $type_options[0] = 'Select a Type';
-  ksort($type_options);
-  $form['add_relationships']['type_id'] = array(
-    '#type' => 'select',
-    '#title' => t('Type of Relationship'),
-    '#options' => $type_options
-
-  );
-
-  $form['add_relationships']['object_id'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Object'),
-    '#description' => 'The Uniquename, Name, Database Reference or Synonym of a Stock can be used here',
-  );
-
-  $form['add_relationships']['r_description'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Notes on the relationship') . '<span class="form-optional" title="This field is optional">+</span>',
-    '#description' => t('Should not include Genotypes and Phenotypes'),
-  );
-
-  $form['add_relationships']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add a Relationship')
-  );
-
-  $form['add_relationships']['r_stock_id'] = array(
-    '#type' => 'value',
-    '#value' => $stock_id,
-    '#required' => TRUE
-
-  );
-
-  $form['add_relationships']['r_stock_uniquename'] = array(
-    '#type' => 'value',
-    '#value' => $node->stock->uniquename,
-    '#required' => TRUE
-  );
-
-  return $form;
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_relationship_form_validate($form, &$form_state) {
-
-  //Require Validation if adding
-  if ($form_state['clicked_button']['#value'] == t('Add a Relationship') ) {
-    // check valid stock selected for subject
-    $subject_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']['subject_id'], $_SESSION['organism']);
-    if (sizeof($subject_results) > 1) {
-      $links= array();
-      for ($i=0; $i<sizeof($subject_results); $i++) {
-      $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
-      $message = "Too many stocks match '" . $form_state['values']['subject_id'] . "'! "
-                  . " Please refine your input to match ONLY ONE stock. <br />"
-     . "To aid in this process, here are the stocks that match your initial input: "
-     . join(', ', $links);
-      form_set_error('subject_id', $message);
-    }
-    elseif (sizeof($subject_results) < 1) {
-      form_set_error('subject_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
-    }
-    elseif (sizeof($subject_results) == 1) {
-      $form_state['values']['subject_id'] = $subject_results[0]->stock->stock_id;
-    }
-
-    // check valid stock selected for object
-    $object_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']['object_id'], $_SESSION['organism']);
-    if (sizeof($object_results) > 1) {
-      $links= array();
-      for ($i=0; $i<sizeof($object_results); $i++) {
-      $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
-      $message = t("Too many stocks match '%object'!  Please refine your input to match
-        ONLY ONE stock. <br /> To aid in this process, here are the stocks that match your
-        initial input: %stocks.",
-        array('%object' => $form_state['values']['object_id'],
-          '%stocks' => join(', ', $links)
-        )
-      );
-      form_set_error('object_id', $message);
-    }
-    elseif (sizeof($object_results) < 1) {
-      form_set_error('object_id', t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
-    }
-    elseif (sizeof($object_results) == 1) {
-      $form_state['values']['object_id'] = $object_results[0]->stock->stock_id;
-    }
-
-    // check valid type selected
-    if ($form_state['values']['type_id'] == 0) {
-      form_set_error('type_id', 'Please select a type of relationship.');
-    }
-    else {
-      $sql = "SELECT count(*) as count FROM {cvterm} WHERE cvterm_id = :cvterm_id";
-      $tmp_obj = chado_query($sql, array(':cvterm_id' => $form_state['values']['type_id']))->fetchObject();
-
-      if ($tmp_obj->count != 1) {
-        form_set_error('type_id', 'The type you selected is not valid. Please choose another one.');
-      }
-    }
-
-    // check either subject or object is the current stock
-    if ( $subject_results[0]->nid != $form_state['values']['rel_nid'] ) {
-      if ( $object_results[0]->nid != $form_state['values']['rel_nid'] ) {
-        form_set_error('subject_id', 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
-      }
-    }
-  } //end of require validation if adding relationship
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_ONE_relationship_form_submit($form, &$form_state) {
-
-  if ($form_state['values']['subject_id'] > 0) {
-    $sql = "
-      INSERT INTO {stock_relationship} (subject_id, type_id, object_id, value) 
-      VALUES (:subject_id, :type_id, :object_id, :value)
-    ";
-    chado_query($sql, array(':subject_id' => $form_state['values']['subject_id'],
-      ':type_id' => $form_state['values']['type_id'],
-      ':object_id' => $form_state['values']['object_id'],
-      ':value' => $form_state['values']['r_description']));
-
-    drupal_set_message(t('Successfully Added Relationship.'));
-  } //end of insert relationship
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_relationships_page($node) {
-  $output = '';
-
-  $output .= drupal_get_form('tripal_stock_edit_ALL_relationships_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_add_ONE_relationship_form', $node);
-  $output .= '<br />';
-  $output .= drupal_get_form('tripal_stock_back_to_stock_button', $node->nid);
-
-  return $output;
-}
-
-/**
- * Implements Hook_form()
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_relationships_form($form_state, $node) {
-  $form = array();
-
-  // All Stock Relationships
-  $node = tripal_core_expand_chado_vars($node, 'table', 'stock_relationship');
-
-  // compile all relationships into one variable
-  $relationships = array();
-  if (is_array($node->stock->stock_relationship->subject_id)) {
-    foreach ($node->stock->stock_relationship->subject_id as $r) {
-      $relationships[$r->stock_relationship_id] = $r;
-    }
-  }
-  elseif (is_object($node->stock->stock_relationship->subject_id)) {
-    $relationships[$node->stock->stock_relationship->subject_id->stock_relationship_id] = $node->stock->stock_relationship->subject_id;
-  }
-
-  if (is_array($node->stock->stock_relationship->object_id)) {
-    foreach ($node->stock->stock_relationship->object_id as $r) {
-      $relationships[$r->stock_relationship_id] = $r;
-    }
-  }
-  elseif (is_object($node->stock->stock_relationship->object_id)) {
-    $relationships[$node->stock->stock_relationship->object_id->stock_relationship_id] = $node->stock->stock_relationship->object_id;
-  }
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid
-  );
-
-  $form['r_stock_uniquename'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->stock->uniquename
-  );
-
-  $i=0;
-  if (sizeof($relationships) != 0) {
-  foreach ($relationships as $r) {
-
-    $i++;
-    $form["num-$i"] = array(
-      '#type' => 'item',
-      '#value' => $i . '.'
-    );
-
-    $form["id-$i"] = array(
-      '#type' => 'hidden',
-      '#value' => $r->stock_relationship_id
-    );
-
-    //Enter relationship specific fields
-    if ( $node->stock->stock_id != $r->subject_id->stock_id ) {
-      $default = $r->subject_id->uniquename;
-      $description = l($r->subject_id->name, 'node/' . $r->subject_id->nid);
-    }
-    else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
-    $form["subject_id-$i"] = array(
-      '#type' => 'textfield',
-      //'#title' => t('Subject'),
-      '#required'   => TRUE,
-      '#size' => 30,
-      '#default_value' => $default,
-      '#description' => t('%description', array('%description' => $description)),
-    );
-
-    $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
-    ksort($type_options);
-    $form["type_id-$i"] = array(
-      '#type' => 'select',
-      //'#title' => t('Type of Relationship'),
-      '#options' => $type_options,
-      '#required' => TRUE,
-      '#default_value' => $r->type_id->cvterm_id
-    );
-
-    if ( $node->stock->stock_id != $r->object_id->stock_id ) {
-      $default = $r->object_id->uniquename;
-      $description = l($r->object_id->name, 'node/' . $r->object_id->nid);
-    }
-    else { $default = $node->stock->uniquename; $description = 'Current Stock'; }
-    $form["object_id-$i"] = array(
-      '#type' => 'textfield',
-      //'#title' => t('Object'),
-      '#required'   => TRUE,
-      '#size' => 30,
-      '#default_value' => $default,
-      '#description' => $description
-    );
-
-    $form["submit-$i"] = array(
-      '#type' => 'submit',
-      '#value' => t("Delete #$i")
-    );
-
-  }} //end of foreach relationship
-
-  $form['num_relationships'] = array(
-    '#type' => 'hidden',
-    '#value' => $i
-  );
-
-  $form["submit-edits"] = array(
-    '#type' => 'submit',
-    '#value' => t('Update Relationships')
-  );
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_relationships_form_validate($form, &$form_state) {
-
-  // Only Require if Updating Relationships
-  if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
-
-    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
-
-      // check valid stock selected for subject
-      $subject_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']["subject_id-$i"], $_SESSION['organism']);
-      if (sizeof($subject_results) > 1) {
-        $links= array();
-        for ($j=0; $j<sizeof($subject_results); $j++) {
-        $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
-        $message = t("Too many stocks match '%subject'!  Please refine your input to match
-          ONLY ONE stock. <br /> To aid in this process, here are the stocks that match
-          your initial input: %stocks",
-          array('%subject' => $form_state['values']["subject_id-$i"],
-          '%stocks' => join(', ', $links)
-          )
-        );
-        form_set_error("subject_id-$i", $message);
-      }
-      elseif (sizeof($subject_results) < 1) {
-        form_set_error("subject_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
-      }
-      elseif (sizeof($subject_results) == 1) {
-        $form_state['values']["subject_id-$i"] = $subject_results[0]->stock->stock_id;
-      }
-
-      // check valid stock selected for object
-      $object_results = tripal_stock_get_stock_by_name_identifier( $form_state['values']["object_id-$i"], $_SESSION['organism']);
-      if (sizeof($object_results) > 1) {
-        $links= array();
-        for ($j=0; $j<sizeof($object_results); $j++) {
-        $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
-        $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
-                 . "Please refine your input to match ONLY ONE stock. <br />"
-                 . "To aid in this process, here are the stocks that match your initial input: "
-                 . join(', ', $links);
-        form_set_error("object_id-$i", $message);
-      }
-      elseif (sizeof($object_results) < 1) {
-        form_set_error("object_id-$i", t("There are no stocks matching your input. Please check your input for typos and/or lookup the stock <a href='!url'>here</a>", array('!url' => url('stocks'))));
-      }
-      elseif (sizeof($object_results) == 1) {
-        $form_state['values']["object_id-$i"] = $object_results[0]->stock->stock_id;
-      }
-
-      // check valid type selected
-      if ($form_state['values']["type_id-$i"] == 0) {
-        form_set_error('type_id', 'Please select a type of relationship.');
-      }
-      else {
-        $sql = "SELECT count(*) as count FROM {cvterm} WHERE cvterm_id= :cvterm_id";
-        $tmp_obj = chado_query($sql, array(':cvterm_id' => $form_state['values']["type_id-$i"]))->fetchObject();
-
-        if ($tmp_obj->count != 1) {
-          form_set_error("type_id-$i", 'The type you selected is not valid. Please choose another one.');
-        }
-      }
-
-      // check either subject or object is the current stock
-      if ( $subject_results[0]->nid != $form_state['values']['nid'] ) {
-        if ( $object_results[0]->nid != $form_state['values']['nid'] ) {
-          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
-        }
-      }
-
-    } // end of for each relationship
-  } //end of if updating relationships
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_edit_ALL_relationships_form_submit($form, &$form_state) {
-
-  if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
-    //Update all
-    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {
-
-      //process stock textfields
-      tripal_stock_update_relationship(
-        $form_state['values']["id-$i"],
-        $form_state['values']["subject_id-$i"],
-        $form_state['values']["type_id-$i"],
-        $form_state['values']["object_id-$i"]
-      );
-    }
-    drupal_set_message(t("Updated all Relationships"));
-    drupal_goto('node/' . $form_state['values']['nid']);
-
-  }
-  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {
-
-    $i = $matches[1];
-    tripal_stock_delete_relationship($form_state['values']["id-$i"]);
-    drupal_set_message(t("Deleted Relationship"));
-
-  }
-  elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
-    drupal_goto('node/' . $form_state['values']['nid']);
-  }
-  else {
-    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
-  }
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_update_relationship($stock_relationship_id, $subject_id, $cvterm_id, $object_id) {
-
-  $sql = "
-    UPDATE {stock_relationship} SET subject_id = :subject_id, type_id = :type_id, object_id = :object_id 
-    WHERE stock_relationship_id = :stock_relationship_id
-  ";
-  chado_query($sql, array(':subject_id' => $subject_id, ':type_id' => $cvterm_id,
-    ':object_id' => $object_id, ':stock_relationship_id' => $stock_relationship_id));
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_delete_relationship($stock_relationship_id) {
-  $sql = "DELETE FROM {stock_relationship} WHERE stock_relationship_id = :stock_relationship_id";
-  chado_query($sql, array(':stock_relationship_id' => $stock_relationship_id));
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function theme_tripal_stock_edit_ALL_relationships_form($form) {
-  $output = '';
-
-  $output .= '<br /><fieldset>';
-  $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
-  $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating ' .
-             'the subject and object of the relationship can contain the uniquename, name, database ' .
-             'reference or synonym of a stock of the same organism.</p>';
-  $output .= '<table>';
-  $output .= '<tr><th>#</th><th>Subject</th><th>Type</th><th>Object</th><th></th></tr>';
-
-  for ($i=1; $i<=$form['num_relationships']['#value']; $i++) {
-    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
-             . drupal_render($form["subject_id-$i"]) . '</td><td>'
-         . drupal_render($form["type_id-$i"]) . '</td><td>'
-         . drupal_render($form["object_id-$i"]) . '</td><td>'
-         . drupal_render($form["submit-$i"]) . '</td></tr>';
-  }
-
-  $output .= '</table><br />';
-  $output .= drupal_render($form);
-  $output .= '</fieldset>';
-
-  return $output;
-}
-
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_list_relationships_for_node($stock_name, $subject_relationships, $object_relationships) {
-
-  if (!empty($subject_relationships) OR !empty($object_relationships) ) {
-    $output = '<table>';
-    $output .= '<tr><th>Subject</th><th>Relationship Type</th><th>Object</th></tr>';
-
-    if (!empty($subject_relationships) ) {
-      foreach ($subject_relationships as $s) {
-        $output .= '<tr><td>' . $s->subject_name . '</td><td>' . $s->relationship_type . '</td><td>' . $stock_name . '</td></tr>';
-      }
-    }
-
-    if (!empty($object_relationships) ) {
-      foreach ($object_relationships as $o) {
-        $output .= '<tr><td>' . $stock_name . '</td><td>' . $o->relationship_type . '</td><td>' . $o->object_name . '</td></tr>';
-      } // end of foreach property
-    }
-
-    $output .= '</table>';
-  }
-  else {
-    $output = 'No Relationships Involving the Current Stock';
-  }
-
-  return $output;
-
-}

+ 0 - 228
tripal_stock/includes/tripal_stock-secondary_tables.inc

@@ -1,228 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_back_to_stock_button($form_state, $nid) {
-  $form = array();
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $nid
-  );
-
-  $form["submit-back"] = array(
-    '#type' => 'submit',
-    '#value' => t('Back to Stock')
-  );
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_back_to_stock_button_submit($form, $form_state) {
-  drupal_goto('node/' . $form_state['values']['nid']);
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_chado_properties_progress($current) {
-
-    $value = '<div class="form_progress"><div class="form_progress-text">';
-
-    if ($current == 'main') {
-    $value .= '<span id="form-step-current">Create Basic Stock</span>'; }
-    else { $value .= '<span id="form-step">Create Basic Stock</span>'; }
-
-    $value .= '<span id="form-segway">  >>  </span>';
-
-    if ($current == 'properties') {
-    $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
-    else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }
-
-    $value .= '<span id="form-segway">  >>  </span>';
-
-    if ($current == 'db_references') {
-    $value .= '<span id="form-step-current">Add Database References</span>'; }
-    else { $value .= '<span id="form-step">Add Database References</span>'; }
-
-    $value .= '<span id="form-segway">  >>  </span>';
-
-    if ($current == 'relationships') {
-    $value .= '<span id="form-step-current">Add Relationships</span>'; }
-    else { $value .= '<span id="form-step">Add Relationships</span>'; }
-
-    $value .= '</div></div>';
-
-    return $value;
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_chado_properties_navigate($form_state, $step, $nid) {
-  $form = array();
-
-  $form['current_step'] = array(
-    '#type' => 'hidden',
-    '#value' => $step
-  );
-
-  // Use this field to set all the steps and the path to each form
-  // where each step is of the form name;path and each step is separated by ::
-  $steps =array(
-    'properties' => 'node/%node/properties',
-    'db_references' => 'node/%node/db_references',
-    'relationships' => 'node/%node/relationships'
-  );
-  $steps_value = array();
-  foreach ($steps as $k => $v) {
-  $steps_value[] = $k . ';' . $v; }
-  $form['steps'] = array(
-    '#type' => 'hidden',
-    '#value' => implode('::', $steps_value)
-  );
-
-  $form['first_step'] = array(
-    '#type' => 'hidden',
-    '#value' => 'properties'
-  );
-
-  $form['last_step'] = array(
-    '#type' => 'hidden',
-    '#value' => 'relationships'
-  );
-
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $nid
-  );
-
-  if ($step != $form['first_step']['#value']) {
-    $form['submit-prev'] = array(
-      '#type' => 'submit',
-      '#value' => t('Previous Step')
-    );
-  }
-
-  if ($step != $form['last_step']['#value']) {
-    $form['submit-next'] = array(
-      '#type' => 'submit',
-      '#value' => t('Next Step')
-    );
-  }
-
-  if ($step == $form['last_step']['#value']) {
-    $form['submit-finish'] = array(
-      '#type' => 'submit',
-      '#value' => t('Finish')
-    );
-  }
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {
-
-  $raw_steps = preg_split('/::/', $form_state['values']['steps']);
-
-  $steps = array();
-  $current_index = 'EMPTY';
-  $i=0;
-
-  foreach ($raw_steps as $raw_step) {
-    $step = preg_split('/;/', $raw_step);
-    $steps[$i] = $step;
-
-    if ($step[0] == $form_state['values']['current_step']) {
-      $current_index = $i;
-    }
-
-    $i++;
-  }
-  $num_steps = $i;
-
-  if (strcmp($current_index, 'EMPTY') == 0) {
-    // No Matching Step
-    drupal_set_message(t('Could not determine next step - %currentstep, please contact the administrator', array('%currentstep' => $form_state['values']['current_step'])), 'error');
-  }
-  elseif ($current_index == 0) {
-    $next_goto = $steps[$current_index+1][1];
-  }
-  elseif ($current_index == ($num_steps-1)) {
-    $prev_goto = $steps[$current_index-1][1];
-    $next_goto = 'node/%node';
-  }
-  else {
-    $prev_goto = $steps[$current_index-1][1];
-    $next_goto = $steps[$current_index+1][1];
-  }
-
-  if ($form_state['clicked_button']['#value'] == t('Previous Step') ) {
-    //replace %node
-    $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
-    $_REQUEST['destination'] = $prev_goto;
-  }
-  elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
-    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
-    $_REQUEST['destination'] = $next_goto;
-  }
-  elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
-    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
-    $_REQUEST['destination'] = $next_goto;
-  }
-
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_is_obsolete_form($node, $stock_id) {
-
-  $form['make_obsolete'] = array(
-    '#type' => 'submit',
-    '#value' => t('Mark Stock as Obsolete')
-  );
-
-  $form['make_obsolete_stock_id'] = array(
-    '#type' => 'value',
-    '#value' => $stock_id,
-    '#required' => TRUE
-  );
-
-  return $form;
-}
-
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_is_obsolete_form_submit($form, &$form_state) {
-  $sql = "UPDATE {stock} SET is_obsolete='t' WHERE stock_id= :stock_id";
-  chado_query($sql, array(':stock_id' => $form_state['values']['make_obsolete_stock_id']));
-}
-

+ 1 - 1
tripal_stock/theme/tripal_stock/tripal_stock_references.tpl.php

@@ -49,7 +49,7 @@ if(count($references) > 0){ ?>
 	          else {
 	            print $dbxref->accession;
 	          }
-	          if ($dbxref->is_primary) {
+	          if (property_exists($dbxref,'is_primary')) {
 	            print " <i>(primary cross-reference)</i>";
 	          } ?>
 	        </td>

+ 0 - 59
tripal_stock/tripal_stock.module

@@ -82,65 +82,6 @@ function tripal_stock_menu() {
     'weight' => 10
   );
 
-  // Adding Secondary Properties-----------------
-  $items['node/%cs_node/properties'] = array(
-    'title' => 'Add Properties & Synonyms',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_add_ALL_property_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_stock content'),
-    'type' => MENU_CALLBACK
-  );
-
-  $items['node/%cs_node/db_references'] = array(
-    'title' => 'Add Database References',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_add_ALL_dbreferences_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_stock content'),
-    'type' => MENU_CALLBACK
-  );
-
-  $items['node/%cs_node/relationships'] = array(
-    'title' => 'Add Relationships',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_add_ALL_relationships_page',
-    'page arguments' => array(1),
-    'access arguments' => array('create chado_stock content'),
-    'type' => MENU_CALLBACK
-  );
-
-  //Edit/Deleting Secondary Properties-------------
-  $items['node/%cs_node/edit_properties'] = array(
-    'title' => 'Edit Properties',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_edit_ALL_properties_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_stock content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 8,
-  );
-
-    $items['node/%cs_node/edit_relationships'] = array(
-    'title' => 'Edit Relationships',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_edit_ALL_relationships_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_stock content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 9,
-  );
-
-  $items['node/%cs_node/edit_db_references'] = array(
-    'title' => 'Edit DB References',
-    'description' => 'Settings for Chado Stocks',
-    'page callback' => 'tripal_stock_edit_ALL_dbreferences_page',
-    'page arguments' => array(1),
-    'access arguments' => array('edit chado_stock content'),
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 10,
-  );
-
   // the menu link for addressing any stock (by name, uniquename, synonym)
   $items['stock/%'] = array(
     'page callback' => 'tripal_stock_match_stocks_page',