Просмотр исходного кода

API: updated stock api and added generic chado_get_record_with_property function

Lacey Sanderson 11 лет назад
Родитель
Сommit
a1bc820447

+ 97 - 0
tripal_core/api/tripal_core.chado_general.api.inc

@@ -394,3 +394,100 @@ function chado_delete_property($basetable, $record_id, $property, $cv_name) {
 
   return chado_delete_record($basetable . 'prop', $match);
 }
+
+/**
+ * Get all records with a given property.
+ *
+ * @param $basetable
+ *   The base table for which variables should be generated.
+ * @param $property
+ *   An array/object describing the property to select records for. It should at least
+ *   have either a type_name (if unique across cvs) or type_id. Other supported keys
+ *   include: cv_id/cv_name (of the type), value and rank
+ * @param $record
+ *   An array/object describing the base table record. This can be used to restrict the
+ *   base table records returned to a given type or organism
+ * @param $options
+ *   An array of options. Supported keys include:
+ *     - Any keys supported by chado_generate_var(). See that function definition for
+ *       additional details.
+ *
+ * @return
+ *   An array of chado variables with the given property
+ *
+ * @ingroup tripal_chado_api
+ */
+function chado_get_record_with_property($basetable, $property, $record = array(), $options = array()) {
+  $property_table = $basetable . 'prop';
+  $foreignkey_name = $basetable . '_id';
+
+  // Get paramters in the correct format
+  if (is_array($property)) {
+    $property = (object) $property;
+  }
+  if (is_object($record)) {
+    $record = (array) $record;
+  }
+
+  // Check parameters
+  if (!isset($property->type_name) AND !isset($property->type_id)) {
+    tripal_report_error(
+      'chado_api',
+      TRIPAL_ERROR,
+      "chado_get_record_with_property: You must identify the type of property you want to
+       select records for by supplying either a type_name or type_id. You identified the
+       property as %prop.",
+      array(
+        '%prop'=> print_r($property, TRUE)
+      )
+    );
+  }
+
+  // Build the select values array based on the type
+  if (isset($property->type_name)) {
+    $values = array();
+    $values['type_id'] = array(
+      'name' => $property->type_name
+    );
+
+    // If the cv is set, add that too
+    if (isset($property->cv_name)) {
+      $values['type_id']['cv_id']['name'] = $property->cv_name;
+    }
+    elseif (isset($property->cv_id)) {
+      $values['type_id']['cv_id'] = $property->cv_id;
+    }
+  }
+  elseif ($property->type_id) {
+    $values = array('type_id' => $property->type_id);
+  }
+
+  // Add the value and rank to values array if present
+  if (isset($property->value)) {
+    $values['value'] = $property->value;
+  }
+  if (isset($property->rank)) {
+    $values['rank'] = $property->rank;
+  }
+
+  // Add the record details to the values array
+  if (!empty($record)) {
+    $values[$foreignkey_name] = $record;
+  }
+
+  // Now select the ids of the properties that match
+  $select = chado_select_record($property_table, array($foreignkey_name), $values);
+
+  // For each of these ids, pull out the full base records
+  $records = array();
+  foreach ($select as $s) {
+    $id = $s->{$foreignkey_name};
+    $records[$id] = chado_generate_var(
+      $basetable,
+      array($foreignkey_name => $id),
+      $options
+    );
+  }
+
+  return $records;
+}

+ 1 - 1
tripal_cv/api/tripal_cv.DEPRECATED.inc

@@ -166,7 +166,7 @@ function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal')
     $identifiers['cv_id'] = $cv_id;
   }
   if (isset($cv_name)) {
-    $identifiers['cv'] = array(
+    $identifiers['cv_id'] = array(
       'name' => $cv_name
     );
   }

+ 140 - 9
tripal_stock/api/tripal_stock.DEPRECATED.inc

@@ -23,7 +23,7 @@ function tripal_stock_get_stock_by_nid($nid) {
     )
   );
 
