Tripal v1.0 (6.x-1.0)
Stock Module

Functions

 tripal_stock_admin ()
 tripal_stock_admin_validate ($form, &$form_state)
 tripal_stock_sync_stock_set ($organism_id, $job_id)
 get_tripal_stock_admin_form_cleanup_set (&$form)
 tripal_stock_cleanup ($dummy=NULL, $job_id=NULL)
 tripal_stock_add_ALL_dbreferences_page ($node)
 tripal_stock_add_ONE_dbreference_form ($form_state, $node)
 tripal_stock_add_ONE_dbreference_form_validate ($form, &$form_state)
 tripal_stock_add_ONE_dbreference_form_submit ($form, &$form_state)
 tripal_stock_edit_ALL_dbreferences_page ($node)
 tripal_stock_edit_ALL_db_references_form ($form_state, $node)
 tripal_stock_edit_ALL_db_references_form_submit ($form, &$form_state)
 tripal_stock_update_db_reference ($dbxref_id, $database_id, $accession)
 tripal_stock_delete_db_reference ($dbxref_id)
 theme_tripal_stock_edit_ALL_db_references_form ($form)
 tripal_stock_list_dbreferences_for_node ($db_references)
 tripal_stock_add_ALL_property_page ($node)
 tripal_stock_add_ONE_property_form ($form_state, $node)
 tripal_stock_add_ONE_property_form_validate ($form, &$form_state)
 tripal_stock_add_ONE_property_form_submit ($form, &$form_state)
 tripal_stock_edit_ALL_properties_page ($node)
 tripal_stock_edit_ALL_properties_form ($form_state, $node)
 tripal_stock_edit_ALL_properties_form_submit ($form, &$form_state)
 tripal_stock_update_property ($stockprop_id, $cvterm_id, $value, $preferred, $nid)
 tripal_stock_delete_property ($stockprop_id)
 theme_tripal_stock_edit_ALL_properties_form ($form)
 tripal_stock_list_properties_for_node ($properties, $synonyms)
 tripal_stock_add_ALL_relationships_page ($node)
 tripal_stock_add_ONE_relationship_form ($form_state, $node)
 tripal_stock_add_ONE_relationship_form_validate ($form, &$form_state)
 tripal_stock_add_ONE_relationship_form_submit ($form, &$form_state)
 tripal_stock_edit_ALL_relationships_page ($node)
 tripal_stock_edit_ALL_relationships_form ($form_state, $node)
 tripal_stock_edit_ALL_relationships_form_validate ($form, &$form_state)
 tripal_stock_edit_ALL_relationships_form_submit ($form, &$form_state)
 tripal_stock_update_relationship ($stock_relationship_id, $subject_id, $cvterm_id, $object_id)
 tripal_stock_delete_relationship ($stock_relationship_id)
 theme_tripal_stock_edit_ALL_relationships_form ($form)
 tripal_stock_list_relationships_for_node ($stock_name, $subject_relationships, $object_relationships)
 tripal_stock_back_to_stock_button ($form_state, $nid)
 tripal_stock_back_to_stock_button_submit ($form, $form_state)
 tripal_stock_add_chado_properties_progress ($current)
 tripal_stock_add_chado_properties_navigate ($form_state, $step, $nid)
 tripal_stock_add_chado_properties_navigate_submit ($form, $form_state)
 tripal_stock_is_obsolete_form ($node, $stock_id)
 tripal_stock_is_obsolete_form_submit ($form, &$form_state)
 tripal_stock_menu ()
 cs_node_load ($nid)
 tripal_stock_perm ()
 chado_stock_access ($op, $node, $account)
 tripal_stock_views_api ()
 tripal_stock_theme ()
 tripal_stock_node_info ()
 chado_stock_load ($node)
 chado_stock_form ($node, $form_state)
 chado_stock_validate ($node, &$form)
 chado_stock_insert ($node)
 chado_stock_update ($node)
 chado_stock_delete ($node)
 tripal_stock_block ($op= 'list', $delta=0, $edit=array())
 tripal_stock_preprocess_tripal_stock_relationships (&$variables)
 tripal_stock_nodeapi (&$node, $op, $teaser, $page)
 tripal_stock_preprocess_tripal_organism_stocks (&$variables)

Detailed Description

Provides functions for managing chado stocks including creating details pages for each stock

