|
@@ -1,5 +1,4 @@
|
|
|
<?php
|
|
|
-// $Id$
|
|
|
|
|
|
/**
|
|
|
* @file
|
|
@@ -11,13 +10,13 @@
|
|
|
* @{
|
|
|
* 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
|
|
|
+ * 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)
|
|
|
* @}
|
|
|
* @ingroup tripal_modules
|
|
@@ -51,7 +50,7 @@ function tripal_stock_menu() {
|
|
|
'access arguments' => array('administer site configuration'),
|
|
|
'type' => MENU_NORMAL_ITEM
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
$items['admin/tripal/tripal_stock/configuration'] = array(
|
|
|
'title' => t('Configuration'),
|
|
|
'description' => t('Settings for Chado Stocks'),
|
|
@@ -60,39 +59,39 @@ function tripal_stock_menu() {
|
|
|
'access arguments' => array('administer site configuration'),
|
|
|
'type' => MENU_NORMAL_ITEM
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
//Displaying stocks----------------------------
|
|
|
$items['stocks'] = array(
|
|
|
- 'menu_name' => ('primary-links'),
|
|
|
+ 'menu_name' => ('primary-links'),
|
|
|
'title' => t('Stocks'),
|
|
|
'page callback' => 'tripal_stock_show_stocks',
|
|
|
'access arguments' => array('access chado_stock content'),
|
|
|
- 'type' => MENU_NORMAL_ITEM,
|
|
|
+ 'type' => MENU_NORMAL_ITEM,
|
|
|
);
|
|
|
|
|
|
// Adding Secondary Properties-----------------
|
|
|
- $items['node/%cs_node/properties'] = array(
|
|
|
- 'title' => t('Add Properties & Synonyms'),
|
|
|
+ $items['node/%cs_node/properties'] = array(
|
|
|
+ 'title' => t('Add Properties & Synonyms'),
|
|
|
'description' => t('Settings for Chado Stocks'),
|
|
|
- 'page callback' => 'tripal_stock_add_ALL_property_page',
|
|
|
- 'page arguments' => array(1),
|
|
|
+ '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' => t('Add Database References'),
|
|
|
- 'description' => t('Settings for Chado Stocks'),
|
|
|
- 'page callback' => 'tripal_stock_add_ALL_dbreferences_page',
|
|
|
+ $items['node/%cs_node/db_references'] = array(
|
|
|
+ 'title' => t('Add Database References'),
|
|
|
+ 'description' => t('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' => t('Add Relationships'),
|
|
|
- 'description' => t('Settings for Chado Stocks'),
|
|
|
- 'page callback' => 'tripal_stock_add_ALL_relationships_page',
|
|
|
+ $items['node/%cs_node/relationships'] = array(
|
|
|
+ 'title' => t('Add Relationships'),
|
|
|
+ 'description' => t('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
|
|
@@ -111,7 +110,7 @@ function tripal_stock_menu() {
|
|
|
|
|
|
$items['node/%cs_node/edit_relationships'] = array(
|
|
|
'title' => t('Edit Relationships'),
|
|
|
- 'description' => t('Settings for Chado Stocks'),
|
|
|
+ 'description' => t('Settings for Chado Stocks'),
|
|
|
'page callback' => 'tripal_stock_edit_ALL_relationships_page',
|
|
|
'page arguments' => array(1),
|
|
|
'access arguments' => array('edit chado_stock content'),
|
|
@@ -134,9 +133,9 @@ function tripal_stock_menu() {
|
|
|
/**
|
|
|
* Implements Menu wildcard_load hook
|
|
|
*
|
|
|
- * Purpose: Allows the node ID of a chado stock to be dynamically
|
|
|
+ * 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
|
|
|
+ * and supplied to the page as an arguement. This is an example
|
|
|
* of dynamic argument replacement using wildcards in the path.
|
|
|
*
|
|
|
* @param $nid
|
|
@@ -194,7 +193,7 @@ function tripal_stock_perm() {
|
|
|
*/
|
|
|
function chado_stock_access($op, $node, $account) {
|
|
|
if ($op == 'create') {
|
|
|
- if(!user_access('create chado_stock content', $account)){
|
|
|
+ if (!user_access('create chado_stock content', $account)) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
@@ -227,7 +226,7 @@ function chado_stock_access($op, $node, $account) {
|
|
|
* An array with fields important for views integration
|
|
|
*
|
|
|
* @ingroup tripal_stock
|
|
|
- */
|
|
|
+ */
|
|
|
function tripal_stock_views_api() {
|
|
|
return array(
|
|
|
'api' => 2.0,
|
|
@@ -243,11 +242,11 @@ function tripal_stock_views_api() {
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
function tripal_stock_theme() {
|
|
|
- return array(
|
|
|
- 'tripal_stock_stock_table' => array (
|
|
|
- 'arguments' => array('stocks'),
|
|
|
- ),
|
|
|
- // Property edit forms--------------------------
|
|
|
+ return array(
|
|
|
+ 'tripal_stock_stock_table' => array(
|
|
|
+ 'arguments' => array('stocks'),
|
|
|
+ ),
|
|
|
+ // Property edit forms--------------------------
|
|
|
'tripal_stock_edit_ALL_properties_form' => array(
|
|
|
'arguments' => array('form'),
|
|
|
'function' => 'theme_tripal_stock_edit_ALL_properties_form',
|
|
@@ -261,27 +260,27 @@ function tripal_stock_theme() {
|
|
|
'function' => 'theme_tripal_stock_edit_ALL_relationships_form',
|
|
|
),
|
|
|
// Block Templates------------------------------
|
|
|
- 'tripal_stock_base' => array (
|
|
|
- 'arguments' => array('node'=> null),
|
|
|
+ 'tripal_stock_base' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_stock_base',
|
|
|
),
|
|
|
- 'tripal_stock_properties' => array (
|
|
|
- 'arguments' => array('node'=> null),
|
|
|
+ 'tripal_stock_properties' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_stock_properties',
|
|
|
),
|
|
|
- 'tripal_stock_references' => array (
|
|
|
- 'arguments' => array('node'=> null),
|
|
|
+ 'tripal_stock_references' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_stock_references',
|
|
|
),
|
|
|
- 'tripal_stock_relationships' => array (
|
|
|
- 'arguments' => array('node'=> null),
|
|
|
+ 'tripal_stock_relationships' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_stock_relationships',
|
|
|
- ),
|
|
|
- 'tripal_stock_synonyms' => array (
|
|
|
- 'arguments' => array('node'=> null),
|
|
|
+ ),
|
|
|
+ 'tripal_stock_synonyms' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_stock_synonyms',
|
|
|
),
|
|
|
- );
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -296,17 +295,18 @@ function tripal_stock_theme() {
|
|
|
*
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-function tripal_stock_show_stocks () {
|
|
|
- $sql = "SELECT COUNT(stock_id) FROM {chado_stock}";
|
|
|
+function tripal_stock_show_stocks() {
|
|
|
+ $sql = "SELECT COUNT(stock_id) FROM {chado_stock}";
|
|
|
$no_stocks = db_result(db_query($sql));
|
|
|
- if($no_stocks != 0) {
|
|
|
+ if ($no_stocks != 0) {
|
|
|
$stocks = tripal_stock_get_all_stocks();
|
|
|
- if($no_stocks != count($stocks)) {
|
|
|
+ if ($no_stocks != count($stocks)) {
|
|
|
drupal_set_message("Synchronization needed.");
|
|
|
}
|
|
|
- return theme('tripal_stock_stock_table',&$stocks);
|
|
|
- } else {
|
|
|
- return t("No Stocks exists. Please contact administrators to ".
|
|
|
+ return theme('tripal_stock_stock_table', &$stocks);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return t("No Stocks exists. Please contact administrators to " .
|
|
|
"synchronize stocks.");
|
|
|
}
|
|
|
}
|
|
@@ -322,11 +322,11 @@ function tripal_stock_show_stocks () {
|
|
|
*
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-function theme_tripal_stock_stock_table (&$stocks) {
|
|
|
+function theme_tripal_stock_stock_table(&$stocks) {
|
|
|
|
|
|
- // cycle through the stocks and build the stocks page
|
|
|
- $output = "<div id=\"stocks\">";
|
|
|
- $output .= '<table>';
|
|
|
+ // cycle through the stocks and build the stocks page
|
|
|
+ $output = "<div id=\"stocks\">";
|
|
|
+ $output .= '<table>';
|
|
|
$output .= "<tr>";
|
|
|
$output .= "<th>Name</th>";
|
|
|
$output .= "<th>Type</th>";
|
|
@@ -334,16 +334,16 @@ function theme_tripal_stock_stock_table (&$stocks) {
|
|
|
$output .= "<th>Description</th>";
|
|
|
$output .= "</tr>";
|
|
|
|
|
|
- foreach($stocks as $node){
|
|
|
- $output .= "<tr>";
|
|
|
- $output .= "<td>".l($node->stock->name, "node/".$node->nid)."</td>";
|
|
|
- $output .= "<td>".$node->stock->type_id->name."</td>";
|
|
|
- $output .= "<td nowrap>".$node->stock->organism_id->common_name."</td>";
|
|
|
- $output .= "<td>".$node->stock->description."</td>";
|
|
|
- $output .= "</tr>";
|
|
|
- }
|
|
|
- $output .= "</table>";
|
|
|
- $output .= "</div>";
|
|
|
+ foreach ($stocks as $node) {
|
|
|
+ $output .= "<tr>";
|
|
|
+ $output .= "<td>" . l($node->stock->name, "node/" . $node->nid) . "</td>";
|
|
|
+ $output .= "<td>" . $node->stock->type_id->name . "</td>";
|
|
|
+ $output .= "<td nowrap>" . $node->stock->organism_id->common_name . "</td>";
|
|
|
+ $output .= "<td>" . $node->stock->description . "</td>";
|
|
|
+ $output .= "</tr>";
|
|
|
+ }
|
|
|
+ $output .= "</table>";
|
|
|
+ $output .= "</div>";
|
|
|
|
|
|
return $output;
|
|
|
}
|
|
@@ -386,9 +386,9 @@ function chado_stock_load($node) {
|
|
|
"SELECT stock_id as stock_id FROM {chado_stock} WHERE vid=%d",
|
|
|
$node->vid
|
|
|
));
|
|
|
-
|
|
|
+
|
|
|
// Get stock content and add to node
|
|
|
- $stock = tripal_core_generate_chado_var('stock', array('stock_id'=>$map->stock_id));
|
|
|
+ $stock = tripal_core_generate_chado_var('stock', array('stock_id' => $map->stock_id));
|
|
|
//
|
|
|
// move expandable fields downwards
|
|
|
$node->expandable_fields = $stock->expandable_fields;
|
|
@@ -398,7 +398,7 @@ function chado_stock_load($node) {
|
|
|
$node->expandable_nodes = $stock->expandable_nodes;
|
|
|
unset($stock->expandable_nodes);
|
|
|
$node->stock = $stock;
|
|
|
-
|
|
|
+
|
|
|
return $node;
|
|
|
}
|
|
|
|
|
@@ -407,12 +407,12 @@ function chado_stock_load($node) {
|
|
|
* Implements hook_form(): Creates the main Add/Edit/Delete Form for chado stocks
|
|
|
*
|
|
|
* Parts to be added by this form
|
|
|
- * name,
|
|
|
- * uniquename,
|
|
|
- * description,
|
|
|
+ * 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)
|
|
|
+ * main_db_reference => accession, version, description, db_name(select from dropdown)
|
|
|
*
|
|
|
* @param $node
|
|
|
* An empty node object on insert OR the current stock node object on update
|
|
@@ -448,13 +448,13 @@ function chado_stock_form($node, $form_state) {
|
|
|
// Will then do default redirect (to new node) on submit
|
|
|
$form['simulate_multipart'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
- '#attributes'=>array('style'=>"display:none"),
|
|
|
+ '#attributes' => array('style' => "display:none"),
|
|
|
'#default_value' => TRUE
|
|
|
);
|
|
|
|
|
|
if (!isset($node->stock->uniquename)) {
|
|
|
- $form['progress'] = array(
|
|
|
- '#type' => 'item',
|
|
|
+ $form['progress'] = array(
|
|
|
+ '#type' => 'item',
|
|
|
'#value' => tripal_stock_add_chado_properties_progress('main')
|
|
|
);
|
|
|
}
|
|
@@ -468,14 +468,14 @@ function chado_stock_form($node, $form_state) {
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Name'),
|
|
|
'#default_value' => $node->stock->name,
|
|
|
- '#required' => TRUE
|
|
|
+ '#required' => TRUE
|
|
|
);
|
|
|
|
|
|
$form['names']['uniquename'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Unique Name'),
|
|
|
'#default_value' => $node->stock->uniquename,
|
|
|
- '#required' => TRUE
|
|
|
+ '#required' => TRUE
|
|
|
);
|
|
|
|
|
|
$form['names']['stock_id'] = array(
|
|
@@ -485,29 +485,33 @@ function chado_stock_form($node, $form_state) {
|
|
|
|
|
|
$form['details'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
- '#title' => t('Stock Details')
|
|
|
+ '#title' => t('Stock Details')
|
|
|
);
|
|
|
|
|
|
- $type_options = tripal_cv_get_cvterm_options( variable_get('chado_stock_types_cv', 'null') );
|
|
|
+ $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; }
|
|
|
+ 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,
|
|
|
+ '#required' => TRUE,
|
|
|
);
|
|
|
|
|
|
$stock_oganism_options = tripal_organism_get_organism_options();
|
|
|
$stock_oganism_options[0] = 'Select An Organism';
|
|
|
- if ($node->nid == '') { $organism_default = 0; } else { $organism_default = $node->stock->organism_id->organism_id; }
|
|
|
+ if ($node->nid == '') {
|
|
|
+ $organism_default = 0; }
|
|
|
+ else { $organism_default = $node->stock->organism_id->organism_id; }
|
|
|
$form['details']['organism_id'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => t('Source Organism for stock'),
|
|
|
'#default_value' => $organism_default,
|
|
|
'#options' => $stock_oganism_options,
|
|
|
- '#required' => TRUE
|
|
|
+ '#required' => TRUE
|
|
|
);
|
|
|
|
|
|
|
|
@@ -538,7 +542,9 @@ function chado_stock_form($node, $form_state) {
|
|
|
|
|
|
$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; }
|
|
|
+ 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'),
|
|
@@ -561,31 +567,33 @@ function chado_stock_form($node, $form_state) {
|
|
|
*/
|
|
|
function chado_stock_validate($node, &$form) {
|
|
|
|
|
|
- $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'";
|
|
|
-
|
|
|
+ $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)) {
|
|
|
- $previous_db = tripal_db_set_active('chado');
|
|
|
- $chado_row = db_fetch_object(db_query("SELECT * FROM stock WHERE uniquename='".$node->uniquename."'"));
|
|
|
- tripal_db_set_active($previous_db);
|
|
|
- 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.");
|
|
|
- }
|
|
|
- }
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
+ $chado_row = db_fetch_object(db_query("SELECT * FROM {stock} WHERE uniquename='" . $node->uniquename . "'"));
|
|
|
+ tripal_db_set_active($previous_db);
|
|
|
+ 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 {
|
|
|
- $previous_db = tripal_db_set_active('chado');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
$num_rows = db_fetch_object(db_query($int_in_chado_sql, 'cvterm', 'cvterm_id', $node->type_id));
|
|
|
tripal_db_set_active($previous_db);
|
|
|
if ( $num_rows->count != 1) {
|
|
@@ -595,8 +603,9 @@ function chado_stock_validate($node, &$form) {
|
|
|
// 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 {
|
|
|
- $previous_db = tripal_db_set_active('chado');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
$num_rows = db_fetch_object(db_query($int_in_chado_sql, 'organism', 'organism_id', $node->organism_id));
|
|
|
tripal_db_set_active($previous_db);
|
|
|
if ( $num_rows->count != 1 ) {
|
|
@@ -604,12 +613,13 @@ function chado_stock_validate($node, &$form) {
|
|
|
}
|
|
|
|
|
|
// Check if Accession also database
|
|
|
- if ($node->accession != '') {
|
|
|
+ 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 {
|
|
|
+ }
|
|
|
+ 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.');
|
|
@@ -618,7 +628,7 @@ function chado_stock_validate($node, &$form) {
|
|
|
|
|
|
// Check database is valid db_id in chado ( $form['values']['database_reference']['database'] )
|
|
|
if ( $node->database > 0) {
|
|
|
- $previous_db = tripal_db_set_active('chado');
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
$num_rows = db_fetch_object(db_query($int_in_chado_sql, 'db', 'db_id', $node->database));
|
|
|
tripal_db_set_active($previous_db);
|
|
|
if ($num_rows->count != 1) {
|
|
@@ -639,51 +649,52 @@ function chado_stock_validate($node, &$form) {
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
function chado_stock_insert($node) {
|
|
|
-
|
|
|
+
|
|
|
//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
|
|
|
- );
|
|
|
- }
|
|
|
+ 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
|
|
|
+
|
|
|
+ // create dbxref
|
|
|
if ( !empty($node->accession) ) {
|
|
|
- if ( !empty($node->database) ) {
|
|
|
+ if ( !empty($node->database) ) {
|
|
|
$values = array(
|
|
|
- 'db_id' => $node->database,
|
|
|
- 'accession' => $node->accession,
|
|
|
+ '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('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; }
|
|
|
- }
|
|
|
+ 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('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(
|
|
|
+ if ($dbxref_status) {
|
|
|
+ $values = array(
|
|
|
'dbxref_id' => array(
|
|
|
- 'db_id' => $node->database,
|
|
|
- 'accession' => $node->accession
|
|
|
+ 'db_id' => $node->database,
|
|
|
+ 'accession' => $node->accession
|
|
|
),
|
|
|
'organism_id' => $node->organism_id,
|
|
|
'name' => $node->title,
|
|
@@ -692,8 +703,9 @@ function chado_stock_insert($node) {
|
|
|
'type_id' => $node->type_id
|
|
|
);
|
|
|
$stock_status = tripal_core_chado_insert('stock', $values);
|
|
|
- } else {
|
|
|
- $values = array(
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $values = array(
|
|
|
'organism_id' => $node->organism_id,
|
|
|
'name' => $node->title,
|
|
|
'uniquename' => $node->uniquename,
|
|
@@ -705,39 +717,41 @@ function chado_stock_insert($node) {
|
|
|
|
|
|
// 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('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
|
|
|
+ $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('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('Error during stock creation.', 'error');
|
|
|
- watchdog('tripal_stock',
|
|
|
- 'Insert Stock: Unable to create stock where values:%values',
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_message('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
|
|
|
);
|
|
@@ -763,70 +777,73 @@ function chado_stock_update($node) {
|
|
|
|
|
|
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('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
|
|
|
- );
|
|
|
- }
|
|
|
+ }
|
|
|
+ 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('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(
|
|
|
+ $update_values = array(
|
|
|
'organism_id' => $node->organism_id,
|
|
|
'name' => $node->title,
|
|
|
'uniquename' => $node->uniquename,
|
|
@@ -834,25 +851,25 @@ function chado_stock_update($node) {
|
|
|
'type_id' => $node->type_id,
|
|
|
);
|
|
|
if ($dbxref_status) {
|
|
|
- $update_values['dbxref_id'] = array(
|
|
|
- 'db_id' => $node->database,
|
|
|
- 'accession' => $node->accession
|
|
|
- );
|
|
|
+ $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
|
|
|
+ 'stock',
|
|
|
+ array('stock_id' => $node->stock_id),
|
|
|
+ $update_values
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
if (!$status) {
|
|
|
- drupal_set_message('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
|
|
|
- );
|
|
|
+ drupal_set_message('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
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -876,11 +893,11 @@ function chado_stock_delete($node) {
|
|
|
// Set stock in chado: is_obsolete = TRUE
|
|
|
$previous_db = tripal_db_set_active('chado');
|
|
|
db_query(
|
|
|
- "DELETE FROM stock WHERE stock_id=%d",
|
|
|
+ "DELETE FROM {stock} WHERE stock_id=%d",
|
|
|
$node->stock->stock_id
|
|
|
);
|
|
|
tripal_db_set_active($previous_db);
|
|
|
-
|
|
|
+
|
|
|
//remove drupal node and all revisions
|
|
|
db_query(
|
|
|
"DELETE FROM {chado_stock} WHERE nid=%d",
|
|
@@ -892,7 +909,7 @@ function chado_stock_delete($node) {
|
|
|
* Purpose: Implement Blocks relating to stock content
|
|
|
*
|
|
|
* @param $op
|
|
|
- * What kind of information to retrieve about the block or blocks.
|
|
|
+ * What kind of information to retrieve about the block or blocks.
|
|
|
* Possible values include list, configure, save, view.
|
|
|
* @param $delta
|
|
|
* Which block to return (not applicable if $op is 'list').
|
|
@@ -900,66 +917,66 @@ function chado_stock_delete($node) {
|
|
|
* If $op is 'save', the submitted form data from the configuration form.
|
|
|
*
|
|
|
* @return
|
|
|
- * 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
|
|
|
+ * 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)
|
|
|
*
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-function tripal_stock_block ($op = 'list', $delta = 0, $edit=array()) {
|
|
|
- switch($op) {
|
|
|
+function tripal_stock_block($op = 'list', $delta = 0, $edit=array()) {
|
|
|
+ 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;
|
|
|
-
|
|
|
+
|
|
|
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);
|
|
|
-
|
|
|
+ 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;
|
|
|
-
|
|
|
+ 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;
|
|
|
+
|
|
|
}
|
|
|
- return $block;
|
|
|
- }
|
|
|
- }
|
|
|
+ return $block;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|