|
@@ -174,13 +174,28 @@ function cs_node_load($nid) {
|
|
|
*
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-function tripal_stock_perm() {
|
|
|
+function tripal_stock_permissions() {
|
|
|
return array(
|
|
|
- 'access chado_stock content',
|
|
|
- 'create chado_stock content',
|
|
|
- 'edit chado_stock content',
|
|
|
- 'delete chado_stock content',
|
|
|
- 'administer tripal stocks',
|
|
|
+ 'access chado_stock content' => array(
|
|
|
+ 'title' => t('View Stocks'),
|
|
|
+ 'description' => t('Allow users to view stock pages.'),
|
|
|
+ ),
|
|
|
+ 'create chado_stock content' => array(
|
|
|
+ 'title' => t('Create Stocks'),
|
|
|
+ 'description' => t('Allow users to create new stock pages.'),
|
|
|
+ ),
|
|
|
+ 'delete chado_stock content' => array(
|
|
|
+ 'title' => t('Delete Stocks'),
|
|
|
+ 'description' => t('Allow users to delete stock pages.'),
|
|
|
+ ),
|
|
|
+ 'edit chado_stock content' => array(
|
|
|
+ 'title' => t('Edit Stocks'),
|
|
|
+ 'description' => t('Allow users to edit stock pages.'),
|
|
|
+ ),
|
|
|
+ 'adminster tripal stock' => array(
|
|
|
+ 'title' => t('Administer Stocks'),
|
|
|
+ 'description' => t('Allow users to administer all stocks.'),
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -357,7 +372,7 @@ function tripal_stock_node_info() {
|
|
|
return array(
|
|
|
'chado_stock' => array(
|
|
|
'name' => t('Stock'),
|
|
|
- 'module' => 'chado_stock',
|
|
|
+ 'base' => '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,
|
|
@@ -522,7 +537,7 @@ function chado_stock_form($node, $form_state) {
|
|
|
$org_rset = chado_query($sql);
|
|
|
$organisms = array();
|
|
|
$organisms[''] = '';
|
|
|
- while ($organism = db_fetch_object($org_rset)) {
|
|
|
+ while ($organism = $org_rset->fetchObject()) {
|
|
|
$organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
|
|
|
}
|
|
|
$form['details']['organism_id'] = array(
|
|
@@ -586,19 +601,24 @@ 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 {:table} WHERE :column = :value";
|
|
|
+ $string_in_chado_sql = "SELECT count(*) as count FROM {:table} WHERE :column = :value";
|
|
|
|
|
|
// if this is an update, we want to make sure that a different stock for
|
|
|
// the organism doesn't already have this uniquename. We don't want to give
|
|
|
// two sequences the same uniquename
|
|
|
if ($node->stock_id) {
|
|
|
- $sql = "SELECT *
|
|
|
- FROM {stock} S
|
|
|
- INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
|
|
|
- WHERE uniquename = '%s'
|
|
|
- AND organism_id = %d AND CVT.name = '%s' AND NOT stock_id = %d";
|
|
|
- $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->stock_type, $node->stock_id));
|
|
|
+ $sql = "
|
|
|
+ SELECT *
|
|
|
+ FROM {stock} S
|
|
|
+ INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
|
|
|
+ WHERE
|
|
|
+ uniquename = :uname AND organism_id = :organism_id AND
|
|
|
+ CVT.name = :cvtname AND NOT stock_id = :stock_id
|
|
|
+ ";
|
|
|
+ $result = chado_query($sql, array(':uname' => $node->uniquename,
|
|
|
+ ':organism_id' => $node->organism_id, ':cvtname' => $node->stock_type,
|
|
|
+ ':stock_id' => $node->stock_id))->fetchObject();
|
|
|
if ($result) {
|
|
|
form_set_error('uniquename', t("Stock update cannot proceed. The stock name '$node->uniquename' is not unique for this organism. Please provide a unique name for this stock."));
|
|
|
}
|
|
@@ -607,12 +627,13 @@ function chado_stock_validate($node, &$form) {
|
|
|
// if this is an insert then we just need to make sure this name doesn't
|
|
|
// already exist for this organism if it does then we need to throw an error
|
|
|
else {
|
|
|
- $sql = "SELECT *
|
|
|
- FROM {Stock} S
|
|
|
- INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
|
|
|
- WHERE uniquename = '%s'
|
|
|
- AND organism_id = %d AND CVT.name = '%s'";
|
|
|
- $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->stock_type));
|
|
|
+ $sql = "
|
|
|
+ SELECT *
|
|
|
+ FROM {Stock} S
|
|
|
+ INNER JOIN {cvterm} CVT ON S.type_id = CVT.cvterm_id
|
|
|
+ WHERE uniquename = :uname'AND organism_id = :organism_id AND CVT.name = :cvtname";
|
|
|
+ $result = chado_query($sql, array(':uname' => $node->uniquename,
|
|
|
+ ':organism_id' => $node->organism_id, ':cvtname' => $node->stock_type))->fetchObject();
|
|
|
if ($result) {
|
|
|
form_set_error('uniquename', t("Stock insert cannot proceed. The stock name '$node->uniquename' already exists for this organism. Please provide a unique name for this stock."));
|
|
|
}
|
|
@@ -624,7 +645,7 @@ function chado_stock_validate($node, &$form) {
|
|
|
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));
|
|
|
+ $num_rows = chado_query($int_in_chado_sql, array(':table' => 'cvterm', ':column' => 'cvterm_id', ':value' => $node->type_id))->fetchObject();
|
|
|
if ( $num_rows->count != 1) {
|
|
|
form_set_error('type_id', "The type you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
|
|
|
}
|
|
@@ -634,7 +655,7 @@ function chado_stock_validate($node, &$form) {
|
|
|
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));
|
|
|
+ $num_rows = chado_query($int_in_chado_sql, array(':table' => 'organism', ':column' => 'organism_id', ':value' => $node->organism_id))->fetchObject();
|
|
|
if ( $num_rows->count != 1 ) {
|
|
|
form_set_error('organism_id', "The organism you selected is not valid. Please choose another one. (CODE:$num_rows)"); }
|
|
|
}
|
|
@@ -655,7 +676,7 @@ function chado_stock_validate($node, &$form) {
|
|
|
|
|
|
// 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));
|
|
|
+ $num_rows = chado_query($int_in_chado_sql, array(':table' => 'db', ':column' => 'db_id', ':value' => $node->database))->fetchObject();
|
|
|
if ($num_rows->count != 1) {
|
|
|
form_set_error('database', 'The database you selected is not valid. Please choose another one.'); }
|
|
|
}
|
|
@@ -679,13 +700,8 @@ function chado_stock_insert($node) {
|
|
|
// 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
|
|
|
- );
|
|
|
+ $sql = "INSERT INTO {chado_stock} (nid, vid, stock_id) VALUES (:nid, :vid, :stock_id)";
|
|
|
+ db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':stock_id' => $node->stock_id));
|
|
|
}
|
|
|
|
|
|
return $node;
|
|
@@ -755,8 +771,8 @@ function chado_stock_insert($node) {
|
|
|
$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);
|
|
|
+ $sql = "INSERT INTO {chado_stock} (nid, vid, stock_id) VALUES :nid, :vid, :stock_id)";
|
|
|
+ db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':stock_id' => $stock->stock_id));
|
|
|
|
|
|
// Move on to next stage of Stock Creation based on next_stage_path field
|
|
|
if ($node->simulate_multipart) {
|
|
@@ -906,133 +922,112 @@ function chado_stock_update($node) {
|
|
|
function chado_stock_delete($node) {
|
|
|
|
|
|
// Set stock in chado: is_obsolete = TRUE
|
|
|
- chado_query(
|
|
|
- "DELETE FROM {stock} WHERE stock_id=%d",
|
|
|
- $node->stock->stock_id
|
|
|
- );
|
|
|
+ chado_query("DELETE FROM {stock} WHERE stock_id = :stock_id", array(':stock_id' => $node->stock->stock_id));
|
|
|
|
|
|
//remove drupal node and all revisions
|
|
|
- db_query(
|
|
|
- "DELETE FROM {chado_stock} WHERE nid=%d",
|
|
|
- $node->nid
|
|
|
- );
|
|
|
+ db_query("DELETE FROM {chado_stock} WHERE nid = :nid", array(':nid' => $node->nid));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Purpose: Implement Blocks relating to stock content
|
|
|
- *
|
|
|
- * @param $op
|
|
|
- * 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').
|
|
|
- * @param $edit
|
|
|
- * 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
|
|
|
- * by $delta (view)
|
|
|
- *
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-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;
|
|
|
+function tripal_stock_block_info() {
|
|
|
+ $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['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['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['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;
|
|
|
-
|
|
|
-
|
|
|
+ $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 $blocks;
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_stock
|
|
|
+ */
|
|
|
+function tripal_stock_block_view($delta = '') {
|
|
|
|
|
|
- }
|
|
|
- return $block;
|
|
|
+ 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;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1059,9 +1054,9 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
|
INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
|
|
|
INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
|
|
|
LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
|
|
|
- WHERE SR.subject_id = %d
|
|
|
+ WHERE SR.subject_id = :stock_id
|
|
|
";
|
|
|
- $as_subject = chado_query($sql, $stock->stock_id);
|
|
|
+ $as_subject = chado_query($sql, array(':stock_id' => $stock->stock_id));
|
|
|
$sql = "
|
|
|
SELECT
|
|
|
S.name, S.uniquename, S.stock_id, CS.nid,
|
|
@@ -1072,9 +1067,9 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
|
INNER JOIN {cvterm} CVT on SR.type_id = CVT.cvterm_id
|
|
|
INNER JOIN {cvterm} CVTs on S.type_id = CVTs.cvterm_id
|
|
|
LEFT JOIN public.chado_stock CS on S.stock_id = CS.stock_id
|
|
|
- WHERE SR.object_id = %d
|
|
|
+ WHERE SR.object_id = :stock_id
|
|
|
";
|
|
|
- $as_object = chado_query($sql, $stock->stock_id);
|
|
|
+ $as_object = chado_query($sql, array(':stock_id' => $stock->stock_id));
|
|
|
|
|
|
// combine both object and subject relationshisp into a single array
|
|
|
$relationships = array();
|
|
@@ -1082,7 +1077,7 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
|
$relationships['subject'] = array();
|
|
|
|
|
|
// iterate through the object relationships
|
|
|
- while ($relationship = db_fetch_object($as_object)) {
|
|
|
+ while ($relationship = $as_object->fetchObject()) {
|
|
|
|
|
|
// get the relationship and child types
|
|
|
$rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
|
|
@@ -1098,7 +1093,7 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
|
}
|
|
|
|
|
|
// now add in the subject relationships
|
|
|
- while ($relationship = db_fetch_object($as_subject)) {
|
|
|
+ while ($relationship = $as_subject->fetchObject()) {
|
|
|
|
|
|
// get the relationship and child types
|
|
|
$rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
|
|
@@ -1118,88 +1113,74 @@ function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
- * Implementation of hook_nodeapi().
|
|
|
- * Display stock information for associated organisms
|
|
|
- * This function also provides contents for indexing
|
|
|
- *
|
|
|
* @ingroup tripal_stock
|
|
|
*/
|
|
|
-function tripal_stock_nodeapi(&$node, $op, $teaser, $page) {
|
|
|
-
|
|
|
- switch ($op) {
|
|
|
-
|
|
|
- // 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;
|
|
|
- }
|
|
|
+function tripal_stock_node_presave($node) {
|
|
|
+
|
|
|
+ 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;
|
|
|
-
|
|
|
- // 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @ingroup tripal_stock
|
|
|
+ */
|
|
|
+function tripal_stock_node_insert($node) {
|
|
|
+ switch ($node->type) {
|
|
|
+ case 'chado_stock':
|
|
|
+ if (!$node->stock_id) {
|
|
|
+ $sql = "SELECT * FROM {chado_stock} WHERE nid = :nid";
|
|
|
+ $chado_stock = db_query($sql, array(':nid' => $node->nid))->fetchObject();
|
|
|
+ $node->stock_id = $chado_stock->stock_id;
|
|
|
}
|
|
|
- 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;
|
|
|
+ // remove any previous alias
|
|
|
+ db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => "node/$node->nid"));
|
|
|
|
|
|
- // add items to other nodes, build index and search results
|
|
|
- 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) {
|
|
|
+ // set the URL for this stock page
|
|
|
+ $url_alias = tripal_stock_get_stock_url($node);
|
|
|
+ path_set_alias("node/$node->nid", $url_alias);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @ingroup tripal_stock
|
|
|
+ */
|
|
|
+function tripal_stock_node_update($node) {
|
|
|
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
+ switch ($node->type) {
|
|
|
+ case 'chado_stock':
|
|
|
+
|
|
|
+ // remove any previous alias
|
|
|
+ db_query("DELETE FROM {url_alias} WHERE src = :src", array(':src' => "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;
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * @ingroup tripal_stock
|
|
|
+ */
|
|
|
+function tripal_stock_node_view($node, $view_mode, $langcode) {
|
|
|
+
|
|
|
+ switch ($node->type) {
|
|
|
+ case 'chado_organism':
|
|
|
+ if ($view_mode == 'full') {
|
|
|
+ // Show stock if the organism/feature is not at teaser view
|
|
|
+ $node->content['tripal_organism_stocks'] = array(
|
|
|
+ '#value' => theme('tripal_organism_stocks', $node),
|
|
|
+ );
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -1234,9 +1215,9 @@ function tripal_stock_match_stocks_page($id) {
|
|
|
INNER JOIN {cvterm} CVT on CVT.cvterm_id = S.type_id
|
|
|
INNER JOIN public.chado_stock CS on CS.stock_id = S.stock_id
|
|
|
WHERE
|
|
|
- S.uniquename = '%s' or S.name = '%s'
|
|
|
+ S.uniquename = :uname or S.name = :name
|
|
|
";
|
|
|
- $results = chado_query($sql, $id, $id);
|
|
|
+ $results = chado_query($sql, array(':uname' => $id, ':name' => $id));
|
|
|
|
|
|
$num_matches = 0;
|
|
|
|
|
@@ -1244,7 +1225,7 @@ function tripal_stock_match_stocks_page($id) {
|
|
|
$header = array('Uniquename', 'Name', 'Type', 'Species');
|
|
|
$rows = array();
|
|
|
$curr_match;
|
|
|
- while ($match = db_fetch_object($results)) {
|
|
|
+ while ($match = $results->fetchObject()) {
|
|
|
$curr_match = $match;
|
|
|
$rows[] = array(
|
|
|
$match->uniquename,
|