function tripal_stock_preprocess_tripal_stock_relationships
2.x tripal_stock.theme.inc | tripal_stock_preprocess_tripal_stock_relationships(&$variables) |
3.x tripal_stock.theme.inc | tripal_stock_preprocess_tripal_stock_relationships(&$variables) |
1.x tripal_stock.module | tripal_stock_preprocess_tripal_stock_relationships(&$variables) |
Related topics
File
- tripal_stock/
tripal_stock.module, line 1022 - Implements Tripal Stock Module hooks
Code
function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
// we want to provide a new variable that contains the matched stocks.
$stock = $variables['node']->stock;
// normally we would use tripal_core_expand_chado_vars to expand our
// organism object and add in the relationships, however whan a large
// number of relationships are present this significantly slows the
// query, therefore we will manually perform the query
$sql = "
SELECT
S.name, S.uniquename, S.stock_id, CS.nid,
CVT.name as rel_type, CVTs.name as obj_type,
SR.value
FROM {stock_relationship} SR
INNER JOIN {stock} S on SR.object_id = S.stock_id
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
";
$as_subject = chado_query($sql, $stock->stock_id);
$sql = "
SELECT
S.name, S.uniquename, S.stock_id, CS.nid,
CVT.name as rel_type, CVTs.name as sub_type,
SR.value
FROM {stock_relationship} SR
INNER JOIN {stock} S on SR.subject_id = S.stock_id
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
";
$as_object = chado_query($sql, $stock->stock_id);
// combine both object and subject relationshisp into a single array
$relationships = array();
$relationships['object'] = array();
$relationships['subject'] = array();
// iterate through the object relationships
while ($relationship = db_fetch_object($as_object)) {
// get the relationship and child types
$rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
$sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
if (!array_key_exists($rel_type, $relationships['object'])) {
$relationships['object'][$rel_type] = array();
}
if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
$relationships['object'][$rel_type][$sub_type] = array();
}
$relationships['object'][$rel_type][$sub_type][] = $relationship;
}
// now add in the subject relationships
while ($relationship = db_fetch_object($as_subject)) {
// get the relationship and child types
$rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
$obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
if (!array_key_exists($rel_type, $relationships['subject'])) {
$relationships['subject'][$rel_type] = array();
}
if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
$relationships['subject'][$rel_type][$obj_type] = array();
}
$relationships['subject'][$rel_type][$obj_type][] = $relationship;
}
$stock->all_relationships = $relationships;
}