The Tripal Stock Module provides functionality for adding, editing, deleting and accessing chado stocks. The stock module was designed to store information about stock collections in a laboratory. What is called a stock could also be called a strain or an accession. There is a lot in common between a Drosophila stock and a Saccharomyces strain and an Arabidopsis line. They all come from some taxon, have genotypes, physical locations in the lab, some conceivable relationship with a publication, some conceivable relationship with a sequence feature (such as a transgene), and could be described by some ontology term. For more information about the chado Stock Module see the GMOD Wiki Page (http://gmod.org/wiki/Chado_Stock_Module)


Function Documentation

chado_stock_access ( op,
node,
account 
)

Implements hook_access(): Maps permission catagories to actions

Parameters:
$opThe operation current operation: one of create, update, delete
$nodeThe node object the current operation is being performed on
$accountA user object representing the user for whom the operation is to be performed
Returns:
TRUE grants access; FALSE denies it

Definition at line 184 of file tripal_stock.module.

                                                  {
  if ($op == 'create') {
    if (!user_access('create chado_stock content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'update') {
    if (!user_access('edit chado_stock content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'delete') {
    if (!user_access('delete chado_stock content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'view') {
    if (!user_access('access chado_stock content', $account)) {
      return FALSE;
    }
  }
  return NULL;
}
chado_stock_delete ( node)

Implements hook_delete(): Handles deleting of chado_stocks

NOTE: Currently deletes data -no undo or record-keeping functionality

Parameters:
$nodeThe current node including fields with the form element names and submitted values
Returns:
TRUE if the node was successfully deleted from drupal/chado; FALSE otherwise

Definition at line 833 of file tripal_stock.module.

                                   {

  // Set stock in chado: is_obsolete = TRUE
  chado_query(
    "DELETE FROM {stock} WHERE stock_id=%d",
    $node->stock->stock_id
  );

  //remove drupal node and all revisions
  db_query(
    "DELETE FROM {chado_stock} WHERE nid=%d",
    $node->nid
  );
}
chado_stock_form ( node,
form_state 
)

Implements hook_form(): Creates the main Add/Edit/Delete Form for chado stocks

Parts to be added by this form name, uniquename, description, type => select from cvterm with key cvterm_id, organism => select from available with key organism_id main_db_reference => accession, version, description, db_name(select from dropdown)

Parameters:
$nodeAn empty node object on insert OR the current stock node object on update
$form_stateThe current state of the form
Returns:
A description of the form to be rendered by drupal_get_form()

Definition at line 371 of file tripal_stock.module.

                                              {

  // Expand all fields needed
  $fields_needed = array('stock.uniquename', 'stock.name', 'stock.stock_id', 'stock.type_id', 'stock.organism_id', 'stock.description', 'stock.dbxref_id', 'dbxref.accession', 'dbxref.description', 'dbxref.db_id', 'db.db_id');
  foreach ($fields_needed as $field_name) {
    // Check to see if it's excluded and expand it if so
    if ($node->expandable_fields) {
      if (in_array($field_name, $node->expandable_fields)) {
        $node = tripal_core_expand_chado_vars($node, 'field', $field_name);
      }
    }
  }

  // This defines the path for the next step in a simulated multipart form
  // NOTE: The %node gets replaced with the nid in insert
  $form['next_step_path'] = array(
    '#type' => 'hidden',
    '#value' => 'node/%node/properties'
  );

  // If you don't want a multipart form set this to false
  // Will then do default redirect (to new node) on submit
  $form['simulate_multipart'] = array(
    '#type' => 'textfield',
    '#attributes' => array('style' => "display:none"),
    '#default_value' => TRUE
  );

  if (!isset($node->stock->uniquename)) {
    $form['progress'] = array(
      '#type' => 'item',
      '#value' => tripal_stock_add_chado_properties_progress('main')
    );
  }

  $form['names'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stock Name')
  );

  $form['names']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $node->stock->name,
    '#required'       => TRUE
  );

  $form['names']['uniquename'] = array(
    '#type' => 'textfield',
    '#title' => t('Unique Name'),
    '#default_value' => $node->stock->uniquename,
    '#required'       => TRUE
  );

  $form['names']['stock_id'] = array(
    '#type' => 'hidden',
    '#value' => $node->stock->stock_id
  );

  $form['details'] = array(
    '#type' => 'fieldset',
    '#title' =>  t('Stock Details')
  );

  $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'NULL') );
  $type_options[0] = 'Select a Type';
  if ($node->nid == '') {
  $type_default = 0; }
  else { $type_default = $node->stock->type_id->cvterm_id; }
  $form['details']['type_id'] = array(
    '#type' => 'select',
    '#title' => t('Type of Stock'),
    '#options' => $type_options,
    '#default_value' => $type_default,
    '#required'    => TRUE,
  );

 
  // get the list of organisms
  $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
  $org_rset = chado_query($sql);
  $organisms = array();
  $organisms[''] = '';
  while ($organism = db_fetch_object($org_rset)) {
    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
  }
  $form['details']['organism_id'] = array(
    '#type' => 'select',
    '#title' => t('Source Organism for stock'),
    '#default_value' => $organism_default,
    '#options' => $organisms,
    '#required'    => TRUE
  );


  $form['details']['stock_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Notes'),
    '#default_value' => $node->stock->description,
    '#description' => t('Briefly enter any notes on the above stock. This should not include phenotypes or genotypes.'),
  );

  $form['database_reference'] = array(
    '#type' => 'fieldset',
    '#title' => t('Stock Database Reference')
  );

  $form['database_reference']['accession'] = array(
    '#type' => 'textfield',
    '#title' => t('Accession'),
    '#default_value' => $node->stock->dbxref_id->accession
  );

  $form['database_reference']['db_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description of Database Reference'),
    '#default_value' => $node->stock->dbxref_id->description,
    '#description' => t('Optionally enter a description about the database accession.')
  );

  $db_options = tripal_db_get_db_options();
  $db_options[0] = 'Select a Database';
  if ($node->nid == '') {
  $db_default = 0; }
  else { $db_default = $node->stock->dbxref_id->db_id->db_id; }
  $form['database_reference']['database'] = array(
    '#type' => 'select',
    '#title' => t('Database'),
    '#options' => $db_options,
    '#default_value' => $db_default
  );

  return $form;
}
chado_stock_insert ( node)

Implements hook_insert(): Inserts data from chado_stock_form() into drupal and chado

Parameters:
$nodeThe current node including fields with the form element names and submitted values
Returns:
TRUE if the node was successfully inserted into drupal/chado; FALSE otherwise

Definition at line 591 of file tripal_stock.module.

                                   {

  //If the chado stock exists
  // then don't create but simply link to node
  if ($node->chado_stock_exists) {
    if (!empty($node->stock_id)) {
      db_query(
        "INSERT INTO {chado_stock} (nid, vid, stock_id) "
        ."VALUES (%d, %d, %d)",
        $node->nid,
        $node->vid,
        $node->stock_id
      );
    }
    return $node;
  }

  // create dbxref
  if ( !empty($node->accession) ) {
    if ( !empty($node->database) ) {
      $values = array(
        'db_id' => $node->database,
        'accession' => $node->accession,
      );
      if (!tripal_core_chado_select('dbxref', array(dbxref_id), $values)) {
        $values['description'] = $node->db_description;
        $values['version'] = '1';
        $dbxref_status = tripal_core_chado_insert('dbxref', $values);
        if (!$dbxref_status) {
          drupal_set_message(t('Unable to add database reference to this stock.'), 'warning');
          watchdog('tripal_stock',
            'Insert Stock: Unable to create dbxref where values:%values',
            array('%values' => print_r($values, TRUE)),
            WATCHDOG_WARNING
          );
        }
      }
      else { $dbxref_status = 1; }
    }
  }

  // create stock
  if ($dbxref_status) {
    $values = array(
      'dbxref_id' => array(
        'db_id' => $node->database,
        'accession' => $node->accession
      ),
      'organism_id' => $node->organism_id,
      'name' => $node->title,
      'uniquename' => $node->uniquename,
      'description' => $node->stock_description,
      'type_id' => $node->type_id
    );
    $stock_status = tripal_core_chado_insert('stock', $values);
  }
  else {
    $values = array(
      'organism_id' => $node->organism_id,
      'name' => $node->title,
      'uniquename' => $node->uniquename,
      'description' => $node->stock_description,
      'type_id' => $node->type_id
    );
    $stock_status = tripal_core_chado_insert('stock', $values);
  }

  // create drupal chado_stock entry
  if ($stock_status) {
    $values = array(
      'organism_id' => $node->organism_id,
      'uniquename' => $node->uniquename,
      'type_id' => $node->type_id
    );
    $chado_stock = tripal_core_chado_select('stock', array('stock_id'), $values);
    if (!empty($chado_stock[0]->stock_id)) {
      db_query(
        "INSERT INTO {chado_stock} (nid, vid, stock_id) "
        ."VALUES (%d, %d, %d)",
        $node->nid,
        $node->vid,
        $chado_stock[0]->stock_id
      );

        //Move on to next stage of Stock Creation based on next_stage_path field
      if ($node->simulate_multipart) {
        $next_stage_path = preg_replace('/%node/', $node->nid, $node->next_step_path);
        $_REQUEST['destination'] = $next_stage_path;
      }
    }
    else {
      drupal_set_message(t('Error during stock creation.'), 'error');
      watchdog('tripal_stock',
        'Insert Stock: Unable to find newly created stock where values:%values',
        array('%values' => print_r($values, TRUE)),
        WATCHDOG_ERROR
      );
      return FALSE;
    }
  }
  else {
    drupal_set_message(t('Error during stock creation.'), 'error');
    watchdog('tripal_stock',
      'Insert Stock: Unable to create stock where values:%values',
      array('%values' => print_r($values, TRUE)),
      WATCHDOG_WARNING
    );
    return FALSE;
  }

}
chado_stock_load ( node)

Implements hook_load(): Prepares the chado_stock node

Parameters:
$nodeThe basic node containing all variables common to all nodes
Returns:
A stock node containing all the variables from the basic node and all stock specific variables

Definition at line 334 of file tripal_stock.module.

                                 {

  // get the stock details from chado
  $stock_id = chado_get_id_for_node('stock', $node);
  
  // build the variable with all the stock details
  $values = array('stock_id' => $stock_id);
  $stock = tripal_core_generate_chado_var('stock', $values);
  
  // add this to the node
  $additions = new stdClass();
  $additions->stock = $stock;
  return $additions;
}
chado_stock_update ( node)

Implements hook_update(): Handles Editing/Updating of main stock info

NOTE: Currently just writes over all old data

Parameters:
$nodeThe current node including fields with the form element names and submitted values
Returns:
TRUE if the node was successfully updated in drupal/chado; FALSE otherwise

Definition at line 716 of file tripal_stock.module.

                                   {

  if ($node->revision) {
    // there is no way to handle revisions in Chado but leave
    // this here just to make not we've addressed it.
  }
//  if ($node->revision) {
//    chado_stock_insert($node);
//  }
//  else {

  //update dbxref
  if ($node->database) {
    if ($node->accession) {
      $dbxref_mode = '';
      $stock = tripal_core_chado_select(
        'stock',
        array('dbxref_id', 'type_id'),
        array('stock_id' => $node->stock_id)
      );

      if ($stock[0]->dbxref_id) {
        $values = array(
          'db_id' => $node->database,
          'accession' => $node->accession,
          'description' => $node->db_description
        );
        $dbxref_status = tripal_core_chado_update(
          'dbxref',
          array('dbxref_id' => $stock[0]->dbxref_id),
          $values
        );
        $dbxref_mode = 'Update';
      }
      else {
        if ($stock[0]->type_id) {
          //create the dbxref
          //used the type_id as a control to check we have a stock but not a dbxref
          $values = array(
            'db_id' => $node->database,
            'accession' => $node->accession,
            'description' => $node->db_description,
            'version' => '1',
          );
          $dbxref_status = tripal_core_chado_insert(
            'dbxref',
            $values
          );
          $dbxref_mode = 'Create';
        }
        else {
          drupal_set_message(t('Unable to find stock to Update'), 'error');
          watchdog(
            'tripal_stock',
            'Stock Update: Unable to find stock to update using values: %values',
            array('%values', print_r($values, TRUE)),
            WATCHDOG_ERROR
          );
          return FALSE;
        }
      }
    }
  }

  if (!$dbxref_status) {
    watchdog(
      'tripal_stock',
      'Stock Update: Unable to %mode main stock dbxref with values: %values',
      array('%values' => print_r($values, TRUE), '%mode' => $dbxref_mode),
      WATCHDOG_WARNING
    );
  }

  //can't change stock id which is all thats stored in drupal thus only update chado
  $update_values = array(
    'organism_id' => $node->organism_id,
    'name' => $node->title,
    'uniquename' => $node->uniquename,
    'description' => $node->stock_description,
    'type_id' => $node->type_id,
  );
  if ($dbxref_status) {
    $update_values['dbxref_id'] = array(
      'db_id' => $node->database,
      'accession' => $node->accession
    );
  }
  $status = tripal_core_chado_update(
    'stock',
    array('stock_id' => $node->stock_id),
    $update_values
  );

  if (!$status) {
    drupal_set_message(t('Unable to update stock'), 'error');
    watchdog(
      'tripal_stock',
      'Stock Update: Unable to update stock using match values: %mvalues and update values: %uvalues',
      array('%mvalues' => print_r(array('stock_id' => $node->stock_id), TRUE), '%uvalues' => print_r($update_values, TRUE)),
      WATCHDOG_ERROR
    );
  }
}
chado_stock_validate ( node,
&$  form 
)

Implements hook_validate(): Validate the input from the chado_stock node form

Parameters:
$nodeThe current node including fields with the form element names and submitted values
$formA description of the form to be rendered by drupal_get_form()

Definition at line 516 of file tripal_stock.module.

                                             {

  $int_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s=%d";
  $string_in_chado_sql = "SELECT count(*) as count FROM %s WHERE %s='%s'";

  // Validate Uniquename only if add
  if (empty($node->stock_id)) {
    $chado_row = db_fetch_object(chado_query("SELECT * FROM {stock} WHERE uniquename='" . $node->uniquename . "'"));
    if (!empty($chado_row->stock_id)) {
      $drupal_row = db_fetch_object(db_query("SELECT * FROM {chado_stock} WHERE stock_id=" . $chado_row->stock_id));
      if (!empty($drupal_row->nid)) {
        $link = l('node/' . $drupal_row->nid, $node->uniquename);
        form_set_error('uniquename', "There is already a stock with that uniquename $link. Please enter another uniquename.");
      }
      else {
        form_set_error('uniquename', "There is already a stock with that uniquename (although it's not sync'd with drupal). Please enter another uniquename.");
      }
    }
  }


  // Check Type of Stock is valid cvterm_id in chado ( $form['values']['details']['type_id'] )
  if ( $node->type_id == 0) {
    form_set_error('type_id', 'Please select a type of stock.');
  }
  else {
    $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'cvterm', 'cvterm_id', $node->type_id));
    if ( $num_rows->count != 1) {
      form_set_error('type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
  }

  // Check Source Organism is valid organism_id in chado ( $form['values']['details']['organism_id'] )
  if ( $node->organism_id == 0) {
    form_set_error('organism_id', 'Please select a source organism for this stock');
  }
  else {
    $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'organism', 'organism_id', $node->organism_id));
    if ( $num_rows->count != 1 ) {
      form_set_error('organism_id', "The organism you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
  }

  // Check if Accession also database
  if ($node->accession != '') {
    if ($node->database == 0) {
      // there is an accession but no database selected
      form_set_error('database', 'You need to enter both a database and an accession for that database in order to add a database reference.');
    }
  }
  else {
    if ($node->database > 0) {
      // there is a database selected but no accession
      form_set_error('accession', 'You need to enter both a database and an accession for that database in order to add a database reference.');
    }
  }

  // Check database is valid db_id in chado ( $form['values']['database_reference']['database'] )
  if ( $node->database > 0) {
    $num_rows = db_fetch_object(chado_query($int_in_chado_sql, 'db', 'db_id', $node->database));
    if ($num_rows->count != 1) {
      form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
  }

}
cs_node_load ( nid)

Implements Menu wildcard_load hook

Purpose: Allows the node ID of a chado stock to be dynamically pulled from the path. The node is loaded from this node ID and supplied to the page as an arguement. This is an example of dynamic argument replacement using wildcards in the path.

Parameters:
$nidThe node ID passed in from the path
Returns:
The node object with the passed in nid

Definition at line 138 of file tripal_stock.module.

                            {
  if (is_numeric($nid)) {
    $node = node_load($nid);
    if ($node->type == 'chado_stock') {
      return $node;
    }
  }

  return FALSE;
}
get_tripal_stock_admin_form_cleanup_set ( &$  form)

Definition at line 313 of file tripal_stock-administration.inc.

                                                         {
  $form['cleanup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Clean Up')
  );
  $form['cleanup']['description'] = array(
     '#type' => 'item',
     '#value' => t("With Drupal and Chado residing in different databases ".
        "it is possible that nodes in Drupal and stocks in Chado become ".
        "\"orphaned\".  This can occur if an stock node in Drupal is ".
        "deleted but the corresponding chado stock is not and/or vice ".
        "versa. Click the button below to resolve these discrepancies."),
     '#weight' => 1,
  );
  $form['cleanup']['button'] = array(
    '#type' => 'submit',
    '#value' => t('Clean up orphaned stocks'),
    '#weight' => 2,
  );
}
theme_tripal_stock_edit_ALL_db_references_form ( form)

Themes the Edit All Database References for a stock form

Parameters:
$formAn array describing the form to be themed
Returns:
An HTML rendering of the form

Definition at line 396 of file tripal_stock-db_references.inc.

                                                               {
  $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;
}
theme_tripal_stock_edit_ALL_properties_form ( form)

Definition at line 355 of file tripal_stock-properties.inc.

                                                            {
  $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;
}
theme_tripal_stock_edit_ALL_relationships_form ( form)

Definition at line 478 of file tripal_stock-relationships.inc.

                                                               {
  $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;
}
tripal_stock_add_ALL_dbreferences_page ( node)

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

Parameters:
$nodeThe stock node to add the database references to
Returns:
HTML formatted output

Definition at line 20 of file tripal_stock-db_references.inc.

                                                       {
  $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;
}
tripal_stock_add_ALL_property_page ( node)

Definition at line 12 of file tripal_stock-properties.inc.

                                                   {
  $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;
}
tripal_stock_add_ALL_relationships_page ( node)

Definition at line 12 of file tripal_stock-relationships.inc.

                                                        {
  $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;
}
tripal_stock_add_chado_properties_navigate ( form_state,
step,
nid 
)

Definition at line 79 of file tripal_stock-secondary_tables.inc.

                                                                              {
  $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;
}
tripal_stock_add_chado_properties_navigate_submit ( form,
form_state 
)

Definition at line 146 of file tripal_stock-secondary_tables.inc.

                                                                               {

  $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;
  }

}
tripal_stock_add_chado_properties_progress ( current)

Definition at line 42 of file tripal_stock-secondary_tables.inc.

                                                              {

    $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;

}
tripal_stock_add_ONE_dbreference_form ( form_state,
node 
)

Implements Hook_form(): Handles adding of Database References to Stocks

Parameters:
$form_stateAn array describing the current state of the form
$nodeThe stock node to add the database reference to
Returns:
An array describing the form to be rendered

Definition at line 48 of file tripal_stock-db_references.inc.

                                                                   {

  $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;
}
tripal_stock_add_ONE_dbreference_form_submit ( form,
&$  form_state 
)

Implements hoook_form_submit(): Actually adds the db reference to the stock

Parameters:
$formAn array describing the form that was rendered
$form_stateAn array describing the current state of the form including user input

Definition at line 149 of file tripal_stock-db_references.inc.

                                                                           {

  // 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
    chado_query(
      "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')",
      $form_state['values']['database'],
      $form_state['values']['accession'],
      $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)) {
      chado_query(
        "INSERT INTO {stock_dbxref} (stock_id, dbxref_id) VALUES (%d, %d)",
        $form_state['values']['db_stock_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

}
tripal_stock_add_ONE_dbreference_form_validate ( form,
&$  form_state 
)

Implements hook_form_validate(): Validates the input from tripal_stock_add_ONE_dbreference_form()

Parameters:
$formAn array describing the form that was rendered
$form_stateAn array describing the current state of the form including user input

Definition at line 107 of file tripal_stock-db_references.inc.

                                                                             {

  // 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) {
      $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $form_state['values']['database']));

      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
    $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {dbxref} WHERE accession='%s'", $form_state['values']['accession']));

    if ($tmp_obj->count > 0) {
      form_set_error('accession', 'This accession has already been assigned to another stock.');
    }

  } //end of if adding

}
tripal_stock_add_ONE_property_form ( form_state,
node 
)