-  return FALSE;
+  return chado_get_stock(array('nid' => $nid));
 }
 
 /**
@@ -45,7 +45,7 @@ function tripal_stock_get_stock_by_stock_id($stock_id) {
     )
   );
 
-  return FALSE;
+  return chado_get_stock(array('stock_id' => $stock_id));
 }
 
 /**
@@ -60,14 +60,23 @@ function tripal_stock_get_all_stocks() {
   tripal_report_error(
     'tripal_api',
     TRIPAL_NOTICE,
-    "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
+    "DEPRECATED: %old_function has been completely deprecated. There are often so many
+     stocks in a chado database that it is unlikely a user really wants all of them.",
     array(
-      '%old_function'=>'tripal_stock_get_all_stocks',
-      '%new_function' => 'chado_get_multiple_stocks'
+      '%old_function'=>'tripal_stock_get_all_stocks'
     )
   );
 
-  return FALSE;
+  $sql = "SELECT stock_id, nid from {chado_stock}";
+  $resource = db_query($sql);
+  $stocks = array();
+  while ($r = $resource->fetchObject()) {
+    $node = node_load($r->nid);
+    if ($node) {
+      $stocks[$r->stock_id] = $node;
+    }
+  }
+  return $stocks;
 }
 
 /**
@@ -89,7 +98,7 @@ function tripal_stock_get_stocks($values) {
     )
   );
 
-  return FALSE;
+  return chado_get_multiple_stocks($values);
 }
 
 /**
@@ -111,7 +120,8 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
     )
   );
 
-  return FALSE;
+  $stock_values['property'] = $stockprop_values;
+  return chado_get_multiple_stocks($stock_values);
 }
 
 /**
@@ -119,6 +129,18 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
  * This function has been replaced by chado_get_stock().
  *
+ * Return all stocks with a given name identifier
+ *  which might match stock.name, stock.uniquename, dbxref.accession,
+ *  stockprop.value where stockprop.type='synonym'
+ *
+ * @param $name
+ *   The name identfier to be used
+ * @param $organism_id
+ *   The stock.organism_id of the stock to be selected
+ *
+ * @return
+ *   An array of stock node objects
+ *
  * @see chado_get_stock().
  */
 function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
@@ -133,5 +155,114 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
     )
   );
 
-  return FALSE;
+  $stock_ids = array();
+
+  $options = array(
+    'case_insensitive_columns' => array('name', 'uniquename', 'accession', 'value')
+  );
+
+  // where name_identifier = stock.name-------------------------------
+  $current_stocks = chado_select_record('stock', array('stock_id'),
+    array(
+      'name' => $name,
+      'organism_id' => $organism_id,
+    ),
+    array(
+      'case_insensitive_columns' => array('name'),
+    )
+  );
+  if (!empty($current_stocks)) {
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
+  }
+
+  // where name_identifier = stock.uniquename-------------------------------
+  $current_stocks = chado_select_record('stock', array('stock_id'),
+    array(
+      'uniquename' => $name,
+      'organism_id' => $organism_id,
+    ),
+    array(
+      'case_insensitive_columns' => array('uniquename'),
+    )
+  );
+  if (!empty($current_stocks)) {
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
+  }
+
+  // where name_identifier = dbxref.accession-------------------------------
+  // linked to stock through stock.dbxref
+  $current_stocks = chado_select_record('stock', array('stock_id'),
+    array(
+      'dbxref_id' => array(
+        'accession' => $name,
+      ),
+      'organism_id' => $organism_id,
+    ),
+    array(
+      'case_insensitive_columns' => array('accession'),
+    )
+  );
+  if (!empty($current_stocks)) {
+    foreach ($current_stocks as $c) {
+    $stock_ids[] = $c->stock_id; }
+  }
+
+  // linked to stock through stock_dbxref?
+  $current_stocks = chado_select_record('stock_dbxref', array('stock_id'),
+    array(
+      'dbxref_id' => array(
+        'accession' => $name,
+      ),
+      'stock_id' => array(
+        'organism_id' => $organism_id,
+      ),
+    ),
+    array(
+      'case_insensitive_columns' => array('accession'),
+    )
+  );
+  if (!empty($current_stocks)) {
+    foreach ($current_stocks as $c) {
+      $stock_ids[] = $c->stock_id;
+    }
+  }
+
+  // where name_identifier = stockprop.value-------------------------------
+  // where type='synonym'
+  $current_stocks = chado_select_record('stockprop', array('stock_id'),
+    array(
+      'stock_id' => array(
+        'organism_id' => $organism_id,
+      ),
+      'type_id' => array(
+        'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
+        'name' => 'synonym',
+      ),
+      'value' => $name,
+    ),
+    array(
+      'case_insensitive_columns' => array('value'),
+    )
+  );
+  if (!empty($current_stocks)) {
+    foreach ($current_stocks as $c) {
+      $stock_ids[] = $c->stock_id;
+    }
+  }
+
+  // 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);
+    if ($node) {
+      $stocks[] = $node;
+    }
+  }
+
+  return $stocks;
 }

