123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
- function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
-
- $stock = $variables['node']->stock;
-
- $options = array(
- 'return_array' => 1,
- 'order_by' => array('rank' => 'ASC'),
-
-
-
- 'include_fk' => array(
- 'type_id' => 1,
- 'object_id' => array(
- 'type_id' => 1,
- 'organism_id' => 1
- ),
- 'subject_id' => array(
- 'type_id' => 1,
- 'organism_id' => 1
- ),
- ),
- );
- $stock = chado_expand_var($stock, 'table', 'stock_relationship', $options);
-
- $srelationships = $stock->stock_relationship->subject_id;
- $orelationships = $stock->stock_relationship->object_id;
-
- $relationships = array();
- $relationships['object'] = array();
- $relationships['subject'] = array();
-
- if ($orelationships) {
- foreach ($orelationships as $relationship) {
- $rel = new stdClass();
- $rel->record = $relationship;
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
- $child_type = $relationship->subject_id->type_id->name;
-
- $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
- $n = db_query($sql, array(':stock_id' => $relationship->subject_id->stock_id))->fetchObject();
- if ($n) {
- $rel->record->nid = $n->nid;
- }
- if (!array_key_exists($rel_type, $relationships['object'])) {
- $relationships['object'][$rel_type] = array();
- }
- if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
- $relationships['object'][$rel_type][$child_type] = array();
- }
- $relationships['object'][$rel_type][$child_type][] = $rel;
- }
- }
-
- if ($srelationships) {
- foreach ($srelationships as $relationship) {
- $rel = new stdClass();
- $rel->record = $relationship;
- $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
- $parent_type = $relationship->object_id->type_id->name;
-
- $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
- $n = db_query($sql, array(':stock_id' => $relationship->object_id->stock_id))->fetchObject();
- if ($n) {
- $rel->record->nid = $n->nid;
- }
- if (!array_key_exists($rel_type, $relationships['subject'])) {
- $relationships['subject'][$rel_type] = array();
- }
- if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$parent_type] = array();
- }
- $relationships['subject'][$rel_type][$parent_type][] = $rel;
- }
- }
- $stock->all_relationships = $relationships;
- }
|