Definition at line 31 of file tripal_stock-properties.inc.

                                                                {
  $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;
}
tripal_stock_add_ONE_property_form_submit ( form,
&$  form_state 
)

Definition at line 125 of file tripal_stock-properties.inc.

                                                                        {

  // 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; }

    chado_query(
      "INSERT INTO {stockprop} (stock_id, type_id, value, rank) VALUES (%d, %d, '%s', %d)",
      $form_state['values']['prop_stock_id'],
      $form_state['values']['prop_type_id'],
      $form_state['values']['prop_value'],
      $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_execute('chado_stock_node_form', $node_form_state, $node);

    }

  } //end of if property to add
}
tripal_stock_add_ONE_property_form_validate ( form,
&$  form_state 
)

Definition at line 86 of file tripal_stock-properties.inc.

                                                                          {

  // 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 = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['prop_type_id']));
      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

}
tripal_stock_add_ONE_relationship_form ( form_state,
node 
)

Implements Hook_form(): Handles adding of Relationships to Stocks

Definition at line 31 of file tripal_stock-relationships.inc.

                                                                    {

  $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;

}
tripal_stock_add_ONE_relationship_form_submit ( form,
&$  form_state 
)

Definition at line 178 of file tripal_stock-relationships.inc.

                                                                            {

  if ($form_state['values']['subject_id'] > 0) {
    chado_query(
      "INSERT INTO {stock_relationship} (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
      $form_state['values']['subject_id'],
      $form_state['values']['type_id'],
      $form_state['values']['object_id'],
      $form_state['values']['r_description']
    );

    drupal_set_message(t('Successfully Added Relationship.'));
  } //end of insert relationship

}
tripal_stock_add_ONE_relationship_form_validate ( form,
&$  form_state 
)

