|
@@ -21,7 +21,8 @@
|
|
* Stock Module see the GMOD Wiki Page (http://gmod.org/wiki/Chado_Stock_Module)
|
|
* Stock Module see the GMOD Wiki Page (http://gmod.org/wiki/Chado_Stock_Module)
|
|
* @}
|
|
* @}
|
|
*/
|
|
*/
|
|
-require_once("includes/tripal_stock-administration.inc");
|
|
|
|
|
|
+require_once("includes/tripal_stock.admin.inc");
|
|
|
|
+require_once("includes/tripal_stock.sync_stocks.inc");
|
|
require_once("includes/other_module_api_functions.inc");
|
|
require_once("includes/other_module_api_functions.inc");
|
|
require_once("includes/tripal_stock-secondary_tables.inc");
|
|
require_once("includes/tripal_stock-secondary_tables.inc");
|
|
require_once("includes/tripal_stock-properties.inc");
|
|
require_once("includes/tripal_stock-properties.inc");
|
|
@@ -57,6 +58,15 @@ function tripal_stock_menu() {
|
|
'access arguments' => array('administer tripal stocks'),
|
|
'access arguments' => array('administer tripal stocks'),
|
|
'type' => MENU_NORMAL_ITEM
|
|
'type' => MENU_NORMAL_ITEM
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ $items['admin/tripal/tripal_stock/sync'] = array(
|
|
|
|
+ 'title' => ' Sync Stocks',
|
|
|
|
+ 'description' => 'Sync stocks from Chado with Drupal',
|
|
|
|
+ 'page callback' => 'drupal_get_form',
|
|
|
|
+ 'page arguments' => array('tripal_stock_sync_form'),
|
|
|
|
+ 'access arguments' => array('administer tripal stocks'),
|
|
|
|
+ 'type' => MENU_NORMAL_ITEM,
|
|
|
|
+ );
|
|
|
|
|
|
// Adding Secondary Properties-----------------
|
|
// Adding Secondary Properties-----------------
|
|
$items['node/%cs_node/properties'] = array(
|
|
$items['node/%cs_node/properties'] = array(
|
|
@@ -345,6 +355,29 @@ function chado_stock_load($node) {
|
|
$values = array('stock_id' => $stock_id);
|
|
$values = array('stock_id' => $stock_id);
|
|
$stock = tripal_core_generate_chado_var('stock', $values);
|
|
$stock = tripal_core_generate_chado_var('stock', $values);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ // by default, the titles are saved using the unique constraint. We will
|
|
|
|
+ // keep it the same, but remove the duplicate name if the unique name and name
|
|
|
|
+ // are identical
|
|
|
|
+ $title_type = variable_get('chado_stock_title', 'unique_constraint');
|
|
|
|
+ if($title_type == 'unique_constraint') {
|
|
|
|
+ if (strcmp($stock->name, $stock->uniquename)==0) {
|
|
|
|
+ $node->title = $stock->name . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
|
|
|
|
+ }
|
|
|
|
+ // in previous version of Tripal, the stock title was simply the unique name.
|
|
|
|
+ // so, we recreate the title just to be sure all of our stock pages are consistent
|
|
|
|
+ else {
|
|
|
|
+ $node->title = $stock->name . ", " . $stock->uniquename . " (" . $stock->type_id->name . ") " . $stock->organism_id->genus . " " . $stock->organism_id->species ;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // set the title to be the stock name or uniquename as configured
|
|
|
|
+ if($title_type == 'stock_name') {
|
|
|
|
+ $node->title = $stock->name;
|
|
|
|
+ }
|
|
|
|
+ if($title_type == 'stock_unique_name') {
|
|
|
|
+ $node->title = $stock->uniquename;
|
|
|
|
+ }
|
|
|
|
+
|
|
// add this to the node
|
|
// add this to the node
|
|
$additions = new stdClass();
|
|
$additions = new stdClass();
|
|
$additions->stock = $stock;
|
|
$additions->stock = $stock;
|
|
@@ -413,7 +446,7 @@ function chado_stock_form($node, $form_state) {
|
|
'#title' => t('Stock Name')
|
|
'#title' => t('Stock Name')
|
|
);
|
|
);
|
|
|
|
|
|
- $form['names']['title'] = array(
|
|
|
|
|
|
+ $form['names']['sname'] = array(
|
|
'#type' => 'textfield',
|
|
'#type' => 'textfield',
|
|
'#title' => t('Name'),
|
|
'#title' => t('Name'),
|
|
'#default_value' => $node->stock->name,
|
|
'#default_value' => $node->stock->name,
|
|
@@ -440,8 +473,11 @@ function chado_stock_form($node, $form_state) {
|
|
$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';
|
|
$type_options[0] = 'Select a Type';
|
|
if ($node->nid == '') {
|
|
if ($node->nid == '') {
|
|
- $type_default = 0; }
|
|
|
|
- else { $type_default = $node->stock->type_id->cvterm_id; }
|
|
|
|
|
|
+ $type_default = 0;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $type_default = $node->stock->type_id->cvterm_id;
|
|
|
|
+ }
|
|
$form['details']['type_id'] = array(
|
|
$form['details']['type_id'] = array(
|
|
'#type' => 'select',
|
|
'#type' => 'select',
|
|
'#title' => t('Type of Stock'),
|
|
'#title' => t('Type of Stock'),
|
|
@@ -462,7 +498,7 @@ function chado_stock_form($node, $form_state) {
|
|
$form['details']['organism_id'] = array(
|
|
$form['details']['organism_id'] = array(
|
|
'#type' => 'select',
|
|
'#type' => 'select',
|
|
'#title' => t('Source Organism for stock'),
|
|
'#title' => t('Source Organism for stock'),
|
|
- '#default_value' => $organism_default,
|
|
|
|
|
|
+ '#default_value' => $node->stock->organism_id->organism_id,
|
|
'#options' => $organisms,
|
|
'#options' => $organisms,
|
|
'#required' => TRUE
|
|
'#required' => TRUE
|
|
);
|
|
);
|
|
@@ -579,9 +615,9 @@ function chado_stock_validate($node, &$form) {
|
|
if ($num_rows->count != 1) {
|
|
if ($num_rows->count != 1) {
|
|
form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
|
|
form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Implements hook_insert(): Inserts data from chado_stock_form() into drupal and chado
|
|
* Implements hook_insert(): Inserts data from chado_stock_form() into drupal and chado
|
|
*
|
|
*
|
|
@@ -594,8 +630,8 @@ function chado_stock_validate($node, &$form) {
|
|
* @ingroup tripal_stock
|
|
* @ingroup tripal_stock
|
|
*/
|
|
*/
|
|
function chado_stock_insert($node) {
|
|
function chado_stock_insert($node) {
|
|
-
|
|
|
|
- //If the chado stock exists
|
|
|
|
|
|
+
|
|
|
|
+ // If the chado stock exists (e.g. this is only a syncing operation)
|
|
// then don't create but simply link to node
|
|
// then don't create but simply link to node
|
|
if ($node->chado_stock_exists) {
|
|
if ($node->chado_stock_exists) {
|
|
if (!empty($node->stock_id)) {
|
|
if (!empty($node->stock_id)) {
|
|
@@ -607,12 +643,15 @@ function chado_stock_insert($node) {
|
|
$node->stock_id
|
|
$node->stock_id
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
return $node;
|
|
return $node;
|
|
}
|
|
}
|
|
|
|
|
|
- // create dbxref
|
|
|
|
- if ( !empty($node->accession) ) {
|
|
|
|
- if ( !empty($node->database) ) {
|
|
|
|
|
|
+ // before we can add the stock, we must add the dbxref if one has been
|
|
|
|
+ // provided by the user.
|
|
|
|
+ $dbxref_status = 0;
|
|
|
|
+ if (!empty($node->accession) ) {
|
|
|
|
+ if (!empty($node->database) ) {
|
|
$values = array(
|
|
$values = array(
|
|
'db_id' => $node->database,
|
|
'db_id' => $node->database,
|
|
'accession' => $node->accession,
|
|
'accession' => $node->accession,
|
|
@@ -630,11 +669,14 @@ function chado_stock_insert($node) {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else { $dbxref_status = 1; }
|
|
|
|
|
|
+ else {
|
|
|
|
+ $dbxref_status = 1;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // create stock
|
|
|
|
|
|
+ // create stock including the dbxref
|
|
|
|
+ $stock = '';
|
|
if ($dbxref_status) {
|
|
if ($dbxref_status) {
|
|
$values = array(
|
|
$values = array(
|
|
'dbxref_id' => array(
|
|
'dbxref_id' => array(
|
|
@@ -642,56 +684,41 @@ function chado_stock_insert($node) {
|
|
'accession' => $node->accession
|
|
'accession' => $node->accession
|
|
),
|
|
),
|
|
'organism_id' => $node->organism_id,
|
|
'organism_id' => $node->organism_id,
|
|
- 'name' => $node->title,
|
|
|
|
|
|
+ 'name' => $node->sname,
|
|
'uniquename' => $node->uniquename,
|
|
'uniquename' => $node->uniquename,
|
|
'description' => $node->stock_description,
|
|
'description' => $node->stock_description,
|
|
'type_id' => $node->type_id
|
|
'type_id' => $node->type_id
|
|
);
|
|
);
|
|
- $stock_status = tripal_core_chado_insert('stock', $values);
|
|
|
|
|
|
+ $stock = tripal_core_chado_insert('stock', $values);
|
|
}
|
|
}
|
|
|
|
+ // create a stock without a dbxref
|
|
else {
|
|
else {
|
|
$values = array(
|
|
$values = array(
|
|
'organism_id' => $node->organism_id,
|
|
'organism_id' => $node->organism_id,
|
|
- 'name' => $node->title,
|
|
|
|
- 'uniquename' => $node->uniquename,
|
|
|
|
|
|
+ 'name' => $node->sname,
|
|
|
|
+ 'uniquename' => $node->uniquename,
|
|
'description' => $node->stock_description,
|
|
'description' => $node->stock_description,
|
|
- 'type_id' => $node->type_id
|
|
|
|
|
|
+ 'type_id' => $node->type_id
|
|
);
|
|
);
|
|
- $stock_status = tripal_core_chado_insert('stock', $values);
|
|
|
|
|
|
+ $stock = 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;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ // if the stock creation was succesful then add the URL and the entry in the
|
|
|
|
+ // chado_stock table
|
|
|
|
+ if (is_array($stock)) {
|
|
|
|
+
|
|
|
|
+ // convert the stock into an object
|
|
|
|
+ $stock = (object) $stock;
|
|
|
|
+
|
|
|
|
+ // add the entry to the chado_stock table
|
|
|
|
+ $sql = "INSERT INTO {chado_stock} (nid, vid, stock_id) VALUES (%d, %d, %d)";
|
|
|
|
+ db_query($sql, $node->nid, $node->vid, $stock->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 {
|
|
else {
|
|
drupal_set_message(t('Error during stock creation.'), 'error');
|
|
drupal_set_message(t('Error during stock creation.'), 'error');
|
|
@@ -702,7 +729,6 @@ function chado_stock_insert($node) {
|
|
);
|
|
);
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -724,10 +750,6 @@ function chado_stock_update($node) {
|
|
// there is no way to handle revisions in Chado but leave
|
|
// there is no way to handle revisions in Chado but leave
|
|
// this here just to make not we've addressed it.
|
|
// this here just to make not we've addressed it.
|
|
}
|
|
}
|
|
-// if ($node->revision) {
|
|
|
|
-// chado_stock_insert($node);
|
|
|
|
-// }
|
|
|
|
-// else {
|
|
|
|
|
|
|
|
//update dbxref
|
|
//update dbxref
|
|
if ($node->database) {
|
|
if ($node->database) {
|
|
@@ -794,7 +816,7 @@ function chado_stock_update($node) {
|
|
//can't change stock id which is all thats stored in drupal thus only update chado
|
|
//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,
|
|
'organism_id' => $node->organism_id,
|
|
- 'name' => $node->title,
|
|
|
|
|
|
+ 'name' => $node->sname,
|
|
'uniquename' => $node->uniquename,
|
|
'uniquename' => $node->uniquename,
|
|
'description' => $node->stock_description,
|
|
'description' => $node->stock_description,
|
|
'type_id' => $node->type_id,
|
|
'type_id' => $node->type_id,
|
|
@@ -805,11 +827,8 @@ function chado_stock_update($node) {
|
|
'accession' => $node->accession
|
|
'accession' => $node->accession
|
|
);
|
|
);
|
|
}
|
|
}
|
|
- $status = tripal_core_chado_update(
|
|
|
|
- 'stock',
|
|
|
|
- array('stock_id' => $node->stock_id),
|
|
|
|
- $update_values
|
|
|
|
- );
|
|
|
|
|
|
+ $status = tripal_core_chado_update('stock', array('stock_id' => $node->stock_id), $update_values);
|
|
|
|
+
|
|
|
|
|
|
if (!$status) {
|
|
if (!$status) {
|
|
drupal_set_message(t('Unable to update stock'), 'error');
|
|
drupal_set_message(t('Unable to update stock'), 'error');
|
|
@@ -820,6 +839,11 @@ function chado_stock_update($node) {
|
|
WATCHDOG_ERROR
|
|
WATCHDOG_ERROR
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
+ // set the URL for this stock page
|
|
|
|
+ $values = array('stock_id' => $node->stock_id);
|
|
|
|
+ $stock = tripal_core_chado_select('stock', array('*'), $values);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1059,8 +1083,59 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
function tripal_stock_nodeapi(&$node, $op, $teaser, $page) {
|
|
function tripal_stock_nodeapi(&$node, $op, $teaser, $page) {
|
|
|
|
|
|
switch ($op) {
|
|
switch ($op) {
|
|
- // Note that this function only adds stock view to an organism/feature
|
|
|
|
- // node.
|
|
|
|
|
|
+
|
|
|
|
+ // set the title to ensure it is always unique
|
|
|
|
+ case 'presave':
|
|
|
|
+ switch ($node->type) {
|
|
|
|
+ case 'chado_stock':
|
|
|
|
+
|
|
|
|
+ $values = array('organism_id' => $node->organism_id);
|
|
|
|
+ $organism = tripal_core_chado_select('organism', array('genus','species'), $values);
|
|
|
|
+ $values = array('cvterm_id' => $node->type_id);
|
|
|
|
+ $cvterm = tripal_core_chado_select('cvterm', array('name'), $values);
|
|
|
|
+ $node->title = $node->sname . ', ' . $node->uniquename . ' (' . $cvterm[0]->name . ') ' . $organism[0]->genus . ' ' . $organism[0]->species;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ // set the URL path after inserting. We do it here because we do not
|
|
|
|
+ // know the stock_id in the presave
|
|
|
|
+ case 'insert':
|
|
|
|
+ switch ($node->type) {
|
|
|
|
+ case 'chado_stock':
|
|
|
|
+ if (!$node->stock_id) {
|
|
|
|
+ $sql = "SELECT * FROM {chado_stock} WHERE nid = %d";
|
|
|
|
+ $chado_stock = db_fetch_object(db_query($sql, $node->nid));
|
|
|
|
+ $node->stock_id = $chado_stock->stock_id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // remove any previous alias
|
|
|
|
+ db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
|
|
|
|
+
|
|
|
|
+ // set the URL for this stock page
|
|
|
|
+ $url_alias = tripal_stock_get_stock_url($node);
|
|
|
|
+ path_set_alias("node/$node->nid", $url_alias);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ // set the URL path after inserting. We do it here because we do not
|
|
|
|
+ // know the stock_id in the presave
|
|
|
|
+ case 'update':
|
|
|
|
+ switch ($node->type) {
|
|
|
|
+ case 'chado_stock':
|
|
|
|
+
|
|
|
|
+ // remove any previous alias
|
|
|
|
+ db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
|
|
|
|
+
|
|
|
|
+ // set the URL for this stock page
|
|
|
|
+ $url_alias = tripal_stock_get_stock_url($node);
|
|
|
|
+ path_set_alias("node/$node->nid", $url_alias);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ // add items to other nodes, build index and search results
|
|
case 'view':
|
|
case 'view':
|
|
// add the stock to the organism/feature search indexing
|
|
// add the stock to the organism/feature search indexing
|
|
if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
|
|
if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
|