+ 147 - 270
tripal_stock/api/tripal_stock.api.inc

@@ -13,310 +13,187 @@
  */
 
 /**
- * Purpose: Return a given stock node using the nid
- *
- * @param $nid
- *   The node ID of the stock you want to load
+ * Retrieves a chado stock object
+ *
+ * @param $identifier
+ *   An array with the key stating what the identifier is. Supported keys (only one of the
+ *   following unique keys is required):
+ *    - stock_id: the chado stock.stock_id primary key
+ *    - nid: the drupal nid of the stock
+ *   There are also some specially handled keys. They are:
+ *    - property: An array/object describing the property to select records for. It
+ *      should at least have either a type_name (if unique across cvs) or type_id. Other
+ *      supported keys include: cv_id/cv_name (of the type), value and rank
+ * @param $options
+ *   An array of options. Supported keys include:
+ *     - Any keys supported by chado_generate_var(). See that function definition for
+ *       additional details.
+ *
+ * NOTE: the $identifier parameter can really be any array similar to $values passed into
+ *   chado_select_record(). It should fully specify the stock record to be returned.
  *
  * @return
- *   stock node with the passed in node ID
+ *   If unique values were passed in as an identifier then an object describing the stock
+ *   will be returned (will be a chado variable from chado_generate_var()). Otherwise,
+ *   FALSE will be returned.
  *
  * @ingroup tripal_stock_api
  */