Definition at line 107 of file tripal_stock-relationships.inc.

                                                                              {

  //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 {
      $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['type_id']));

      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
}
tripal_stock_admin ( )

Purpose: Provide administration options for chado_stocks

Returns:
Form array (as described by the drupal form api)

Definition at line 15 of file tripal_stock-administration.inc.

                              {
  $form = array();

  // before proceeding check to see if we have any
  // currently processing jobs. If so, we don't want
  // to give the opportunity to sync Stocks
  $active_jobs = FALSE;
  if (tripal_get_module_active_jobs('tripal_stock')) {
    $active_jobs = TRUE;
  }
  if ($active_jobs) {
    $form['notice'] = array(
       '#type' => 'fieldset',
       '#title' => t('Stock Management Temporarily Unavailable')
    );
    $form['notice']['message'] = array(
       '#value' => t("Currently, stock management jobs are waiting or ".
          "are running. Managemment features have been hidden until these ".
          "jobs complete.  Please check back later once these jobs have ".
          "finished.  You can view the status of pending jobs in the Tripal ".
          "jobs page."),
    );
  }
  else {

    // SET Vocabularies -----------------------------------------------------------------------------------------
    $form['set_cv'] = array(
      '#type' => 'fieldset',
      '#title' => t('Set Stock Controlled Vocabularies'),
      '#weight' => -10
    );

    $form['set_cv']['message'] = array(
         '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
                ." are used. Cvs are used to control user input for the type of stock,"
          ." any properties they enter for a stock & the types of relationships"
          ." between stocks. Only cvs already loaded into chado can be selected here.")
    );

    // get the list of CVs for the next form element
    $sql = "SELECT * FROM {cv} ORDER BY name";
    $results = chado_query($sql);
    $cv_options = array();
    while ($r = db_fetch_object($results)) {
      $cv_options[$r->cv_id] = $r->name;
    }

    $form['set_cv']['stock_types_cv'] = array(
     '#type' => 'select',
     '#title' => t('Controlled Vocabulary governing Stock Types'),
     '#options' => $cv_options,
     '#default_value' => variable_get('chado_stock_types_cv', 0)
    );

    $form['set_cv']['stock_prop_types_cv'] = array(
     '#type' => 'select',
     '#title' => t('Controlled Vocabulary governing Types of Stock Properties'),
     '#description' => t("This cv must contain a cvterm entry where name='synonym'."),
     '#options' => $cv_options,
     '#default_value' => variable_get('chado_stock_prop_types_cv', 0)
    );

    $form['set_cv']['stock_relationship_cv'] = array(
     '#type' => 'select',
     '#title' => t('Controlled Vocabulary governing Types of Relationsips between Stocks'),
     '#options' => $cv_options,
     '#default_value' => variable_get('chado_stock_relationship_cv', 0)
    );

    $form['set_cv']['button'] = array(
      '#type' => 'submit',
      '#value' => t('Set Controlled Vacabularies')
    );

    // SYNC STOCKS-----------------------------------------------------------------------------------------------
    $form['sync'] = array(
      '#type' => 'fieldset',
      '#title' => t('Sync Stocks'),
      '#weight' => -10
    );

    $form['sync']['description'] = array(
      '#type' => 'item',
      '#value' => t("Click the 'Sync all Germplasm' button to create Drupal ".
         "content for stocks in chado. Depending on the ".
         "number of stocks in the chado database this may take a long ".
         "time to complete. ")
    );

    // get the list of organisms
    $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
    $org_rset = chado_query($sql);
    $organisms = array();
    $organisms[''] = '';
    while ($organism = db_fetch_object($org_rset)) {
      $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
    }
    $form['sync']['organisms'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Organisms for which Stocks should be sync\'d'),
      '#description' => t('Only sync\'d Organisms are listed. Leaving an organism unchecked does not delete already sync\'d Stocks.'),
      '#options' => $organisms,
      '#required'    => FALSE,
      '#prefix'      => '<div id="lib_boxes">',
      '#suffix'      => '</div>'
    );

    $form['sync']['button'] = array(
      '#type' => 'submit',
      '#value' => t('Sync Stocks')
    );
    get_tripal_stock_admin_form_cleanup_set($form);
  }

  return system_settings_form($form);

}
tripal_stock_admin_validate ( form,
&$  form_state 
)

