function tripal_stock_nodeapi
1.x tripal_stock.module | tripal_stock_nodeapi(&$node, $op, $teaser, $page) |
Implementation of hook_nodeapi(). Display stock information for associated organisms This function also provides contents for indexing
Related topics
File
- tripal_stock/
tripal_stock.module, line 1105 - Implements Tripal Stock Module hooks
Code
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;
}
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':
// 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) {
}
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;
}
}
break;
}
}