-function tripal_stock_get_stock_by_nid($nid) {
-
-  return node_load($nid);
-
-}
-
-/**
- * Purpose: Return a given stock object using the stock id
- *
- * @return
- *   Stock object created by node load
- *
- * @ingroup tripal_stock_api
- */
-function tripal_stock_get_stock_by_stock_id($stock_id) {
-
-  $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
-  $r = db_query($sql, array(':stock_id' => $stock_id))->fetchObject();
-  if (!empty($r->nid)) {
-    return node_load($r->nid);
+function chado_get_stock($identifiers, $options = array()) {
+
+  // Error Checking of parameters
+  if (!is_array($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: The identifier passed in is expected to be an array with the key
+        matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
-  else {
-    tripal_report_error('tripal_stock', TRIPAL_WARNING, 'tripal_stock_get_stock_by_stock_id(!stock_id): no stock with that stock_id is sync\'d with drupal', array('!stock_id' => $stock_id));
+  elseif (empty($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
+        is expected to be an array with the key matching a column name in the stock table
+        (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
 
-  return 0;
-
-}
-
-/**
- * Returns all stocks currently sync'd with drupal
- *
- * @return
- *   An array of node objects keyed by stock_id
- *
- * @ingroup tripal_stock_api
- */
-function tripal_stock_get_all_stocks() {
-  $sql = "SELECT stock_id, nid from {chado_stock}";
-  $resource = db_query($sql);
-  $stocks = array();
-  while ($r = $resource->fetchObject()) {
-    $node = node_load($r->nid);
-    if ($node) {
-      $stocks[$r->stock_id] = $node;
-    }
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $stock = chado_get_record_with_property('stock', $property, $identifiers, $options);
   }
-  return $stocks;
-}
 
-/**
- * Purpose: Return all stocks that match a given criteria
- *
- * @param $values
- *   An associative array containing the values for filtering the results.
- *
- * @return
- *   An array of matching stock objects (produced using node_load)
- *   matching the given criteria
- *
- * Example usage:
- * @code
- *   $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);
- * @endcode
- * 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.
- *
- * @ingroup tripal_stock_api
- */
-function tripal_stock_get_stocks($values) {
-
-  $stock_ids = chado_select_record('stock', array('stock_id'), $values);
-
-  // Change from stock_ids to nodes-----------------------------------
-  $stock_ids = array_filter($stock_ids);
-  $stock_ids = array_unique($stock_ids);
+  // Else we have a simple case and we can just use chado_generate_var to get the stock
+  else {
 
-  $stocks = array();
-  foreach ($stock_ids as $stock_id) {
-    $node = tripal_stock_get_stock_by_stock_id($stock_id->stock_id);
-    if ($node) {
-      $stocks[] = $node;
-    }
+    // Try to get the stock
+    $stock = chado_generate_var(
+      'stock',
+      $identifiers,
+      $options
+    );
   }
 
-  return $stocks;
-}
-
-/**
- * Retrieve stocks based on associated stock properties
- *
- * @param $stockprop_values
- *   An array of column_name => value where column_name is any column in the stockprop table
- *   and value is the value you want that column to be. This is used as a tripal_core_chado_select
- *   values array so nesting is allowed.
- * @param $stock_values
- *   An array of column_name => value where column_name is any column in the stock table
- *   and value is the value you want that column to be. This is used as a tripal_core_chado_select
- *   values array so nesting is allowed.
- *
- * @return
- *   An array of stock node objects
- *
- * Example usage:
- * @code
- *   $stockprop_values =  array(
- *     'value' => 'CDC Redberry',
- *     'type_id' => array (
- *         'cv_id' => array (
- *            'name' => 'stock_properties',
- *         ),
- *         'name' => 'synonym',
- *         'is_obsolete' => 0
- *      ),
- *   );
- *   $stock_values =  array(
- *     'organism_id' => array(
- *         'genus' => 'Lens',
- *         'species' => 'culinaris',
- *      ),
- *   );
- *   $result = tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values);
- * @endcode
- * The above code selects all Lens culinaris stocks with the synonym (stock property) CDC Redberry.
- * The nodes for each stock selected are loaded and returned in an array.
- *
- * @ingroup tripal_stock_api
- */
-function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values) {
-
-  //add stock values to stockprop values
-  if (!empty($stock_values)) {
-    $stockprop_values['stock_id'] = $stock_values;
+  // Ensure the stock is singular. If it's an array then it is not singular
+  if (is_array($stock)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: The identifiers you passed in were not unique. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
 
-  //get stock_ids from stockprop table
-  $stock_ids = chado_select_record('stockprop', array('stock_id'), $stockprop_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;
-    }
+  // Report an error if $stock is FALSE since then chado_generate_var has failed
+  elseif ($stock === FALSE) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
+        you passed in. You should check that your identifiers are correct, as well as, look
+        for a chado_generate_var error for additional clues. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
 
-  return $stocks;
+  // Else, as far we know, everything is fine so give them their stock :)
+  else {
+    return $stock;
+  }
 }
 
 /**
- * Return all stocks with a given name identifier
- *  which might match stock.name, stock.uniquename, dbxref.accession,
- *  stockprop.value where stockprop.type='synonym'
+ * Retrieves a chado stock object
  *
- * @param $name
- *   The name identfier to be used
- * @param $organism_id
- *   The stock.organism_id of the stock to be selected
+ * @param $identifier
+ *   An array with the key stating what the identifier is. Supported keys include any
+ *   field in the stock table. See the chado_select_record() $values parameter for
+ *   additional details including an example.
+ * @param $options
+ *   An array of options. Supported keys include:
+ *     - Any keys supported by chado_generate_var(). See that function definition for
+ *       additional details.
  *
  * @return
- *   An array of stock node objects
+ *   An array of stock objects matching the criteria.
  *
  * @ingroup tripal_stock_api
  */
-function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
-  $stock_ids = array();
-
-  $options = array(
-    'case_insensitive_columns' => array('name', 'uniquename', 'accession', 'value')
-  );
-
-  // where name_identifier = stock.name-------------------------------
-  $current_stocks = chado_select_record('stock', array('stock_id'),
-    array(
-      'name' => $name,
-      'organism_id' => $organism_id,
-    ),
-    array(
-      'case_insensitive_columns' => array('name'),
-    )
-  );
-  if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) {
-    $stock_ids[] = $c->stock_id; }
+function chado_get_multiple_stocks($identifiers, $options = array()) {
+
+  // Error Checking of parameters
+  if (!is_array($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: The identifier passed in is expected to be an array with the key
+        matching a column name in the stock table (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
-
-  // where name_identifier = stock.uniquename-------------------------------
-  $current_stocks = chado_select_record('stock', array('stock_id'),
-    array(
-      'uniquename' => $name,
-      'organism_id' => $organism_id,
-    ),
-    array(
-      'case_insensitive_columns' => array('uniquename'),
-    )
-  );
-  if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) {
-    $stock_ids[] = $c->stock_id; }
+  elseif (empty($identifiers)) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: You did not pass in anything to identify the stock you want. The identifier
+        is expected to be an array with the key matching a column name in the stock table
+        (ie: stock_id or name). You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
 
-  // where name_identifier = dbxref.accession-------------------------------
-  // linked to stock through stock.dbxref
-  $current_stocks = chado_select_record('stock', array('stock_id'),
-    array(
-      'dbxref_id' => array(
-        'accession' => $name,
-      ),
-      'organism_id' => $organism_id,
-    ),
-    array(
-      'case_insensitive_columns' => array('accession'),
-    )
-  );
-  if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) {
-    $stock_ids[] = $c->stock_id; }
+  // If one of the identifiers is property then use chado_get_record_with_property()
+  if (isset($identifiers['property'])) {
+    $property = $identifiers['property'];
+    unset($identifiers['property']);
+    $stock = chado_get_record_with_property('stock', $property, $identifiers, $options);
   }
 
-  // linked to stock through stock_dbxref?
-  $current_stocks = chado_select_record('stock_dbxref', array('stock_id'),
-    array(
-      'dbxref_id' => array(
-        'accession' => $name,
-      ),
-      'stock_id' => array(
-        'organism_id' => $organism_id,
-      ),
-    ),
-    array(
-      'case_insensitive_columns' => array('accession'),
-    )
-  );
-  if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) {
-      $stock_ids[] = $c->stock_id;
-    }
-  }
+  // Else we have a simple case and we can just use chado_generate_var to get the stock
+  else {
 
-  // where name_identifier = stockprop.value-------------------------------
-  // where type='synonym'
-  $current_stocks = chado_select_record('stockprop', array('stock_id'),
-    array(
-      'stock_id' => array(
-        'organism_id' => $organism_id,
-      ),
-      'type_id' => array(
-        'cv_id' => variable_get('chado_stock_prop_types_cv', 'null'),
-        'name' => 'synonym',
-      ),
-      'value' => $name,
-    ),
-    array(
-      'case_insensitive_columns' => array('value'),
-    )
-  );
-  if (!empty($current_stocks)) {
-    foreach ($current_stocks as $c) {
-      $stock_ids[] = $c->stock_id;
-    }
+    // Try to get the stock
+    $stock = chado_generate_var(
+      'stock',
+      $identifiers,
+      $options
+    );
   }
 
-  // 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);
-    if ($node) {
-      $stocks[] = $node;
-    }
+  // Report an error if $stock is FALSE since then chado_generate_var has failed
+  if ($stock === FALSE) {
+    tripal_report_error(
+      'tripal_stock_api',
+      TRIPAL_ERROR,
+      "chado_get_stock: chado_generate_var() failed to return a stock based on the identifiers
+        you passed in. You should check that your identifiers are correct, as well as, look
+        for a chado_generate_var error for additional clues. You passed in %identifier.",
+      array(
+        '%identifier'=> print_r($identifiers, TRUE)
+      )
+    );
   }
 
-  return $stocks;
+  // Else, as far we know, everything is fine so give them their stock :)
+  else {
+    return $stock;
+  }
 }

+ 21 - 31
tripal_stock/tripal_stock.module

@@ -5,7 +5,7 @@
  */
 
 require_once 'api/tripal_stock.api.inc';
-//require_once 'api/tripal_stock.DEPRECATED.inc';
+require_once 'api/tripal_stock.DEPRECATED.inc';
 
 require_once 'theme/tripal_stock.theme.inc';
 
@@ -178,35 +178,28 @@ function tripal_stock_permission() {
  * @ingroup tripal_stock
  */
 function chado_stock_node_access($node, $op, $account) {
-  $node_type = $node;
-  if (is_object($node)) {
-    $node_type = $node->type;
-  }
-  
-  if($node_type == 'chado_stock') {
-    if ($op == 'create') {
-      if (!user_access('create chado_stock', $account)) {
-        return NODE_ACCESS_DENY;
-      }
-      return NODE_ACCESS_ALLOW;
+  if ($op == 'create') {
+    if (!user_access('create chado_stock content', $account)) {
+      return FALSE;
     }
-    if ($op == 'update') {
-      if (!user_access('edit chado_stock', $account)) {
-        return NODE_ACCESS_DENY;
-      }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_stock content', $account)) {
+      return FALSE;
     }
-    if ($op == 'delete') {
-      if (!user_access('delete chado_stock', $account)) {
-        return NODE_ACCESS_DENY;
-      }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_stock content', $account)) {
+      return FALSE;
     }
-    if ($op == 'view') {
-      if (!user_access('access chado_stock', $account)) {
-        return NODE_ACCESS_DENY;
-      }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_stock content', $account)) {
+      return FALSE;
     }
-    return NODE_ACCESS_IGNORE;
   }
+  return NULL;
 }
 
 /**
@@ -352,7 +345,7 @@ function tripal_stock_block_info() {
   $blocks['properties']['info'] = t('Tripal Stock Properties');
   $blocks['properties']['cache'] = 'BLOCK_NO_CACHE';
 
-  $blocks['references']['info'] = t('Tripal Stock Cross References');
+  $blocks['references']['info'] = t('Tripal Stock References');
   $blocks['references']['cache'] = 'BLOCK_NO_CACHE';
 
   $blocks['relationships_as_object']['info'] = t('Tripal Stock Relationships');
@@ -403,7 +396,7 @@ function tripal_stock_block_view($delta = '') {
         break;
 
       case 'references':
-        $block['subject'] = t('Cross References');
+        $block['subject'] = t('References');
         $block['content'] = theme('tripal_stock_references', $node);
         break;
 
@@ -528,11 +521,8 @@ function tripal_stock_match_stocks_page($id) {
  * @ingroup tripal_stock
  */
 function tripal_stock_form_alter(&$form, &$form_state, $form_id) {
+  // turn of preview button for insert/updates
   if ($form_id == "chado_stock_node_form") {
-    // turn of preview button for insert/updates
     $form['actions']['preview']['#access'] = FALSE;
-    
-    //remove the body field
-    unset($form['body']);
   }
 }