Implements hook_form_validate(): Validates user input

Parameters:
$formAn array describing the form that was rendered
$form_stateAn array describing the current state of the form including user input

Definition at line 143 of file tripal_stock-administration.inc.

                                                          {
  global $user;  // we need access to the user info
  $job_args = array();

  // Sync Stocks
  if ($form_state['values']['op'] == t('Sync Stocks')) {
    // Array organism_id => organims common_name
    //  which only includes those organisms which the user wants to select stocks for
    $organisms_2b_syncd = $form_state['values']['organisms'];

    //for each organism selected submit job (handled by tripal_stock_sync_stock_set)
    //  which syncs all stocks with an organism_id equal to the selelcted organism
    foreach ( $organisms_2b_syncd as $organism_id ) {
      if ($organism_id != 0) {
        $job_args[0] = $organism_id;
        tripal_add_job("Sync Stocks from Organism $organism_id", 'tripal_stock',
          'tripal_stock_sync_stock_set', $job_args, $user->uid);
      }
    }
  }

  if ($form_state['values']['op'] == t('Set Controlled Vacabularies')) {
    variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
    variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
    variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
  }

  // Submit the Cleanup Job if selected
  if ($form_state['values']['op'] == t('Clean up orphaned stocks')) {
    tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
       'tripal_stock_cleanup', $job_args, $user->uid);
  }
}
tripal_stock_back_to_stock_button ( form_state,
nid 
)

Definition at line 12 of file tripal_stock-secondary_tables.inc.

                                                              {
  $form = array();

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $nid
  );

  $form["submit-back"] = array(
    '#type' => 'submit',
    '#value' => t('Back to Stock')
  );

  return $form;
}
tripal_stock_back_to_stock_button_submit ( form,
form_state 
)

Definition at line 33 of file tripal_stock-secondary_tables.inc.

                                                                      {
  drupal_goto('node/' . $form_state['values']['nid']);
}
tripal_stock_block ( op = 'list',
delta = 0,
edit = array() 
)

Purpose: Implement Blocks relating to stock content

Parameters:
$opWhat kind of information to retrieve about the block or blocks. Possible values include list, configure, save, view.
$deltaWhich block to return (not applicable if $op is 'list').
$editIf $op is 'save', the submitted form data from the configuration form.
Returns:
One of the following depending on $op: An array of block descriptions (list), the configuration form (configure), nothing (save), an array defining subject and content for the block indexed by $delta (view)

