function tripal_stock_get_stocks

2.x tripal_stock.DEPRECATED.inc tripal_stock_get_stocks($values)
3.x tripal_stock.DEPRECATED.inc tripal_stock_get_stocks($values)
1.x tripal_stock.api.inc tripal_stock_get_stocks($values)

Purpose: Return all stocks that match a given criteria

  $values =  array(
    'organism_id' => array(
        'genus' => 'Lens',
        'species' => 'culinaris',
     ),
    'name' => 'CDC Redberry',
    'type_id' => array (
        'cv_id' => array (
           'name' => 'germplasm',
        ),
        'name' => 'registered_cultivar',
        'is_obsolete' => 0
     ),
  );
  $result = tripal_stock_get_stocks($values);

The above code selects a record from the chado stock table using three fields with values which identify a stock or multiple stocks. Then the node for each stock identified is returned, if it exists. The $values array is nested such that the organism is identified by way of the organism_id foreign key constraint by specifying the genus and species. The cvterm is also specified using its foreign key and the cv_id for the cvterm is nested as well.

Parameters

$values: An associative array containing the values for filtering the results.

Return value

An array of matching stock objects (produced using node_load) matching the given criteria

Example usage:

Related topics

File

tripal_stock/api/tripal_stock.api.inc, line 109
Provides an application programming interface (API) to manage stocks

Code

function tripal_stock_get_stocks($values) {

  $stock_ids = tripal_core_chado_select('stock', array('stock_id'), $values);

  // Change from stock_ids to nodes-----------------------------------
  $stock_ids = array_filter($stock_ids);
  $stock_ids = array_unique($stock_ids);

  $stocks = array();
  foreach ($stock_ids as $stock_id) {
    $node = tripal_stock_get_stock_by_stock_id($stock_id->stock_id);
    if ($node) {
      $stocks[] = $node;
    }
  }

  return $stocks;
}