Definition at line 866 of file tripal_stock.module.

                                                                     {
  switch ($op) {
    case 'list':
      $blocks['base']['info'] = t('Tripal Stock Details');
      $blocks['base']['cache'] = BLOCK_NO_CACHE;

      $blocks['properties']['info'] = t('Tripal Stock Properties');
      $blocks['properties']['cache'] = BLOCK_NO_CACHE;

      $blocks['references']['info'] = t('Tripal Stock References');
      $blocks['references']['cache'] = BLOCK_NO_CACHE;

      $blocks['relationships_as_object']['info'] = t('Tripal Stock Relationships');
      $blocks['relationships_as_object']['cache'] = BLOCK_NO_CACHE;

      $blocks['synonyms']['info'] = t('Tripal Stock Synonyms');
      $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['collections']['info'] = t('Tripal Stock Collections');
      $blocks['collections']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['phenotypes']['info'] = t('Tripal Stock Phenotypes');
      $blocks['phenotypes']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['genotypes']['info'] = t('Tripal Stock Genotypes');
      $blocks['genotypes']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['locations']['info'] = t('Tripal Stock Locations');
      $blocks['locations']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['orgstocks']['info'] = t('Tripal Organism Stocks');
      $blocks['orgstocks']['cache'] = BLOCK_NO_CACHE;
      
      

      return $blocks;

    case 'view':
      if (user_access('access chado_stock content') and arg(0) == 'node' and is_numeric(arg(1))) {
      $nid = arg(1);
      $node = node_load($nid);

      $block = array();
      switch ($delta) {
        case 'base':
          $block['subject'] = t('Stock Details');
          $block['content'] = theme('tripal_stock_base', $node);
          break;

        case 'properties':
          $block['subject'] = t('Properties');
          $block['content'] = theme('tripal_stock_properties', $node);
          break;

        case 'references':
          $block['subject'] = t('References');
          $block['content'] = theme('tripal_stock_references', $node);
          break;

        case 'relationships':
          $block['subject'] = t('Relationships');
          $block['content'] = theme('tripal_stock_relationships', $node);
          break;

        case 'synonyms':
          $block['subject'] = t('Synonyms');
          $block['content'] = theme('tripal_stock_synonyms', $node);
          break;
          
        case 'collections':
          $block['subject'] = t('Stock Collections');
          $block['content'] = theme('tripal_stock_collections', $node);
          break;
          
        case 'phenotypes':
          $block['subject'] = t('Stock Phenotypes');
          $block['content'] = theme('tripal_stock_phenotypes', $node);
          break;
          
        case 'genotypes':
          $block['subject'] = t('Stock Genotypes');
          $block['content'] = theme('tripal_stock_genotypes', $node);
          break;
          
        case 'locations':
          $block['subject'] = t('Stock Locations');
          $block['content'] = theme('tripal_stock_locations', $node);
          break;
          
        case 'orgstocks':
          $block['subject'] = t('Organism Stocks');
          $block['content'] = theme('tripal_organism_stocks', $node);
          break;

      }
      return $block;
    }
  }
}
tripal_stock_cleanup ( dummy = NULL,
job_id = NULL 
)

Remove orphaned drupal nodes

Parameters:
$dummyNot Used -kept for backwards compatibility
$job_idThe id of the tripal job executing this function

Definition at line 343 of file tripal_stock-administration.inc.

                                                             {

  return tripal_core_clean_orphaned_nodes('stock', $job_id);

}
tripal_stock_delete_db_reference ( dbxref_id)

Deletes a given database reference

Parameters:
$dbxref_idThe chado unique idenfier for the database reference to be deleted
Returns:
TRUE on success; FALSE otherwise

Definition at line 371 of file tripal_stock-db_references.inc.

                                                      {

  chado_query(
    "DELETE FROM {dbxref} WHERE dbxref_id=%d",
    $dbxref_id
  );

  chado_query(
    "DELETE FROM {stock_dbxref} WHERE dbxref_id=%d",
    $dbxref_id
  );

}
tripal_stock_delete_property ( stockprop_id)

Definition at line 341 of file tripal_stock-properties.inc.

                                                     {

  chado_query(
    "DELETE FROM {stockprop} WHERE stockprop_id=%d",
    $stockprop_id
  );

}
tripal_stock_delete_relationship ( stock_relationship_id)

Definition at line 464 of file tripal_stock-relationships.inc.

                                                                  {

  chado_query(
    "DELETE FROM {stock_relationship} WHERE stock_relationship_id=%d",
    $stock_relationship_id
  );

}
tripal_stock_edit_ALL_db_references_form ( form_state,
node 
)

Implements Hook_form(): Handles adding of Database References to Stocks

Specifically this adds dbxrefs to a current stock using the stock_dbxref table

Parameters:
$form_stateAn array describing the current state of the form
$nodeThe stock node whose database references should be edited
Returns:
An array describing the form to be rendered

Definition at line 226 of file tripal_stock-db_references.inc.

                                                                      {
  $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;
}
tripal_stock_edit_ALL_db_references_form_submit ( form,
&$  form_state 
)

Implements hook_form_submit(): Actually edits the database references

Parameters:
$formAn array representing the form
$form_stateAn array representing the current state of the form including user input

Definition at line 306 of file tripal_stock-db_references.inc.

                                                                              {

  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');

  }
}
tripal_stock_edit_ALL_dbreferences_page ( node)

Display the EDIT Database References to Stock Page

This page is displayed as a tab on each stock details page (by default)

Parameters:
$nodeThe stock node to add the database references to
Returns:
HTML formatted output

Definition at line 199 of file tripal_stock-db_references.inc.

                                                        {
  $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;
}
tripal_stock_edit_ALL_properties_form ( form_state,
node 
)

Implements Hook_form(): Handles adding of Properties & Synonyms to Stocks

Definition at line 190 of file tripal_stock-properties.inc.

                                                                   {
  $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;
}
tripal_stock_edit_ALL_properties_form_submit ( form,
&$  form_state 
)

Definition at line 261 of file tripal_stock-properties.inc.

                                                                           {

  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');
  }


}
tripal_stock_edit_ALL_properties_page ( node)

Definition at line 173 of file tripal_stock-properties.inc.

                                                      {
  $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;
}
tripal_stock_edit_ALL_relationships_form ( form_state,
node 
)

Implements Hook_form()

Definition at line 216 of file tripal_stock-relationships.inc.

                                                                      {
  $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;
}
tripal_stock_edit_ALL_relationships_form_submit ( form,
&$  form_state 
)

Definition at line 408 of file tripal_stock-relationships.inc.

                                                                              {

  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');
  }

}
tripal_stock_edit_ALL_relationships_form_validate ( form,
&$  form_state 
)

Definition at line 331 of file tripal_stock-relationships.inc.

                                                                                {

  // 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 {
        $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']["type_id-$i"]));

        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

}
tripal_stock_edit_ALL_relationships_page ( node)

Definition at line 199 of file tripal_stock-relationships.inc.

                                                         {
  $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;
}
tripal_stock_is_obsolete_form ( node,
stock_id 
)

Definition at line 203 of file tripal_stock-secondary_tables.inc.

                                                         {

  $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;
}
tripal_stock_is_obsolete_form_submit ( form,
&$  form_state 
)

Definition at line 224 of file tripal_stock-secondary_tables.inc.

                                                                   {

  chado_query(
    "UPDATE {stock} SET is_obsolete='t' WHERE stock_id=%d",
    $form_state['values']['make_obsolete_stock_id']
  );

}
tripal_stock_list_dbreferences_for_node ( db_references)

List all database references for a given node

Parameters:
$db_referencesAn array of database references to be listed
Returns:
HTML representation of the list

Definition at line 434 of file tripal_stock-db_references.inc.

                                                                 {

  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;
}
tripal_stock_list_properties_for_node ( properties,
synonyms 
)

Definition at line 383 of file tripal_stock-properties.inc.

                                                                       {

  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;
}
tripal_stock_list_relationships_for_node ( stock_name,
subject_relationships,
object_relationships 
)

Definition at line 510 of file tripal_stock-relationships.inc.

                                                                                                              {

  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;

}
tripal_stock_menu ( )

Implements hook_menu(): Adds menu items for the tripal_stock

Returns:
Menu definitions for the tripal_stock

Definition at line 39 of file tripal_stock.module.

                             {
  $items = array();

  //Administrative settings menu-----------------
  $items['admin/tripal/tripal_stock'] = array(
    'title' => 'Stocks',
    'description' => 'Basic Description of Tripal Stock Module Functionality',
    'page callback' => 'theme',
    'page arguments' => array('tripal_stock_admin'),
    'access arguments' => array('administer tripal stocks'),
    'type' => MENU_NORMAL_ITEM
  );

  $items['admin/tripal/tripal_stock/configuration'] = array(
    'title' => 'Configuration',
    'description' => 'Settings for Chado Stocks',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_stock_admin'),
    'access arguments' => array('administer tripal stocks'),
    'type' => MENU_NORMAL_ITEM
  );

  // 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,
  );
  return $items;
}
tripal_stock_node_info ( )

Implements hook_node_info(): registers a stock node type

Returns:
An array describing various details of the node

Definition at line 311 of file tripal_stock.module.

                                  {
  return array(
    'chado_stock' => array(
      'name' => t('Stock'),
      'module' => 'chado_stock',
      'description' => t('A Chado Stock is a collection of material that can be sampled and have experiments performed on it.'),
      'has_title' => TRUE,
      'has_body' => FALSE,
    ),
  );
}
tripal_stock_nodeapi ( &$  node,
op,
teaser,
page 
)

Implementation of hook_nodeapi(). Display stock information for associated organisms This function also provides contents for indexing

Definition at line 1054 of file tripal_stock.module.

                                                           {

  switch ($op) {
    // Note that this function only adds stock view to an organism/feature
    // node.
    case 'view':
      // add the stock to the organism/feature search indexing
      if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {

      }
      elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {

      }
      else {
        switch ($node->type) {
          case 'chado_organism':
            // Show stock if the organism/feature is not at teaser view
            $node->content['tripal_organism_stocks'] = array(
              '#value' => theme('tripal_organism_stocks', $node),
            );
            break;          
        }
      }
      break;
  }
}
tripal_stock_perm ( )

Implementation of hook_perm().

Purpose: Set the permission types that the chado stock module uses

Returns:
Listing of the possible permission catagories

Definition at line 159 of file tripal_stock.module.

                             {
  return array(
    'access chado_stock content',
    'create chado_stock content',
    'edit chado_stock content',
    'delete chado_stock content',
    'administer tripal stocks',
  );
}
tripal_stock_preprocess_tripal_organism_stocks ( &$  variables)

Definition at line 1086 of file tripal_stock.module.

                                                                     {
  $organism = $variables['node']->organism;

  if (!$organism) {
    return;
  }
  
  // get the stocks for this organism
  $sql  = "SELECT S.name, S.stock_id, S.uniquename, CVT.name as cvname ".
          "FROM {stock} S ".
          "  INNER JOIN {cvterm} CVT on S.type_id = CVT.cvterm_id ".
          "WHERE organism_id = %s".
          "ORDER BY stock_id ASC";

  // the counting SQL
  $csql  = "SELECT count(*) ".
           "FROM {stock} S".
           "  INNER JOIN {cvterm} CVT on S.type_id = CVT.cvterm_id ".
           "WHERE organism_id = %s ".
           "GROUP BY organism_id ";

  $previous_db = tripal_db_set_active('chado');  // use chado database
  $org_stocks = pager_query($sql, 25, 0, $csql, $organism->organism_id);
  tripal_db_set_active($previous_db);  // now use drupal database
  
  // get the pager and reformat so it shows the right block
  $pager = theme('pager');  

  // prepare the query that will lookup node ids
  $sql = "SELECT nid FROM {chado_stock} ".
         "WHERE stock_id = %d";
  $i=0;
  $stocks = array();
  while ($stock = db_fetch_object($org_stocks)) {
    $node = db_fetch_object(db_query($sql, $stock->stock_id));
    $stock->nid = $node->nid;
    $stocks[$i++] = $stock;
  }
  
  $organism->stock_browser =  array('stocks' => $stocks, 'pager' => $pager, 'enabled' => TRUE );
}
tripal_stock_preprocess_tripal_stock_relationships ( &$  variables)

Definition at line 971 of file tripal_stock.module.

                                                                         {
  // we want to provide a new variable that contains the matched stocks.
  $stock = $variables['node']->stock;
   
  // normally we would use tripal_core_expand_chado_vars to expand our
  // organism object and add in the relationships, however whan a large
  // number of relationships are present this significantly slows the
  // query, therefore we will manually perform the query
  $sql = "
    SELECT 
      S.name, S.uniquename, S.stock_id, CS.nid, 
      CVT.name as rel_type, CVTs.name as obj_type,
      SR.value
    FROM stock_relationship SR
      INNER JOIN stock S on SR.object_id = S.stock_id
      INNER JOIN cvterm CVT on SR.type_id = CVT.cvterm_id
      INNER JOIN cvterm CVTs on S.type_id = CVTs.cvterm_id
      LEFT JOIN chado_stock CS on S.stock_id = CS.stock_id
    WHERE SR.subject_id = %d      
  ";
  $as_subject = chado_query($sql, $stock->stock_id);
  $sql = "
    SELECT 
      S.name, S.uniquename,  S.stock_id, CS.nid, 
      CVT.name as rel_type, CVTs.name as sub_type,
      SR.value
    FROM stock_relationship SR
      INNER JOIN stock S on SR.subject_id = S.stock_id
      INNER JOIN cvterm CVT on SR.type_id = CVT.cvterm_id
      INNER JOIN cvterm CVTs on S.type_id = CVTs.cvterm_id
      LEFT JOIN chado_stock CS on S.stock_id = CS.stock_id
    WHERE SR.object_id = %d      
  ";
  $as_object = chado_query($sql, $stock->stock_id);   
  
  // combine both object and subject relationshisp into a single array
  $relationships = array();
  $relationships['object'] = array();
  $relationships['subject'] = array();
  
  // iterate through the object relationships
  while ($relationship = db_fetch_object($as_object)) {
     
     // get the relationship and child types
     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
     $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
     
     if (!array_key_exists($rel_type, $relationships['object'])) {
       $relationships['object'][$rel_type] = array();   
     }
     if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
       $relationships['object'][$rel_type][$sub_type] = array();   
     }
     $relationships['object'][$rel_type][$sub_type][] = $relationship;     
  }
  
  // now add in the subject relationships
  while ($relationship = db_fetch_object($as_subject)) {
     
     // get the relationship and child types
     $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
     $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
     
     if (!array_key_exists($rel_type, $relationships['subject'])) {
       $relationships['subject'][$rel_type] = array();   
     }
     if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
       $relationships['subject'][$rel_type][$obj_type] = array();   
     }
     $relationships['subject'][$rel_type][$obj_type][] = $relationship;     
  }
  
  
  $stock->all_relationships = $relationships;

}
tripal_stock_sync_stock_set ( organism_id,
job_id 
)

Syncs all Stocks associated with an organism

Note: Handling of multiple organisms is done in tripal_stock_admin_validate()

Parameters:
$organism_idThe chado primary key of the organism for which stocks should be sync'd
$job_idThe tripal job ID
Returns:
TRUE if successful; FALSE otherwise

db_query( "INSERT INTO chado_stock (stock_id, nid, vid) VALUES (%d, %d, %d)", $r->stock_id, $node->nid, $node->vid );

Definition at line 218 of file tripal_stock-administration.inc.

                                                            {
  global $user;

  if (!$organism_id) {
    print '0 Stocks to Sync -No Organisms Selected.\n';
  }
  else {

  // Get list of stocks to sync
  $result = chado_query(
     "SELECT stock_id, uniquename, type_id, organism_id FROM {stock} WHERE organism_id=%d",
      $organism_id
  );

  $stocks_created_count = 0; //keeps track of total number of stocks successfully created
  $stocks_attempted = 0;
  // foreach stock to be sync'd -> create node & add stock_id
  while ( $r = db_fetch_object($result) ) {
    // $r is the current stock to be sync'd
    $stocks_attempted++;

    print 'Processing ' . $r->uniquename . "... ";

    // check not already in drupal
    $in_drupal_query = db_query(
      "SELECT * FROM {chado_stock} WHERE stock_id=%d",
      $r->stock_id
    );
    if ( !db_fetch_object($in_drupal_query) ) {

      //create new chado_stock node
      $new_node = new stdClass();
      $new_node->type = 'chado_stock';
      $new_node->uid = $user->uid;
      $new_node->title = $r->uniquename;
      $new_node->type_id = $r->type_id;
      $new_node->organism_id = $r->organism_id;
      $new_node->stock_id = $r->stock_id;
      $new_node->chado_stock_exists = TRUE;

      //print 'New Node:';
      //print_r($new_node);

      node_validate($new_node);

      if (!form_get_errors()) {
        //print 'Try to Create Node ';
        $node = node_submit($new_node);
        node_save($node);
        if ($node->nid) {
          $stocks_created_count++;

          //Add stock id to chado_stock table
          }
        }
        else {
          print "Not completed due to errors:\nCreate Stock Form Errors: ";
          print_r(form_get_errors());
        }
        print "Nid=" . $node->nid . "\n";
      }
      else {
        print "Skipped $r->uniquename because it's already in drupal.\n";
      } //end of if not already in drupal
    } //end of while still stocks to be sync'd
  } //end of if organism_id not supplied

  if ($stocks_attempted == 0) {
    print "No stocks retrieved for organism (" . $organism_id . ")\n";
    return 1;
  }
  else {
    if ($stocks_created_count > 0) {
      print "$stocks_created_count Stocks Successfully Created\n";
      return 1;
    }
    else {
      return 0;
    }
  }
}
tripal_stock_theme ( )

Implements hook_theme(): Register themeing functions for this module

Returns:
An array of themeing functions to register

Definition at line 234 of file tripal_stock.module.

                              {
  return array(

    // Property edit forms--------------------------
    'tripal_stock_edit_ALL_properties_form' => array(
      'arguments' => array('form'),
      'function' => 'theme_tripal_stock_edit_ALL_properties_form',
    ),
    'tripal_stock_edit_ALL_db_references_form' => array(
      'arguments' => array('form'),
      'function' => 'theme_tripal_stock_edit_ALL_db_references_form',
    ),
    'tripal_stock_edit_ALL_relationships_form' => array(
      'arguments' => array('form'),
      'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
    ),
    // Block Templates------------------------------
    'tripal_stock_base' => array(
      'arguments' => array('node' => NULL),
      'template' => 'tripal_stock_base',
    ),
    'tripal_stock_properties' => array(
      'arguments' => array('node' => NULL),
      'template' => 'tripal_stock_properties',
    ),
    'tripal_stock_references' => array(
      'arguments' => array('node' => NULL),
      'template' => 'tripal_stock_references',
    ),
    'tripal_stock_relationships' => array(
      'arguments' => array('node' => NULL),
      'template' => 'tripal_stock_relationships',
    ),
    'tripal_stock_synonyms' => array(
      'arguments' => array('node' => NULL),
      'template' => 'tripal_stock_synonyms',
    ),
    'tripal_stock_collections' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_collections',
    ),
    'tripal_stock_collections' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_collections',
    ),
    'tripal_stock_phenotypes' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_phenotypes',
    ),
    'tripal_stock_genotypes' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_genotypes',
    ),
    'tripal_stock_locations' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_stock_locations',
    ),    
    'tripal_organism_stocks' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_organism_stocks',
    ),    
    'tripal_stock_admin' => array(
      'template' => 'tripal_stock_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_stock') . '/theme', 
    ),
  );
}
tripal_stock_update_db_reference ( dbxref_id,
database_id,
accession 
)

Updates a Database Reference

Parameters:
$dbxref_idThe unique chado identifier of the database reference to be updated
$database_idThe new database ID
$accessionThe new accession

Definition at line 349 of file tripal_stock-db_references.inc.

                                                                                {

  chado_query(
    "UPDATE {dbxref} SET db_id=%d, accession='%s' WHERE dbxref_id=%d",
    $database_id,
    $accession,
    $dbxref_id
  );

}
tripal_stock_update_property ( stockprop_id,
cvterm_id,
value,
preferred,
nid 
)

Definition at line 288 of file tripal_stock-properties.inc.

                                                                                           {

  $old_obj = db_fetch_object(chado_query("SELECT * FROM {stockprop} WHERE stockprop_id=%d", $stockprop_id));

  // 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) {
    chado_query(
      "UPDATE {stockprop} SET type_id=%d, value='%s' WHERE stockprop_id=%d",
      $cvterm_id,
      $value,
      $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; }
      chado_query(
        "UPDATE {stockprop} SET type_id=%d, value='%s', rank=%d WHERE stockprop_id=%d",
        $cvterm_id,
        $value,
        $rank,
        $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_execute('chado_stock_node_form', $node_form_state, $node);
  }
}
tripal_stock_update_relationship ( stock_relationship_id,
subject_id,
cvterm_id,
object_id 
)

Definition at line 447 of file tripal_stock-relationships.inc.

                                                                                                       {

  chado_query(
    "UPDATE {stock_relationship} SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
    $subject_id,
    $cvterm_id,
    $object_id,
    $stock_relationship_id
  );

}
tripal_stock_views_api ( )

Implements hook_views_api()

Purpose: Essentially this hook tells drupal that there is views support for for this module which then includes tripal_stock.views.inc where all the views integration code is

Returns:
An array with fields important for views integration

Definition at line 220 of file tripal_stock.module.

                                  {
  return array(
    'api' => 2.0,
  );
}
 All Classes Files Functions Variables